OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / assets / javascripts / models / panel.js.coffee
index c684728..c347941 100644 (file)
@@ -19,6 +19,9 @@ class Pettanr.Panel extends Peta.Root
   pp: () ->\r
     new Pettanr.PanelPicture({id: @get('pp_id')})\r
   \r
+  with_elements: () ->\r
+    new Pettanr.Panel.WithElements({id: @get('id')})\r
+  \r
   is_visible: (operators) ->\r
     switch super(operators)\r
       when null # super return\r
@@ -52,13 +55,34 @@ class Pettanr.Panel extends Peta.Root
       r[pid] = elm.picture() if not r[pid]\r
     r\r
   \r
+  my_url: () ->\r
+    '/' + @path_name() + '/' + @get('id')\r
+  \r
   initialize: (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
     @bind('change:width', () ->\r
       console.log('cng')\r
     )\r
   \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, options = {}) ->\r
+    @url = @my_url()\r
+    options.attrs = {panel: attrs}\r
+    method = if @isNew()\r
+      'create'\r
+    else\r
+      'update'\r
+    xhr = @sync(method, this, options)\r
+    xhr\r
+  \r
+  destroy: (options) ->\r
+    @url = @my_url()\r
+    super(options)\r
+  \r