X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=app%2Fassets%2Fjavascripts%2Fmodels%2Fpanel.js.coffee;h=47ddffa9cc73ed254d39ee79beb2bde2ea986287;hp=1b386304a73a6d8a456d58a2966bc6df8407f9f0;hb=664f8d5b324115a330cbe80338f2374fe570fdff;hpb=bdcca338fe5e9de14028890fac9fafcd20437272 diff --git a/app/assets/javascripts/models/panel.js.coffee b/app/assets/javascripts/models/panel.js.coffee index 1b386304..47ddffa9 100644 --- a/app/assets/javascripts/models/panel.js.coffee +++ b/app/assets/javascripts/models/panel.js.coffee @@ -13,10 +13,46 @@ class Pettanr.Panel extends Peta.Root publish: 0 } - initialize: () -> - if @id - @url = @url + @id + pp: () -> + new Pettanr.PanelPicture({id: @get('pp_id')}) + + is_visible: (operators) -> + switch super(operators) + when null # super return + return true + when false + return false + else + return true if @isNew() + @is_publish() + + is_usable: (operators) -> + @is_visible(operators) + + is_publish: () -> + @get('publish') > 0 + + initialize: (attr = {}, options = {}) -> + @set(attr) + if @get('id') + @url = @url + @get('id') + if options.with_elements + @url = @url + '?with_elements=true' class Pettanr.Panel.Collection extends Backbone.Collection model: Pettanr.Panel - url: '/panels' + url: '/panels/' +class Pettanr.RelationPanel extends Pettanr.Panel + relations: [ + { + type: Backbone.HasMany, + key: 'panel_pictures', + relatedModel: 'Pettanr.PanelPicture', + collectionType: 'Pettanr.PanelPicture.Collection', + reverseRelation: { + key: 'panel_id', + includeInJSON: 'id' + } + }, + ] +