OSDN Git Service

fix: view system2
[pettanr/pettanr.git] / app / assets / javascripts / view / summary / leaf.js.coffee
diff --git a/app/assets/javascripts/view/summary/leaf.js.coffee b/app/assets/javascripts/view/summary/leaf.js.coffee
new file mode 100644 (file)
index 0000000..35dfb0a
--- /dev/null
@@ -0,0 +1,67 @@
+class Pettanr.View.Summary.Leaf extends Pettanr.View\r
+  \r
+  initialize: (options) ->\r
+    super(options)\r
+    @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
+    @item.get_parent(@binder_item_name, this, {\r
+      success: (@binder) =>\r
+        @binder_icon = @binder.icon_view(true)\r
+        @listenTo(@binder_icon, 'click', @binder_click)\r
+        @binder.get_parent('author', this, {\r
+          success: (@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
+    })\r
+  \r
+  load_destination: () ->\r
+    @item.get_parent(@destination_item_name, this, {\r
+      success: (@destination) =>\r
+        @destination_icon = @destination.icon_view(true)\r
+        @listenTo(@destination_icon, 'click', @destination_click)\r
+        @destination.get_parent('author', this, {\r
+          success: (@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
+    })\r
+  \r
+  render: () ->\r
+    this.$el.html('')\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