OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / assets / javascripts / views / panels / show.js.coffee
index 6e34cdb..e8af5f1 100644 (file)
@@ -1,65 +1,71 @@
 # panel: panel item\r
-# operators: operators\r
 # spot: no opacity element\r
-class Pettanr.Views.Panel.Show extends Backbone.View\r
-  tagName: 'div'\r
+class Pettanr.Views.Panel.Show extends Pettanr.View.Show\r
   \r
   initialize: (options) ->\r
-    @panel = options.panel\r
-    @operators = options.operators\r
+    @panel = @item\r
     @spot = options.spot\r
     \r
-    icon_url = Pettanr.url(@panel.table_name(), 'show', {id: @panel.get('id')})\r
-    caption_url = Pettanr.url(@panel.table_name(), 'show', {id: @panel.get('id')})\r
-    prof_url = Pettanr.url(@panel.table_name(), 'show', {id: @panel.get('id'), format: 'prof'})\r
-    @header = new Pettanr.Views.Scroll.ShowModule.Header({\r
-      item: @panel, \r
-      operators: @operators,\r
-      caption: @panel.get('caption'), \r
-      icon_url: icon_url,\r
-      caption_url: caption_url,\r
-      prof_url: prof_url\r
-    })\r
+    @header = new Pettanr.View.Show.Header(@item, this, @default_header_options())\r
+    @authored_by = @item.authored_by()\r
     @body = new Pettanr.Views.Panel.Body({\r
       panel: @panel,\r
-      operators: @operators,\r
       spot: @spot\r
     })\r
-    @footer = new Pettanr.Views.Panel.Footer({\r
-      panel: @panel,\r
-      operators: @operators\r
-    })\r
-    @credits = new Pettanr.Views.Panel.Show.Credits({\r
-      pictures: @panel.licensed_pictures()\r
-    })\r
+    @footer = new Pettanr.Views.Panel.Show.Footer(@panel, this, {})\r
+    @owner = new Pettanr.View.Show.Footer(@item, this, @default_footer_options())\r
+    @listenTo(@header, 'click:pick', @click_pick)\r
+    @listenTo(@authored_by, 'click', @click_authored_by)\r
   \r
   render: () ->\r
     this.$el.html('')\r
     this.$el.append(@header.render().el)\r
+    this.$el.append(@authored_by.render().el)\r
     this.$el.append(@body.render().el)\r
     this.$el.append(@footer.render().el)\r
-    this.$el.append(@credits.render().el)\r
-    rb = new Tag.RowBreak()\r
-    this.$el.append(rb.render().el)\r
+    @add_credits()\r
+    this.$el.append(@owner.render().el) if @item.is_own()\r
     this\r
   \r
-class Pettanr.Views.Panel.Show.Credits extends Backbone.View\r
-  tagName: 'div'\r
-  className: 'credits'\r
+  click_pick: () ->\r
+    @trigger('pick', @item)\r
+  \r
+  is_pickable: () ->\r
+    true\r
+  \r
+  add_pick: (target_model) ->\r
+    @header.add_pick(target_model)\r
+  \r
+class Pettanr.Views.Panel.Show.Footer extends Pettanr.View\r
+  tagName: 'ul'\r
+  \r
+  constructor: (@panel, @context, options) ->\r
+    super(options)\r
   \r
   initialize: (options) ->\r
-    @pictures = options.pictures\r
+    super(options)\r
   \r
   render: () ->\r
+    super()\r
     this.$el.html('')\r
-    _.each @pictures, (picture) =>\r
-      @add_picture(picture)\r
+    this.$el.append(\r
+      Pettanr.AppHelper.distance_of_time_in_words_to_now(@panel.get('updated_at'))\r
+    )\r
+    if Pettanr.cache.operators.is_author()\r
+      inspire_button = Pettanr.View.mini_face_button(\r
+        @panel, \r
+        Pettanr.View.Image.icon_inspire_file(), {\r
+          context: @context,\r
+          click: () =>\r
+            inspire = new Pettanr.Inspire(@panel)\r
+            inspire.go(@context, {\r
+              success: (item) ->\r
+                @trigger('http_get', item.show_url())\r
+              fail: (response, opt) =>\r
+                @open_error_dialog(response, opt)\r
+            })\r
+        }\r
+      )\r
+      this.$el.append(inspire_button.render().el)\r
     this\r
   \r
-  add_picture: (picture) ->\r
-    if not @pictures[picture.get('id')]\r
-      picture.fetch({cache: true}).done =>\r
-        @pictures[picture.get('id')] = picture\r
-        credit = picture.credit_view()\r
-        this.$el.append(credit.render().el)\r
-  \r