class Pettanr.Panel extends Peta.Root url: '/panels/' @singular: () -> 'Panel' @plural: () -> 'Panels' defaults: { id: null, border: 2, publish: 0 } author: () -> new Pettanr.Author({id: @get('author_id')}) pp: () -> new Pettanr.PanelPicture({id: @get('pp_id')}) with_elements: () -> new Pettanr.Panel.WithElements({id: @get('id')}) is_visible: (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', options.operators.author.id) is_usable: (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] = elm.picture() if not r[pid] r my_url: () -> '/' + @path_name() + '/' + @get('id') initialize: (attr = {}, options = {}) -> @set(attr) if @get('id') @url = @my_url() @bind('change:width', () -> console.log('cng') ) class Pettanr.Panel.WithElements extends Pettanr.Panel fetch: (options) -> @url = @my_url() + '?with_elements=true' super(options) save: (attrs, options = {}) -> @url = @my_url() options.attrs = {panel: attrs} method = if @isNew() 'create' else 'update' xhr = @sync(method, this, options) xhr destroy: (options) -> @url = @my_url() super(options)