OSDN Git Service

change: cache system
[pettanr/pettanr.git] / app / assets / javascripts / views / common.js.coffee
index c5c960b..acc43bb 100644 (file)
@@ -203,17 +203,9 @@ 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
-    @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
+    retriever = @item.author()\r
+    @listenTo(retriever, 'retrieve', @retrieve_author)\r
+    retriever.retrieve()\r
   \r
   render: () ->\r
     this.$el.html('')\r
@@ -221,7 +213,7 @@ 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
+  retrieve_author: (@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
@@ -250,30 +242,42 @@ class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary
     @trigger('ready')\r
   \r
   load_binder: () ->\r
-    @binder = @item[@binder_item_name]()\r
-    @binder.fetch({cache: true}).done =>\r
-      @binder_icon = @binder.icon_view(true)\r
-      @listenTo(@binder_icon, 'click', @binder_click)\r
-      @binder_author = @binder.author()\r
-      @binder_author.fetch({cache: true}).done =>\r
-        @binder_author_icon_with_caption = @binder_author.icon_with_caption_view(true, 'name', 12)\r
-        @listenTo(@binder_author_icon_with_caption, 'click', @binder_author_click)\r
-        @binder_view.$el.append(@binder_icon.render().el)\r
-        @binder_view.$el.append(@binder_author_icon_with_caption.render().el)\r
-        @trigger('load_binder')\r
+    retriever = @item[@binder_item_name]()\r
+    @listenTo(retriever, 'retrieve', @retrieve_binder)\r
+    retriever.retrieve()\r
+  \r
+  retrieve_binder: (@binder) ->\r
+    @binder_icon = @binder.icon_view(true)\r
+    @listenTo(@binder_icon, 'click', @binder_click)\r
+    retriever = @binder.author()\r
+    @listenTo(retriever, 'retrieve', @retrieve_binder_author)\r
+    retriever.retrieve()\r
+  \r
+  retrieve_binder_author: (@binder_author) ->\r
+    @binder_author_icon_with_caption = @binder_author.icon_with_caption_view(true, 'name', 12)\r
+    @listenTo(@binder_author_icon_with_caption, 'click', @binder_author_click)\r
+    @binder_view.$el.append(@binder_icon.render().el)\r
+    @binder_view.$el.append(@binder_author_icon_with_caption.render().el)\r
+    @trigger('load_binder')\r
   \r
   load_destination: () ->\r
-    @destination = @item[@destination_item_name]()\r
-    @destination.fetch({cache: true}).done =>\r
-      @destination_icon = @destination.icon_view(true)\r
-      @listenTo(@destination_icon, 'click', @destination_click)\r
-      @destination_author = @destination.author()\r
-      @destination_author.fetch({cache: true}).done =>\r
-        @destination_author_icon_with_caption = @destination_author.icon_with_caption_view(true, 'name', 12)\r
-        @listenTo(@destination_author_icon_with_caption, 'click', @destination_author_click)\r
-        @destination_view.$el.append(@destination_icon.render().el)\r
-        @destination_view.$el.append(@destination_author_icon_with_caption.render().el)\r
-        @trigger('load_destination')\r
+    retriever = @item[@destination_item_name]()\r
+    @listenTo(retriever, 'retrieve', @retrieve_destination)\r
+    retriever.retrieve()\r
+  \r
+  retrieve_destination: (@destination) ->\r
+    @destination_icon = @destination.icon_view(true)\r
+    @listenTo(@destination_icon, 'click', @destination_click)\r
+    retriever = @destination.author()\r
+    @listenTo(retriever, 'retrieve', @retrieve_destination_author)\r
+    retriever.retrieve()\r
+  \r
+  retrieve_destination_author: (@destination_author) ->\r
+    @destination_author_icon_with_caption = @destination_author.icon_with_caption_view(true, 'name', 12)\r
+    @listenTo(@destination_author_icon_with_caption, 'click', @destination_author_click)\r
+    @destination_view.$el.append(@destination_icon.render().el)\r
+    @destination_view.$el.append(@destination_author_icon_with_caption.render().el)\r
+    @trigger('load_destination')\r
   \r
   render: () ->\r
     this.$el.html('')\r