OSDN Git Service

operator move to cache
[pettanr/pettanr.git] / app / assets / javascripts / views / show.js.coffee
index d4eaeee..d1f16aa 100644 (file)
@@ -5,56 +5,78 @@ class Pettanr.Views.Show.Header extends Backbone.View
   \r
   initialize: (options) ->\r
     @item = options.item\r
-    @operators = options.operators\r
     @title = options.caption\r
     @icon_url = options.icon_url\r
     @caption_url = options.caption_url\r
     @prof_url = options.prof_url\r
     \r
+    @pick = null\r
     @icon = new Pettanr.Image.Icon({item: @item, half: true})\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
     @caption = new Tag.A({\r
       attr: {href: '/' + @caption_url},\r
-      handler_name: @caption_url,\r
       class_name: 'caption',\r
-      content: @title\r
+      content: _.escape(@title)\r
     })\r
     @prof = new Pettanr.Image.SymbolImg({attr: {src: '/images/prof.gif'}, half: true})\r
     @prof_button = new Tag.A({\r
       attr: {href: '/' + @prof_url}, \r
-      handler_name: @prof_url,\r
       class_name: 'prof',\r
       content: @prof.render().el\r
     })\r
+    @listenTo(@icon, 'click', @click_icon)\r
+    @listenTo(@caption, 'click', @click_caption)\r
+    @listenTo(@prof_button, 'click', @click_prof)\r
   \r
   render: () ->\r
     this.$el.html('')\r
+    this.$el.append(@pick.render().el) if @pick\r
     this.$el.append(@icon_button.render().el)\r
     this.$el.append(@caption.render().el)\r
     this.$el.append(@prof_button.render().el)\r
     this\r
   \r
+  click_pick: () ->\r
+    @trigger('click:pick')\r
+  \r
+  click_icon: () ->\r
+    @trigger('click:icon')\r
+  \r
+  click_caption: () ->\r
+    @trigger('click:caption')\r
+  \r
+  click_prof: () ->\r
+    @trigger('click:prof')\r
+  \r
+  add_pick: (target_model) ->\r
+    @pick = new Pettanr.Views.Common.PickIcon({\r
+      name: target_model.pick_type(@item.item_name()), half: true\r
+    })\r
+    @listenTo(@pick, 'click', @click_pick)\r
+    @render()\r
+  \r
 class Pettanr.Views.Show.HeaderAuthor extends Backbone.View\r
   tagName: 'div'\r
   \r
   initialize: (options) ->\r
     @item = options.item\r
-    _this = this\r
-    @author = @item.author()\r
-    @author.fetch({cache: true}).done ->\r
-      name = _this.author.get('name')\r
-      author_url = Pettanr.url(_this.author.table_name(), 'show', {id: _this.author.get('id')})\r
-      _this.linked_author =  new Tag.A({\r
-        attr: {href: '/' + author_url}, \r
-        handler_name: author_url,\r
-        content: name\r
-      })\r
-      _this.render()\r
+    retriever = @item.author()\r
+    @listenTo(retriever, 'retrieve', @retrieve_author)\r
+    retriever.retrieve()\r
+    \r
+  retrieve_author: (@author) ->\r
+    name = @author.escape('name')\r
+    author_url = @author.show_url()\r
+    @linked_author =  new Tag.A({\r
+      attr: {href: '/' + author_url}, \r
+      content: name\r
+    })\r
+    @listenTo(@linked_author, 'click', @click)\r
+    @render()\r
   \r
   render: () ->\r
     this.$el.html('')\r
@@ -62,6 +84,33 @@ class Pettanr.Views.Show.HeaderAuthor extends Backbone.View
     this.$el.append(@linked_author.render().el) if @linked_author\r
     this\r
   \r
+  click: () ->\r
+    @trigger('click:author')\r
+  \r
+class Pettanr.Views.Show.LinkedEditButton extends Tag.A\r
+  \r
+  initialize: (options) ->\r
+    item = options.item\r
+    super({\r
+      attr: {href: '/' + item.edit_url()}, \r
+      content: I18n.t('link.edit')\r
+    })\r
+  \r
+  url: () ->\r
+    @url\r
+  \r
+class Pettanr.Views.Show.LinkedDestroyButton extends Tag.A\r
+  \r
+  initialize: (options) ->\r
+    item = options.item\r
+    super({\r
+      attr: {href: '/' + item.destroy_url()}, \r
+      content: I18n.t('link.destroy')\r
+    })\r
+  \r
+  url: () ->\r
+    @destroy_url\r
+  \r
 class Pettanr.Views.Show.OwnerFooter extends Backbone.View\r
   tagName: 'div'\r
   className: 'show-owner-footer'\r
@@ -69,19 +118,10 @@ class Pettanr.Views.Show.OwnerFooter extends Backbone.View
   initialize: (options) ->\r
     super(options)\r
     @item = options.item\r
-    @operators = options.operators\r
-    @edit_url = Pettanr.url(@item.table_name(), 'edit', {id: @item.get('id')})\r
-    @edit =  new Tag.A({\r
-      attr: {href: '/' + @edit_url}, \r
-      handler_name: @edit_url,\r
-      content: I18n.t('link.edit')\r
-    })\r
-    @destroy_url = Pettanr.url(@item.table_name(), 'destroy', {id: @item.get('id')})\r
-    @destroy =  new Tag.A({\r
-      attr: {href: '/' + @destroy_url}, \r
-      handler_name: @destroy_url,\r
-      content: I18n.t('link.destroy')\r
-    })\r
+    @edit = new Pettanr.Views.Show.LinkedEditButton({item: @item})\r
+    @destroy = new Pettanr.Views.Show.LinkedDestroyButton({item: @item})\r
+    @listenTo(@edit, 'click', @click_edit)\r
+    @listenTo(@destroy, 'click', @click_destroy)\r
   \r
   render: () ->\r
     this.$el.html('')\r
@@ -89,18 +129,25 @@ class Pettanr.Views.Show.OwnerFooter extends Backbone.View
     this.$el.append(@destroy.render().el)\r
     this\r
   \r
+  click_edit: () ->\r
+    @trigger('click:edit')\r
+  \r
+  click_destroy: () ->\r
+    @trigger('click:destroy')\r
+  \r
 class Pettanr.Views.Show.Owner extends Backbone.View\r
   tagName: 'div'\r
   \r
   initialize: (options) ->\r
     super(options)\r
     @item = options.item\r
-    @operators = options.operators\r
     @header = new Tag.H3({\r
       class_name: 'owner-header',\r
       content: I18n.t('editor')\r
     })\r
-    @footer = new Pettanr.Views.Show.OwnerFooter({item: @item, operators: @operators})\r
+    @footer = new Pettanr.Views.Show.OwnerFooter({item: @item})\r
+    @listenTo(@footer, 'click:edit', @click_edit)\r
+    @listenTo(@footer, 'click:destroy', @click_destroy)\r
   \r
   render: () ->\r
     this.$el.html('')\r
@@ -108,3 +155,11 @@ class Pettanr.Views.Show.Owner extends Backbone.View
     this.$el.append(@footer.render().el)\r
     this\r
   \r
+  click_edit: () ->\r
+    @trigger('click:footer:edit')\r
+    @trigger('click:edit')\r
+  \r
+  click_destroy: () ->\r
+    @trigger('click:footer:destroy')\r
+    @trigger('click:destroy')\r
+  \r