OSDN Git Service

add app body
[pettanr/pettanr.git] / app / assets / javascripts / views / panels / show.js.coffee
index 6e34cdb..bbfb829 100644 (file)
@@ -9,16 +9,13 @@ class Pettanr.Views.Panel.Show extends Backbone.View
     @operators = options.operators\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
+    @header = new Pettanr.Views.Panel.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
+      icon_url: @panel.show_url(),\r
+      caption_url: @panel.show_url(),\r
+      prof_url: @panel.prof_url()\r
     })\r
     @body = new Pettanr.Views.Panel.Body({\r
       panel: @panel,\r
@@ -29,9 +26,16 @@ class Pettanr.Views.Panel.Show extends Backbone.View
       panel: @panel,\r
       operators: @operators\r
     })\r
-    @credits = new Pettanr.Views.Panel.Show.Credits({\r
+    @credits = new Pettanr.Views.Panel.ShowModule.Credits({\r
       pictures: @panel.licensed_pictures()\r
     })\r
+    @listenTo(@header, 'click:icon', @click_show)\r
+    @listenTo(@header, 'click:caption', @click_show)\r
+    @listenTo(@header, 'click:prof', @click_prof)\r
+    @listenTo(@footer, 'click:panel', @click_show)\r
+    @listenTo(@footer, 'click:author', @click_author)\r
+    @listenTo(@footer, 'click:edit', @click_edit)\r
+    @listenTo(@credits, 'click:credit:icon', @click_credit_icon)\r
   \r
   render: () ->\r
     this.$el.html('')\r
@@ -43,23 +47,52 @@ class Pettanr.Views.Panel.Show extends Backbone.View
     this.$el.append(rb.render().el)\r
     this\r
   \r
-class Pettanr.Views.Panel.Show.Credits extends Backbone.View\r
+  click_show: () ->\r
+    window.router.navigate(@panel.show_url(), true)\r
+  \r
+  click_author: () ->\r
+    window.router.navigate(@panel.author().show_url(), true)\r
+  \r
+  click_edit: () ->\r
+    window.router.navigate(@panel.edit_url(), true)\r
+  \r
+  click_prof: () ->\r
+    window.router.navigate(@panel.prof_url(), true)\r
+  \r
+  click_credit_icon: (item) ->\r
+    window.router.navigate(item.show_url(), true)\r
+  \r
+class Pettanr.Views.Panel.ShowModule\r
+class Pettanr.Views.Panel.ShowModule.Header extends Pettanr.Views.Show.Header\r
+  \r
+  initialize: (options) ->\r
+    super(options)\r
+  \r
+class Pettanr.Views.Panel.ShowModule.Credits extends Backbone.View\r
   tagName: 'div'\r
   className: 'credits'\r
   \r
   initialize: (options) ->\r
     @pictures = options.pictures\r
+    @credited = {}\r
   \r
   render: () ->\r
     this.$el.html('')\r
-    _.each @pictures, (picture) =>\r
+    _.each @pictures, (picture, pid) =>\r
       @add_picture(picture)\r
     this\r
   \r
   add_picture: (picture) ->\r
-    if not @pictures[picture.get('id')]\r
+  \r
+  add_picture: (picture) ->\r
+    pid = picture.get('id')\r
+    if not @credited[pid]\r
       picture.fetch({cache: true}).done =>\r
-        @pictures[picture.get('id')] = picture\r
+        @credited[pid] = picture\r
         credit = picture.credit_view()\r
+        @listenTo(credit, 'click:icon', @click_credit_icon)\r
         this.$el.append(credit.render().el)\r
   \r
+  click_credit_icon: (item) ->\r
+    @trigger('click:credit:icon', item)\r
+  \r