OSDN Git Service

fix:
[pettanr/pettanr.git] / app / assets / javascripts / views / common.js.coffee
index 002b161..c5c960b 100644 (file)
@@ -52,15 +52,44 @@ class Pettanr.Views.Common.LoadIcon extends Pettanr.Views.Common.EmptyIcon
   file_name: () ->\r
     '/images/loading.gif'\r
   \r
-class Pettanr.Views.Common.BackIcon extends Pettanr.Views.Common.EmptyIcon\r
+class Pettanr.Views.Common.RootIcon extends Pettanr.Views.Common.EmptyIcon\r
   \r
   file_name: () ->\r
-    '/images/back.gif'\r
+    '/images/root.png'\r
   \r
-class Pettanr.Views.Common.ForwardIcon extends Pettanr.Views.Common.EmptyIcon\r
+class Pettanr.Views.Common.PickIcon extends Backbone.View\r
   \r
-  file_name: () ->\r
-    '/images/forward.gif'\r
+  initialize: (options) ->\r
+    @class_name = options.class_name\r
+    @name = options.name\r
+    @half = options.half\r
+    @button = if @is_button()\r
+      @linked_icon()\r
+    else\r
+      @icon()\r
+  \r
+  render: () ->\r
+    this.$el.html('')\r
+    @el.className = @class_name if @class_name\r
+    if @is_button()\r
+      @listenTo(@button, 'click', @click)\r
+    this.$el.append(@button.render().el)\r
+    this\r
+  \r
+  is_button: () ->\r
+    @name != 'none'\r
+  \r
+  icon: () ->\r
+    new Pettanr.Image.SymbolImg({attr: {src: '/images/' + @name + '.gif'}, half: @half})\r
+  \r
+  linked_icon: () ->\r
+    new Tag.A({\r
+      attr: {href: '#'},\r
+      content: @icon().render().el\r
+    })\r
+  \r
+  click: () ->\r
+    @trigger('click', this)\r
   \r
 class Pettanr.Views.Common.EmptyCaption extends Backbone.View\r
   tagName: 'div'\r
@@ -174,11 +203,17 @@ class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary
     @visible = new Tag.Div({\r
       content: Pettanr.AppHelper.t_selected_item(@visible_t, @item.get(@visible_column_name))\r
     })\r
-    @author = @item.author()\r
-    @author.fetch({cache: true}).done =>\r
-      @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12)\r
-      @listenTo(@author_icon_with_caption, 'click', @author_click)\r
-      @trigger('ready')\r
+    @empty_author = @item.author()\r
+    @author = Pettanr.cache.restore(@empty_author)\r
+    if @author\r
+      # got cached author\r
+      @render_author()\r
+    else\r
+      # built empty author\r
+      @author = @empty_author\r
+      @author.fetch({cache: true}).done =>\r
+        Pettanr.cache.store(@author)\r
+        @render_author()\r
   \r
   render: () ->\r
     this.$el.html('')\r
@@ -186,6 +221,11 @@ class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary
     this.$el.append(@author_icon_with_caption.render().el)\r
     this\r
   \r
+  render_author: () ->\r
+    @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12)\r
+    @listenTo(@author_icon_with_caption, 'click', @author_click)\r
+    @trigger('ready')\r
+  \r
   author_click: () ->\r
     @trigger('http_get', @author_icon_with_caption.url())\r
   \r