OSDN Git Service

merge:
[pettanr/pettanr.git] / app / assets / javascripts / models / panel_picture.js.coffee
index 3c3003d..40e47ac 100644 (file)
@@ -11,11 +11,28 @@ class Pettanr.PanelPicture extends Peta.Element
     id: null\r
   } \r
   \r
+  @pick_item_name: () ->\r
+    'resource_picture'\r
+  \r
+  @traceable_item_names: () ->\r
+    ['ground_picture', 'picture']\r
+  \r
+  trace_from_ground_picture: () ->\r
+  \r
+  trace_from_picture: () ->\r
+  \r
+  pick: (picked_item) ->\r
+    {\r
+      picture_id: picked_item.get('picture_id'),\r
+      width: picked_item.get('width'),\r
+      height: picked_item.get('height')\r
+    }\r
+  \r
   picture: () ->\r
-    new Pettanr.Picture({id: @get('picture_id')})\r
+    new Pettanr.Cache.Retriever(Pettanr.Picture, @get('picture_id'))\r
   \r
-  panel: (options = {}) ->\r
-    new Pettanr.Panel({id: @get('panel_id')}, options)\r
+  panel: () ->\r
+    new Pettanr.Cache.Retriever(Pettanr.Panel, @get('panel_id'))\r
   \r
   @has_picture: () ->\r
     true\r
@@ -35,7 +52,11 @@ class Pettanr.PanelPicture extends Peta.Element
     res\r
   \r
   filename: (picture) ->\r
-    picture.filename() + '?subdir=' + @flip()\r
+    q = if _.isEmpty(@flip())\r
+      ''\r
+    else\r
+      '?subdir=' + @flip()\r
+    picture.filename() + q\r
   \r
   r_url: (picture) ->\r
     '/pictures/' + @filename(picture)\r
@@ -44,21 +65,27 @@ class Pettanr.PanelPicture extends Peta.Element
     new Pettanr.Image.SymbolPicture({\r
       attr: {\r
         src: picture.r_url(), \r
-        alt: @get('caption')\r
+        alt: @escape('caption')\r
       },\r
       picture: picture\r
     })\r
   \r
-  symbol_option: (cb) ->\r
-    i = @picture()\r
-    _this = this\r
-    i.fetch({cache: true}).done ->\r
-      cb(_this.tmb_opt_img_tag(i))\r
+  symbol_option: () ->\r
+    retriever = @picture()\r
+    @listenTo(retriever, 'retrieve', @retrieve_symbol)\r
+    retriever.retrieve()\r
+  \r
+  retrieve_symbol: (item) -> \r
+    @trigger('ready:symbol', item.tmb_opt_img_tag())\r
   \r
   element_face: () ->\r
     new Pettanr.Views.PanelPicture.ElementFace({element: this})\r
   \r
-  initialize: () ->\r
+  initialize: (attr, options) ->\r
+    super(attr, options)\r
     if @id\r
       @url = @url + @id\r
+    @bind('change:width', () ->\r
+      console.log('cng')\r
+    )\r
   \r