OSDN Git Service

add cache
[pettanr/pettanr.git] / app / assets / javascripts / views / common.js.coffee
index e958bde..88ac3a1 100644 (file)
@@ -1,13 +1,40 @@
 class Pettanr.Views.Common\r
-class Pettanr.Views.Common.LoadIcon extends Tag.Img\r
+  @replace_empty: (caption) ->\r
+    if Pettanr.is_blank(caption)\r
+      empty = new Pettanr.Views.Common.EmptyCaption()\r
+      empty.render().el\r
+    else\r
+      caption\r
+  \r
+class Pettanr.Views.Common.Logo extends Tag.Span\r
+  id: 'logo'\r
   \r
   initialize: () ->\r
+    title = Manifest.manifest().magic_numbers['profile']['users']['caption']\r
+    @logo_button = new Tag.A({\r
+      attr: {href: '/'}, \r
+      class_name: 'logo',\r
+      content: _.escape(title)\r
+    })\r
+    @listenTo(@logo_button, 'click', @click)\r
+  \r
+  render: () ->\r
+    this.$el.html(@logo_button.render().el)\r
+    this\r
+  \r
+  click: () ->\r
+    @trigger('click')\r
+  \r
+\r
+class Pettanr.Views.Common.EmptyIcon extends Tag.Img\r
+  \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
@@ -16,7 +43,28 @@ 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.EmptyCaption extends Backbone.View\r
+  tagName: 'div'\r
+  className: 'empty'\r
+  \r
+  render: () ->\r
+    this.$el.html('empty')\r
+    this\r
+  \r
 class Pettanr.Views.Common.Icon extends Backbone.View\r
   tagName: 'span'\r
   \r
@@ -27,15 +75,21 @@ class Pettanr.Views.Common.Icon extends Backbone.View
     @icon = new Pettanr.Image.Icon({item: @item, half: @half})\r
     @icon_button = new Tag.A({\r
       attr: {href: '/' + @icon_url}, \r
-      handler_name: @icon_url,\r
       class_name: 'icon',\r
       content: @icon.render().el\r
     })\r
+    @listenTo(@icon_button, 'click', @click)\r
   \r
   render: () ->\r
     this.$el.html(@icon_button.render().el)\r
     this\r
   \r
+  click: () ->\r
+    @trigger('click')\r
+  \r
+  url: () ->\r
+    @icon_url\r
+  \r
 class Pettanr.Views.Common.Caption extends Backbone.View\r
   tagName: 'span'\r
   \r
@@ -47,14 +101,20 @@ class Pettanr.Views.Common.Caption extends Backbone.View
     @url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
     @linked_name = new Tag.A({\r
       attr: {href: '/' + @url}, \r
-      handler_name: @url,\r
-      content: @name\r
+      content: _.escape(@name)\r
     })\r
+    @listenTo(@linked_name, 'click', @click)\r
   \r
   render: () ->\r
     this.$el.html(@linked_name.render().el)\r
     this\r
   \r
+  click: () ->\r
+    @trigger('click')\r
+  \r
+  url: () ->\r
+    @url\r
+  \r
 class Pettanr.Views.Common.IconWithCaption extends Backbone.View\r
   tagName: 'span'\r
   \r
@@ -65,6 +125,8 @@ class Pettanr.Views.Common.IconWithCaption extends Backbone.View
     @length = options.length\r
     @icon = new Pettanr.Views.Common.Icon({item: @item, half: @half})\r
     @caption = new Pettanr.Views.Common.Caption({item: @item, column_name: @column_name, length: @length})\r
+    @listenTo(@icon, 'click', @click)\r
+    @listenTo(@caption, 'click', @click)\r
   \r
   render: () ->\r
     this.$el.html('')\r
@@ -72,6 +134,12 @@ class Pettanr.Views.Common.IconWithCaption extends Backbone.View
     this.$el.append(@caption.render().el)\r
     this\r
   \r
+  click: () ->\r
+    @trigger('click')\r
+  \r
+  url: () ->\r
+    @icon.url()\r
+  \r
 class Pettanr.Views.Common.Summary extends Backbone.View\r
   \r
   initialize: (options) ->\r
@@ -104,6 +172,7 @@ class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary
     @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
   \r
   render: () ->\r
@@ -112,6 +181,9 @@ class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary
     this.$el.append(@author_icon_with_caption.render().el)\r
     this\r
   \r
+  author_click: () ->\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
   \r
@@ -120,31 +192,59 @@ class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary
     @item = options.item\r
     @binder_item_name = options.binder_item_name\r
     @destination_item_name = options.destination_item_name\r
+    @binder_view = new Tag.Span({})\r
+    @destination_view = new Tag.Span({})\r
     @load()\r
   \r
   load: () ->\r
+    @listenTo(this, 'load_binder', @load_destination)\r
+    @listenTo(this, 'load_destination', @ready)\r
+    @load_binder()\r
+  \r
+  ready: () ->\r
+    @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
-        @trigger('ready')\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
-        @trigger('ready')\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
-    if @binder_author_icon_with_caption\r
-      this.$el.append(@binder_icon.render().el)\r
-      this.$el.append(@binder_author_icon_with_caption.render().el)\r
-    if @destination_author_icon_with_caption\r
-      this.$el.append(@destination_icon.render().el)\r
-      this.$el.append(@destination_author_icon_with_caption.render().el)\r
+    this.$el.append(@binder_view.render().el)\r
+    this.$el.append(@destination_view.render().el)\r
     this\r
   \r
+  binder_click: () ->\r
+    @trigger('http_get', @binder_icon.url())\r
+  \r
+  destination_click: () ->\r
+    @trigger('http_get', @destination_icon.url())\r
+  \r
+  binder_author_click: () ->\r
+    @trigger('http_get', @binder_author_icon_with_caption.url())\r
+  \r
+  destination_author_click: () ->\r
+    @trigger('http_get', @destination_author_icon_with_caption.url())\r
+  \r