OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / assets / javascripts / models / picture.js.coffee
index 295cb85..4cbe1a3 100644 (file)
@@ -1,25 +1,78 @@
-class Picture extends Item\r
-  @single: () ->\r
+class Pettanr.Picture extends Peta.Content\r
+  \r
+  @singular: () ->\r
     'Picture'\r
   \r
   @plural: () ->\r
     'Pictures'\r
   \r
   defaults: {\r
-    id: 11\r
+    id: null\r
   } \r
   \r
-  initialize: () ->\r
-    confirm("Welcome to Panel")\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
+    @get('id') + '.' + @get('ext')\r
+  \r
+  gifname: () ->\r
+    @get('id') + '.gif'\r
+  \r
+  mime_type: () ->\r
+    'image/' + @get('ext')\r
+  \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: (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
+      true\r
+    else\r
+      false\r
+  \r
+  @head: (opid) ->\r
+    #Picture.find( conditions => ['original_picture_id = ?', opid], :order => 'pictures.revision desc')\r
+  \r
+  head: () ->\r
+    Picture.head(@get('original_picture_id'))\r
+  \r
+  is_head: () ->\r
+    #this == @head()\r
+  \r
+  subdirs: () ->\r
+    if @license_extend().reverse < 0\r
+      ['']\r
+    else\r
+      ['', 'v', 'h', 'vh']\r
+  \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
-  @test: () ->\r
-    confirm( @single())\r
-    confirm( @plural() )\r
-    confirm( @class_name() )\r
-    confirm( @element_name() )\r
-    confirm( @table_name() )\r
-    \r
+  initialize: (attr = {}, options = {}) ->\r
+    super(attr, options)\r
   \r
-  test: () ->\r
-\r
-@Panel = Panel\r