sort and remove entries from a has_many relationship
This commit is contained in:
parent
dfd437a762
commit
42a2bba538
@ -23,6 +23,12 @@ class Locomotive.Models.ContentEntry extends Backbone.Model
|
||||
@set_attribute attribute, attributes[attribute]
|
||||
@set_attribute "remove_#{field}", false
|
||||
|
||||
toMinJSON: ->
|
||||
_.tap {}, (hash) =>
|
||||
_.each @attributes, (val, key) =>
|
||||
if key == 'id' || key == '_destroy' || key.indexOf('position_in_') == 0
|
||||
hash[key] = val
|
||||
|
||||
toJSON: ->
|
||||
_.tap super, (hash) =>
|
||||
hash['_slug'] = '' if hash['_slug'] == null # avoid empty hash
|
||||
@ -30,10 +36,15 @@ class Locomotive.Models.ContentEntry extends Backbone.Model
|
||||
unless _.include(@get('safe_attributes'), key)
|
||||
delete hash[key]
|
||||
|
||||
# TODO: insert has_many
|
||||
_.each @get('_has_many_fields'), (field) => # include the has_many relationships
|
||||
name = field[0]
|
||||
hash["#{name}_attributes"] = @get(name).toMinJSON()
|
||||
|
||||
class Locomotive.Models.ContentEntriesCollection extends Backbone.Collection
|
||||
|
||||
model: Locomotive.Models.ContentEntry
|
||||
|
||||
url: "#{Locomotive.mounted_on}/content_types/:slug/entries"
|
||||
url: "#{Locomotive.mounted_on}/content_types/:slug/entries"
|
||||
|
||||
toMinJSON: ->
|
||||
@map (entry) => entry.toMinJSON()
|
@ -68,5 +68,6 @@ class Locomotive.Views.Shared.Fields.HasManyView extends Backbone.View
|
||||
entry.set _destroy: true
|
||||
|
||||
entry_html.remove()
|
||||
@$('.empty').show() if @$('> ul > li').size() == 0
|
||||
@refresh_position_entries()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user