OSDN Git Service

fix:
[pettanr/pettanr.git] / app / assets / javascripts / views / common.js.coffee
index 41bc2f6..c5c960b 100644 (file)
@@ -26,15 +26,15 @@ class Pettanr.Views.Common.Logo extends Tag.Span
     @trigger('click')\r
   \r
 \r
-class Pettanr.Views.Common.LoadIcon extends Tag.Img\r
+class Pettanr.Views.Common.EmptyIcon extends Tag.Img\r
   \r
-  initialize: () ->\r
+  initialize: (options) ->\r
     @attr = {}\r
     @width = Manifest.manifest().magic_numbers['thumbnail_width']\r
     @height = Manifest.manifest().magic_numbers['thumbnail_height']\r
     @width = Pettanr.to_i(@width/2)\r
     @height = Pettanr.to_i(@height/2)\r
-    @attr['src'] = '/images/loading.gif'\r
+    @attr['src'] = @file_name()\r
     @attr['width'] = @width\r
     @attr['height'] = @height\r
     @attr['alt'] = 'Loading'\r
@@ -43,7 +43,54 @@ class Pettanr.Views.Common.LoadIcon extends Tag.Img
       attr: @attr,\r
     }\r
     super(opt)\r
+    \r
+  file_name: () ->\r
+    '/images/empty.gif'\r
 \r
+class Pettanr.Views.Common.LoadIcon extends Pettanr.Views.Common.EmptyIcon\r
+  \r
+  file_name: () ->\r
+    '/images/loading.gif'\r
+  \r
+class Pettanr.Views.Common.RootIcon extends Pettanr.Views.Common.EmptyIcon\r
+  \r
+  file_name: () ->\r
+    '/images/root.png'\r
+  \r
+class Pettanr.Views.Common.PickIcon extends Backbone.View\r
+  \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
   className: 'empty'\r
@@ -156,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
@@ -168,8 +221,13 @@ 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('navigate', @author_icon_with_caption.url())\r
+    @trigger('http_get', @author_icon_with_caption.url())\r
   \r
 class Pettanr.Views.Common.Leaf\r
 class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary\r
@@ -224,14 +282,14 @@ class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary
     this\r
   \r
   binder_click: () ->\r
-    @trigger('navigate', @binder_icon.url())\r
+    @trigger('http_get', @binder_icon.url())\r
   \r
   destination_click: () ->\r
-    @trigger('navigate', @destination_icon.url())\r
+    @trigger('http_get', @destination_icon.url())\r
   \r
   binder_author_click: () ->\r
-    @trigger('navigate', @binder_author_icon_with_caption.url())\r
+    @trigger('http_get', @binder_author_icon_with_caption.url())\r
   \r
   destination_author_click: () ->\r
-    @trigger('navigate', @destination_author_icon_with_caption.url())\r
+    @trigger('http_get', @destination_author_icon_with_caption.url())\r
   \r