OSDN Git Service

fix event names
[pettanr/pettanr.git] / app / assets / javascripts / views / common.js.coffee
1 class Pettanr.Views.Common\r
2   @replace_empty: (caption) ->\r
3     if Pettanr.is_blank(caption)\r
4       empty = new Pettanr.Views.Common.EmptyCaption()\r
5       empty.render().el\r
6     else\r
7       caption\r
8   \r
9 class Pettanr.Views.Common.Logo extends Tag.Span\r
10   id: 'logo'\r
11   \r
12   initialize: () ->\r
13     title = Manifest.manifest().magic_numbers['profile']['users']['caption']\r
14     @logo_button = new Tag.A({\r
15       attr: {href: '/'}, \r
16       class_name: 'logo',\r
17       content: _.escape(title)\r
18     })\r
19     @listenTo(@logo_button, 'click', @click)\r
20   \r
21   render: () ->\r
22     this.$el.html(@logo_button.render().el)\r
23     this\r
24   \r
25   click: () ->\r
26     @trigger('click')\r
27   \r
28 \r
29 class Pettanr.Views.Common.LoadIcon extends Tag.Img\r
30   \r
31   initialize: () ->\r
32     @attr = {}\r
33     @width = Manifest.manifest().magic_numbers['thumbnail_width']\r
34     @height = Manifest.manifest().magic_numbers['thumbnail_height']\r
35     @width = Pettanr.to_i(@width/2)\r
36     @height = Pettanr.to_i(@height/2)\r
37     @attr['src'] = '/images/loading.gif'\r
38     @attr['width'] = @width\r
39     @attr['height'] = @height\r
40     @attr['alt'] = 'Loading'\r
41     @attr['title'] = 'Loading'\r
42     opt = {\r
43       attr: @attr,\r
44     }\r
45     super(opt)\r
46 \r
47 class Pettanr.Views.Common.EmptyCaption extends Backbone.View\r
48   tagName: 'div'\r
49   className: 'empty'\r
50   \r
51   render: () ->\r
52     this.$el.html('empty')\r
53     this\r
54   \r
55 class Pettanr.Views.Common.Icon extends Backbone.View\r
56   tagName: 'span'\r
57   \r
58   initialize: (options) ->\r
59     @item = options.item\r
60     @half = options.half\r
61     @icon_url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
62     @icon = new Pettanr.Image.Icon({item: @item, half: @half})\r
63     @icon_button = new Tag.A({\r
64       attr: {href: '/' + @icon_url}, \r
65       class_name: 'icon',\r
66       content: @icon.render().el\r
67     })\r
68     @listenTo(@icon_button, 'click', @click)\r
69   \r
70   render: () ->\r
71     this.$el.html(@icon_button.render().el)\r
72     this\r
73   \r
74   click: () ->\r
75     @trigger('click')\r
76   \r
77   url: () ->\r
78     @icon_url\r
79   \r
80 class Pettanr.Views.Common.Caption extends Backbone.View\r
81   tagName: 'span'\r
82   \r
83   initialize: (options) ->\r
84     @item = options.item\r
85     @column_name = options.column_name\r
86     @length = options.length\r
87     @name = Pettanr.truncate(@item.get(@column_name), @length)\r
88     @url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
89     @linked_name = new Tag.A({\r
90       attr: {href: '/' + @url}, \r
91       content: _.escape(@name)\r
92     })\r
93     @listenTo(@linked_name, 'click', @click)\r
94   \r
95   render: () ->\r
96     this.$el.html(@linked_name.render().el)\r
97     this\r
98   \r
99   click: () ->\r
100     @trigger('click')\r
101   \r
102   url: () ->\r
103     @url\r
104   \r
105 class Pettanr.Views.Common.IconWithCaption extends Backbone.View\r
106   tagName: 'span'\r
107   \r
108   initialize: (options) ->\r
109     @item = options.item\r
110     @half = options.half\r
111     @column_name = options.column_name\r
112     @length = options.length\r
113     @icon = new Pettanr.Views.Common.Icon({item: @item, half: @half})\r
114     @caption = new Pettanr.Views.Common.Caption({item: @item, column_name: @column_name, length: @length})\r
115     @listenTo(@icon, 'click', @click)\r
116     @listenTo(@caption, 'click', @click)\r
117   \r
118   render: () ->\r
119     this.$el.html('')\r
120     this.$el.append(@icon.render().el)\r
121     this.$el.append(@caption.render().el)\r
122     this\r
123   \r
124   click: () ->\r
125     @trigger('click')\r
126   \r
127   url: () ->\r
128     @icon.url()\r
129   \r
130 class Pettanr.Views.Common.Summary extends Backbone.View\r
131   \r
132   initialize: (options) ->\r
133     @clear()\r
134     @listenTo(this, 'ready', @render)\r
135   \r
136   clear: () ->\r
137     icon = new Pettanr.Views.Common.LoadIcon()\r
138     this.$el.html(icon.render().el)\r
139     this\r
140   \r
141   render: () ->\r
142     this.$el.html('')\r
143     this\r
144   \r
145 class Pettanr.Views.Common.Binder\r
146 class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary\r
147   \r
148   initialize: (options) ->\r
149     super(options)\r
150     @item = options.item\r
151     @visible_t = options.visible_t\r
152     @visible_column_name = options.visible_column_name\r
153     @load()\r
154   \r
155   load: () ->\r
156     @visible = new Tag.Div({\r
157       content: Pettanr.AppHelper.t_selected_item(@visible_t, @item.get(@visible_column_name))\r
158     })\r
159     @author = @item.author()\r
160     @author.fetch({cache: true}).done =>\r
161       @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12)\r
162       @listenTo(@author_icon_with_caption, 'click', @author_click)\r
163       @trigger('ready')\r
164   \r
165   render: () ->\r
166     this.$el.html('')\r
167     this.$el.append(@visible.render().el)\r
168     this.$el.append(@author_icon_with_caption.render().el)\r
169     this\r
170   \r
171   author_click: () ->\r
172     @trigger('http_get', @author_icon_with_caption.url())\r
173   \r
174 class Pettanr.Views.Common.Leaf\r
175 class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary\r
176   \r
177   initialize: (options) ->\r
178     super(options)\r
179     @item = options.item\r
180     @binder_item_name = options.binder_item_name\r
181     @destination_item_name = options.destination_item_name\r
182     @binder_view = new Tag.Span({})\r
183     @destination_view = new Tag.Span({})\r
184     @load()\r
185   \r
186   load: () ->\r
187     @listenTo(this, 'load_binder', @load_destination)\r
188     @listenTo(this, 'load_destination', @ready)\r
189     @load_binder()\r
190   \r
191   ready: () ->\r
192     @trigger('ready')\r
193   \r
194   load_binder: () ->\r
195     @binder = @item[@binder_item_name]()\r
196     @binder.fetch({cache: true}).done =>\r
197       @binder_icon = @binder.icon_view(true)\r
198       @listenTo(@binder_icon, 'click', @binder_click)\r
199       @binder_author = @binder.author()\r
200       @binder_author.fetch({cache: true}).done =>\r
201         @binder_author_icon_with_caption = @binder_author.icon_with_caption_view(true, 'name', 12)\r
202         @listenTo(@binder_author_icon_with_caption, 'click', @binder_author_click)\r
203         @binder_view.$el.append(@binder_icon.render().el)\r
204         @binder_view.$el.append(@binder_author_icon_with_caption.render().el)\r
205         @trigger('load_binder')\r
206   \r
207   load_destination: () ->\r
208     @destination = @item[@destination_item_name]()\r
209     @destination.fetch({cache: true}).done =>\r
210       @destination_icon = @destination.icon_view(true)\r
211       @listenTo(@destination_icon, 'click', @destination_click)\r
212       @destination_author = @destination.author()\r
213       @destination_author.fetch({cache: true}).done =>\r
214         @destination_author_icon_with_caption = @destination_author.icon_with_caption_view(true, 'name', 12)\r
215         @listenTo(@destination_author_icon_with_caption, 'click', @destination_author_click)\r
216         @destination_view.$el.append(@destination_icon.render().el)\r
217         @destination_view.$el.append(@destination_author_icon_with_caption.render().el)\r
218         @trigger('load_destination')\r
219   \r
220   render: () ->\r
221     this.$el.html('')\r
222     this.$el.append(@binder_view.render().el)\r
223     this.$el.append(@destination_view.render().el)\r
224     this\r
225   \r
226   binder_click: () ->\r
227     @trigger('http_get', @binder_icon.url())\r
228   \r
229   destination_click: () ->\r
230     @trigger('http_get', @destination_icon.url())\r
231   \r
232   binder_author_click: () ->\r
233     @trigger('http_get', @binder_author_icon_with_caption.url())\r
234   \r
235   destination_author_click: () ->\r
236     @trigger('http_get', @destination_author_icon_with_caption.url())\r
237   \r