\r
defaults: {\r
id: null,\r
+ width: 500,\r
+ height: 300,\r
border: 2,\r
publish: 0\r
} \r
\r
author: () ->\r
- new Pettanr.Author({id: @get('author_id')})\r
+ new Pettanr.Cache.Retriever(Pettanr.Author, @get('author_id'))\r
\r
- pp: () ->\r
- new Pettanr.PanelPicture({id: @get('pp_id')})\r
+ with_elements: () ->\r
+ new Pettanr.Panel.WithElements({id: @get('id')})\r
\r
- is_visible: (operators) ->\r
+ overwrite: (options) ->\r
+ operators = Pettanr.cache.operators\r
+ return false if not operators.author\r
+ @set('author_id', operators.author.id)\r
+ \r
+ is_visible: (operators = Pettanr.cache.operators) ->\r
switch super(operators)\r
when null # super return\r
return true\r
return true if @isNew()\r
@is_publish()\r
\r
- is_usable: (operators) ->\r
+ overwrite: (options) ->\r
+ @set('author_id', Pettanr.cache.operators.author.id)\r
+ \r
+ is_usable: (operators = Pettanr.cache.operators) ->\r
@is_visible(operators)\r
\r
is_publish: () ->\r
r[pid] = elm.picture() if not r[pid]\r
r\r
\r
+ my_url: () ->\r
+ s = if @get('id')\r
+ '/' + @get('id')\r
+ else\r
+ ''\r
+ '/' + @path_name() + s\r
+ \r
initialize: (attr = {}, options = {}) ->\r
+ super(attr, options)\r
@set(attr)\r
if @get('id')\r
- @url = @url + @get('id')\r
- if options.with_elements\r
- @url = @url + '?with_elements=true'\r
+ @url = @my_url()\r
\r
-class Pettanr.Panels extends Backbone.Collection\r
- model: Pettanr.Panel\r
- url: '/panels/'\r
+class Pettanr.Panel.WithElements extends Pettanr.Panel\r
+ \r
+ fetch: (options) ->\r
+ @url = @my_url() + '?with_elements=true'\r
+ super(options)\r
+ \r
+ save: (attrs) ->\r
+ @url = @my_url()\r
+ method = if @isNew()\r
+ 'create'\r
+ else\r
+ 'update'\r
+ _this = this\r
+ xhr = @sync(method, this, {\r
+ attrs: {panel: attrs},\r
+ success: (model, response, options) =>\r
+ _this.set(model, {silent: true})\r
+ _this.trigger('save:success', _this, response)\r
+ error: (model, response, options) =>\r
+ _this.trigger('save:fail', _this, response)\r
+ })\r
+ xhr\r
+ \r
+ destroy: (options) ->\r
+ @url = @my_url()\r
+ super(options)\r
\r