OSDN Git Service

fix:replace row break
[pettanr/pettanr.git] / app / assets / javascripts / views / common.js.coffee
index ca22d5e..6280e56 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,8 +43,55 @@ 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.EmptyCaption extends Backbone.View\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 Pettanr.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 Pettanr.View\r
   tagName: 'div'\r
   className: 'empty'\r
   \r
@@ -52,7 +99,7 @@ class Pettanr.Views.Common.EmptyCaption extends Backbone.View
     this.$el.html('empty')\r
     this\r
   \r
-class Pettanr.Views.Common.Icon extends Backbone.View\r
+class Pettanr.Views.Common.Icon extends Pettanr.View\r
   tagName: 'span'\r
   \r
   initialize: (options) ->\r
@@ -77,7 +124,7 @@ class Pettanr.Views.Common.Icon extends Backbone.View
   url: () ->\r
     @icon_url\r
   \r
-class Pettanr.Views.Common.Caption extends Backbone.View\r
+class Pettanr.Views.Common.Caption extends Pettanr.View\r
   tagName: 'span'\r
   \r
   initialize: (options) ->\r
@@ -102,7 +149,7 @@ class Pettanr.Views.Common.Caption extends Backbone.View
   url: () ->\r
     @url\r
   \r
-class Pettanr.Views.Common.IconWithCaption extends Backbone.View\r
+class Pettanr.Views.Common.IconWithCaption extends Pettanr.View\r
   tagName: 'span'\r
   \r
   initialize: (options) ->\r
@@ -127,7 +174,7 @@ class Pettanr.Views.Common.IconWithCaption extends Backbone.View
   url: () ->\r
     @icon.url()\r
   \r
-class Pettanr.Views.Common.Summary extends Backbone.View\r
+class Pettanr.Views.Common.Summary extends Pettanr.View\r
   \r
   initialize: (options) ->\r
     @clear()\r
@@ -156,11 +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
-    @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
+    retriever = @item.author()\r
+    @listenTo(retriever, 'retrieve', @retrieve_author)\r
+    retriever.retrieve()\r
   \r
   render: () ->\r
     this.$el.html('')\r
@@ -168,6 +213,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
+  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
+  \r
   author_click: () ->\r
     @trigger('http_get', @author_icon_with_caption.url())\r
   \r
@@ -192,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