OSDN Git Service

add scroll player
[pettanr/pettanr.git] / app / assets / javascripts / models / original_picture.js.coffee
index fe84000..d373bfe 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
@@ -37,15 +40,14 @@ class Pettanr.OriginalPicture extends Peta.Content
   \r
   symbol_option: (cb) ->\r
     _this = this\r
-    this.fetch().done ->\r
+    this.fetch({cache: true}).done ->\r
       cb(_this.tmb_opt_img_tag())\r
   \r
   revision: () ->\r
-    head = @history()[0]\r
-    if head\r
-      head.revision()\r
-    else\r
-      'unpublished'\r
+    new Pettanr.OriginalPicture.Head({original_picture: this})\r
+  \r
+  history: () ->\r
+    new Pettanr.OriginalPicture.History({original_picture: this})\r
   \r
   is_unpublished: () ->\r
     @get('published_at') == null and @get('stopped_at') == null\r
@@ -61,10 +63,42 @@ 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
   \r
-class Pettanr.OriginalPicture.Collection extends Backbone.Collection\r
-  model: Pettanr.OriginalPicture\r
-  url: '/original_pictures'\r
+class Pettanr.OriginalPicture.History extends Backbone.Collection\r
+  url: '/original_pictures/'\r
+  \r
+  initialize: (options) ->\r
+    @model = Pettanr.Picture\r
+    @url = @url + options.id + '/history'\r
+  \r
+class Pettanr.OriginalPicture.Head extends Backbone.View\r
+  tagName: 'span'\r
+  initialize: (options) ->\r
+    @original_picture = options.original_picture\r
+    @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
+      value = if head\r
+        head.get('revision')\r
+      else\r
+        'unpublished'\r
+      _this.$el.html(value)\r
+    this\r
+  \r