class Pettanr.Panel extends Peta.Root @singular: () -> 'Panel' @plural: () -> 'Panels' defaults: { id: null, width: 500, height: 300, border: 2, publish: 0 } with_elements: () -> new Pettanr.Panel.WithElements({id: @get('id')}) overwrite: (options) -> operators = Pettanr.cache.operators return false if not operators.author @set('author_id', operators.author.id) is_visible: (operators = Pettanr.cache.operators) -> switch super(operators) when null # super return return true when false return false else return true if @isNew() @is_publish() overwrite: (options) -> @set('author_id', Pettanr.cache.operators.author.id) is_usable: (operators = Pettanr.cache.operators) -> @is_visible(operators) is_publish: () -> @get('publish') > 0 @licensed_pictures: (panels) -> r = {} _.each panels, (panel) -> _.extend r, panel.licensed_pictures() r licensed_pictures: () -> r = {} _.each @scenario_elements(), (elm) -> return if not elm.my_class().has_picture() pid = elm.get('picture_id') r[pid] = true if not r[pid] r label: (shorten_length) -> @_label('caption', shorten_length) play: () -> new Pettanr.Panel.Play({id: @get('id')}) edit: (options) -> i = new Pettanr.Panel.Edit({id: @get('id')}) i.load(options) initialize: (attr = {}, options = {}) -> super(attr, options) @set(attr) class Pettanr.Panel.Play extends Pettanr.Panel fetch: (options) -> @url = @default_url() + '?with_elements=true' super(options) class Pettanr.Panel.Edit extends Pettanr.Panel.Play load: (options) -> @fetch({ success: (model, response, opt) => @attributes = @decoded_attributes() @load_elements(options) error: (item, response, opt) => options.fail.call(options.context, response, opt) }) save: (attrs) -> @url = @default_url() method = if @isNew() 'create' else 'update' _this = this xhr = @sync(method, this, { attrs: {panel: attrs}, success: (model, response, options) => _this.set(model, {silent: true}) _this.trigger('save:success', _this, response) error: (model, response, options) => _this.trigger('save:fail', _this, response) }) xhr destroy: (options) -> @url = @my_url() super(options)