OSDN Git Service

fix summary
[pettanr/pettanr.git] / app / assets / javascripts / models / original_picture.js.coffee
index df61ea1..77015a3 100644 (file)
@@ -12,6 +12,9 @@ class Pettanr.OriginalPicture extends Peta.Content
     artist_id: null\r
   } \r
   \r
+  picture: () ->\r
+    new Pettanr.Picture({id: @get('picture_id')})\r
+  \r
   is_visible: (operators) ->\r
     @is_own(operators)\r
   \r
@@ -35,10 +38,20 @@ class Pettanr.OriginalPicture extends Peta.Content
       picture: this\r
     })\r
   \r
-  symbol_option: (cb) ->\r
-    _this = this\r
-    this.fetch({cache: true}).done ->\r
-      cb(_this.tmb_opt_img_tag())\r
+  symbol_option: () ->\r
+    @fetch({cache: true}).done =>\r
+      @symbol_picture = @tmb_opt_img_tag()\r
+      @trigger('ready:symbol')\r
+  \r
+  filer_caption: () ->\r
+    history = @history()\r
+    history.fetch({cache: true}).done =>\r
+      @caption_text = if _.isEmpty(history.models)\r
+        'unpublished'\r
+      else\r
+        head = _.first(history.models)\r
+        Pettanr.to_s(head.get('revision'))\r
+      @trigger('ready:caption')\r
   \r
   revision: () ->\r
     new Pettanr.OriginalPicture.Head({original_picture: this})\r
@@ -60,6 +73,17 @@ class Pettanr.OriginalPicture extends Peta.Content
   is_published: () ->\r
     @get('published_at') != null\r
   \r
+  state: () ->\r
+    switch true\r
+      when @is_unpublished()\r
+        'unpublished'\r
+      when @is_unlicensed()\r
+        'unlicensed'\r
+      when @is_stopped()\r
+        'stopped'\r
+      when @is_published()\r
+        'published'\r
+  \r
   initialize: () ->\r
     if @id\r
       @url = @url + @id\r
@@ -68,8 +92,9 @@ class Pettanr.OriginalPicture.History extends Backbone.Collection
   url: '/original_pictures/'\r
   \r
   initialize: (options) ->\r
+    @original_picture = options.original_picture\r
     @model = Pettanr.Picture\r
-    @url = @url + options.id + '/history'\r
+    @url = @url + @original_picture.get('id') + '/history'\r
   \r
 class Pettanr.OriginalPicture.Head extends Backbone.View\r
   tagName: 'span'\r
@@ -78,13 +103,12 @@ class Pettanr.OriginalPicture.Head extends Backbone.View
     @pictures = new Pettanr.OriginalPicture.History({id: @original_picture.get('id')})\r
   \r
   render: () ->\r
-    _this = this\r
-    @pictures.fetch({cache: true}).done ->\r
-      head = _this.pictures.models[0]\r
+    @pictures.fetch({cache: true}).done =>\r
+      head = @pictures.models[0]\r
       value = if head\r
         head.get('revision')\r
       else\r
         'unpublished'\r
-      _this.$el.html(value)\r
+      this.$el.html(value)\r
     this\r
   \r