OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / assets / javascripts / models / original_picture.js.coffee
index cb58ca3..00cf226 100644 (file)
-class OriginalPicture extends Item\r
-  @single: () ->\r
+class Pettanr.OriginalPicture extends Peta.Content\r
+  url: '/original_pictures/'\r
+  \r
+  @singular: () ->\r
     'OriginalPicture'\r
   \r
   @plural: () ->\r
     'OriginalPictures'\r
   \r
   defaults: {\r
-    id: 11\r
+    id: null,\r
+    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
+  filename: () ->\r
+    @get('id') + '.' + @get('ext')\r
+  \r
+  mime_type: () ->\r
+    'image/' + @get('ext')\r
+  \r
+  r_url: () ->\r
+    '/original_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
+  symbol_option: () ->\r
+    @fetch({cache: true}).done =>\r
+      @trigger('ready:symbol', @tmb_opt_img_tag())\r
+  \r
+  filer_caption: () ->\r
+    history = @history()\r
+    history.fetch({cache: true}).done =>\r
+      caption = if _.isEmpty(history.models)\r
+        'unpublished'\r
+      else\r
+        head = _.first(history.models)\r
+        Pettanr.to_s(head.get('revision'))\r
+      @trigger('ready:caption', caption)\r
+  \r
+  revision: () ->\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
+  \r
+  is_stopped: () ->\r
+    @get('stopped_at') != null\r
+  \r
+  is_unlicensed: () ->\r
+    dt = @get('published_at') || @get('stopped_at')\r
+    return false if not dt\r
+    @get('uploaded_at') > dt\r
+  \r
+  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
-    confirm("Welcome to Panel")\r
-  \r
-  @test: () ->\r
-    confirm( @single())\r
-    confirm( @plural() )\r
-    confirm( @class_name() )\r
-    confirm( @element_name() )\r
-    confirm( @table_name() )\r
-    \r
-  \r
-  test: () ->\r
-\r
-@Panel = Panel\r
+    if @id\r
+      @url = @url + @id\r
+  \r
+class Pettanr.OriginalPicture.History extends Backbone.Collection\r
+  url: '/original_pictures/'\r
+  \r
+  initialize: (options) ->\r
+    @original_picture = options.original_picture\r
+    @model = Pettanr.Picture\r
+    @url = @url + @original_picture.get('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
+    @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\r
+  \r