OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / assets / javascripts / models / picture.js.coffee
index cec6aa9..4cbe1a3 100644 (file)
@@ -1,5 +1,4 @@
 class Pettanr.Picture extends Peta.Content\r
-  url: '/pictures/'\r
   \r
   @singular: () ->\r
     'Picture'\r
@@ -11,7 +10,12 @@ class Pettanr.Picture extends Peta.Content
     id: null\r
   } \r
   \r
-  is_visible: (operators) ->\r
+  @trace_routes: () ->\r
+    {\r
+      resource_picture: ['resource_picture_picture', 'resource_picture']\r
+    }\r
+  \r
+  is_visible: (operators = Pettanr.cache.operators) ->\r
     return true\r
   \r
   filename: () ->\r
@@ -23,36 +27,25 @@ class Pettanr.Picture extends Peta.Content
   mime_type: () ->\r
     'image/' + @get('ext')\r
   \r
-  r_url: () ->\r
-    '/pictures/' + @filename()\r
-  \r
-  opt_img_tag: () ->\r
-    {src: @r_url(), width: @get('width'), height: @get('height')}\r
-  \r
-  tmb_opt_img_tag: () ->\r
-    new Pettanr.Image.SymbolPicture({\r
-      attr: {\r
-        src: @r_url()\r
-      },\r
-      picture: this\r
-    })\r
-  \r
-  tail_opt_img_tag: (img) ->\r
-    {src: img, width: @get('width'), height: @get('height')}\r
-  \r
-  tail_tmb_opt_img_tag: (img) ->\r
-    wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height'))\r
-    {src: img, width: wh[0], height: wh[1]}\r
+  r_url: (subdir = null) ->\r
+    q = if subdir\r
+      '?subdir=' + subdir\r
+    else\r
+      ''\r
+    '/pictures/' + @filename() + q\r
   \r
   alt_name: () ->\r
     lgn = Pettanr.to_s(@license().license_group().get('caption'))\r
     ln = Pettanr.to_s(@license().get('caption'))\r
     lgn + '[' + ln + ']'\r
   \r
-  symbol_option: (cb) ->\r
-    _this = this\r
-    this.fetch({cache: true}).done ->\r
-      cb(_this.tmb_opt_img_tag())\r
+  symbol_option: (context, options) ->\r
+    @retrieve(this, {\r
+      success: (symbol_item) => \r
+        options.success.call(context, symbol_item.to_symbol())\r
+      fail: (response, opt) =>\r
+        options.fail.call(context, response, opt)\r
+    })\r
   \r
   is_enable: () ->\r
     if @head().resource_picture()\r
@@ -75,12 +68,11 @@ class Pettanr.Picture extends Peta.Content
     else\r
       ['', 'v', 'h', 'vh']\r
   \r
-  is_showable: (operators = null) ->\r
+  is_showable: (operators = Pettanr.cache.operators) ->\r
     return false if not @original_picture()\r
     return true if @is_own(operators)\r
     #@is_enable() and @is_head()\r
   \r
-  initialize: () ->\r
-    if @id\r
-      @url = @url + @id\r
+  initialize: (attr = {}, options = {}) ->\r
+    super(attr, options)\r
   \r