2011-12-22 23:45:32 +00:00
|
|
|
class Locomotive.Models.ContentEntry extends Backbone.Model
|
|
|
|
|
|
|
|
paramRoot: 'content_entry'
|
|
|
|
|
2012-01-02 13:54:01 +00:00
|
|
|
urlRoot: "#{Locomotive.mount_on}/content_types/:slug/entries"
|
|
|
|
|
|
|
|
initialize: ->
|
|
|
|
@urlRoot = @urlRoot.replace(':slug', @get('content_type_slug'))
|
|
|
|
|
|
|
|
set_attribute: (attribute, value) ->
|
|
|
|
data = {}
|
|
|
|
data[attribute] = value
|
|
|
|
@set data
|
|
|
|
|
|
|
|
update_attributes: (attributes) ->
|
|
|
|
_.each attributes._file_fields, (field) => # special treatment for files
|
|
|
|
attribute = "#{field}_url"
|
|
|
|
@set_attribute attribute, attributes[attribute]
|
|
|
|
@set_attribute "remove_#{field}", false
|
|
|
|
|
|
|
|
toJSON: ->
|
|
|
|
_.tap super, (hash) =>
|
2012-01-04 01:07:53 +00:00
|
|
|
hash['_slug'] = '' if hash['_slug'] == null # avoid empty hash
|
2012-01-02 13:54:01 +00:00
|
|
|
_.each _.keys(hash), (key) =>
|
|
|
|
unless _.include(@get('safe_attributes'), key)
|
|
|
|
delete hash[key]
|
2011-12-22 23:45:32 +00:00
|
|
|
|
|
|
|
class Locomotive.Models.ContentEntriesCollection extends Backbone.Collection
|
|
|
|
|
2012-01-02 13:54:01 +00:00
|
|
|
model: Locomotive.Models.ContentEntry
|
2011-12-22 23:45:32 +00:00
|
|
|
|
2012-01-02 13:54:01 +00:00
|
|
|
url: "#{Locomotive.mount_on}/content_types/:slug/entries"
|