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 0683896..70be1d5 100644 (file)
@@ -1,5 +1,6 @@
 class Pettanr.Panel extends Peta.Root\r
   url: '/panels/'\r
+  \r
   @singular: () ->\r
     'Panel'\r
   \r
@@ -12,10 +13,49 @@ class Pettanr.Panel extends Peta.Root
     publish: 0\r
   } \r
   \r
-  initialize: () ->\r
-    if @id\r
-      @url = @url + @id\r
+  author: () ->\r
+    new Pettanr.Author({id: @get('author_id')})\r
+  \r
+  pp: () ->\r
+    new Pettanr.PanelPicture({id: @get('pp_id')})\r
+  \r
+  is_visible: (operators) ->\r
+    switch super(operators)\r
+      when null # super return\r
+        return true\r
+      when false\r
+        return false\r
+      else\r
+        return true if @isNew()\r
+        @is_publish()\r
+  \r
+  is_usable: (operators) ->\r
+    @is_visible(operators)\r
+  \r
+  is_publish: () ->\r
+    @get('publish') > 0\r
+  \r
+  @licensed_pictures: (panels) ->\r
+    r = {}\r
+    _.each panels, (panel) ->\r
+      _.extend r, panel.licensed_pictures()\r
+    r\r
+  \r
+  licensed_pictures: () ->\r
+    r = {}\r
+    _.each @scenario_elements(), (elm) ->\r
+      return if not elm.my_class().has_picture()\r
+      pid = elm.get('picture_id')\r
+      r[pid] = elm.picture() if not r[pid]\r
+    r\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
+    @bind('change:width', () ->\r
+      console.log('cng')\r
+    )\r
   \r
-class Pettanr.Panel.Collection extends Backbone.Collection\r
-  model: Pettanr.Panel\r
-  url: '/panels'\r