OSDN Git Service

fix:asoc system
[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.EmptyIcon extends Tag.Img\r
30   \r
31   initialize: (options) ->\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'] = @file_name()\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   file_name: () ->\r
48     '/images/empty.gif'\r
49 \r
50 class Pettanr.Views.Common.LoadIcon extends Pettanr.Views.Common.EmptyIcon\r
51   \r
52   file_name: () ->\r
53     '/images/loading.gif'\r
54   \r
55 class Pettanr.Views.Common.RootIcon extends Pettanr.Views.Common.EmptyIcon\r
56   \r
57   file_name: () ->\r
58     '/images/root.png'\r
59   \r
60 class Pettanr.Views.Common.PickIcon extends Pettanr.View\r
61   \r
62   initialize: (options) ->\r
63     @class_name = options.class_name\r
64     @name = options.name\r
65     @half = options.half\r
66     @button = if @is_button()\r
67       @linked_icon()\r
68     else\r
69       @icon()\r
70   \r
71   render: () ->\r
72     this.$el.html('')\r
73     @el.className = @class_name if @class_name\r
74     if @is_button()\r
75       @listenTo(@button, 'click', @click)\r
76     this.$el.append(@button.render().el)\r
77     this\r
78   \r
79   is_button: () ->\r
80     @name != 'none'\r
81   \r
82   icon: () ->\r
83     new Pettanr.Image.SymbolImg({attr: {src: '/images/' + @name + '.gif'}, half: @half})\r
84   \r
85   linked_icon: () ->\r
86     new Tag.A({\r
87       attr: {href: '#'},\r
88       content: @icon().render().el\r
89     })\r
90   \r
91   click: () ->\r
92     @trigger('click', this)\r
93   \r
94 class Pettanr.Views.Common.EmptyCaption extends Pettanr.View\r
95   tagName: 'div'\r
96   className: 'empty'\r
97   \r
98   render: () ->\r
99     this.$el.html('empty')\r
100     this\r
101   \r
102 class Pettanr.Views.Common.Icon extends Pettanr.View\r
103   tagName: 'span'\r
104   \r
105   initialize: (options) ->\r
106     @item = options.item\r
107     @half = options.half\r
108     @icon_url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
109     @icon = new Pettanr.Image.Icon({item: @item, half: @half})\r
110     @icon_button = new Tag.A({\r
111       attr: {href: '/' + @icon_url}, \r
112       class_name: 'icon',\r
113       content: @icon.render().el\r
114     })\r
115     @listenTo(@icon_button, 'click', @click)\r
116   \r
117   render: () ->\r
118     this.$el.html(@icon_button.render().el)\r
119     this\r
120   \r
121   click: () ->\r
122     @trigger('click')\r
123   \r
124   url: () ->\r
125     @icon_url\r
126   \r
127 class Pettanr.Views.Common.Caption extends Pettanr.View\r
128   tagName: 'span'\r
129   \r
130   initialize: (options) ->\r
131     @item = options.item\r
132     @column_name = options.column_name\r
133     @length = options.length\r
134     @name = Pettanr.truncate(@item.get(@column_name), @length)\r
135     @url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
136     @linked_name = new Tag.A({\r
137       attr: {href: '/' + @url}, \r
138       content: _.escape(@name)\r
139     })\r
140     @listenTo(@linked_name, 'click', @click)\r
141   \r
142   render: () ->\r
143     this.$el.html(@linked_name.render().el)\r
144     this\r
145   \r
146   click: () ->\r
147     @trigger('click')\r
148   \r
149   url: () ->\r
150     @url\r
151   \r
152 class Pettanr.Views.Common.IconWithCaption extends Pettanr.View\r
153   tagName: 'span'\r
154   \r
155   initialize: (options) ->\r
156     @item = options.item\r
157     @half = options.half\r
158     @column_name = options.column_name\r
159     @length = options.length\r
160     @icon = new Pettanr.Views.Common.Icon({item: @item, half: @half})\r
161     @caption = new Pettanr.Views.Common.Caption({item: @item, column_name: @column_name, length: @length})\r
162     @listenTo(@icon, 'click', @click)\r
163     @listenTo(@caption, 'click', @click)\r
164   \r
165   render: () ->\r
166     this.$el.html('')\r
167     this.$el.append(@icon.render().el)\r
168     this.$el.append(@caption.render().el)\r
169     this\r
170   \r
171   click: () ->\r
172     @trigger('click')\r
173   \r
174   url: () ->\r
175     @icon.url()\r
176   \r
177 class Pettanr.Views.Common.Summary extends Pettanr.View\r
178   \r
179   initialize: (options) ->\r
180     @clear()\r
181     @listenTo(this, 'ready', @render)\r
182   \r
183   clear: () ->\r
184     icon = new Pettanr.Views.Common.LoadIcon()\r
185     this.$el.html(icon.render().el)\r
186     this\r
187   \r
188   render: () ->\r
189     this.$el.html('')\r
190     this\r
191   \r
192 class Pettanr.Views.Common.Binder\r
193 class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary\r
194   \r
195   initialize: (options) ->\r
196     super(options)\r
197     @item = options.item\r
198     @visible_t = options.visible_t\r
199     @visible_column_name = options.visible_column_name\r
200     @load()\r
201   \r
202   load: () ->\r
203     @visible = new Tag.Div({\r
204       content: Pettanr.AppHelper.t_selected_item(@visible_t, @item.get(@visible_column_name))\r
205     })\r
206     @item.get_parent('author', this, {\r
207       success: (@author) =>\r
208         @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12)\r
209         @listenTo(@author_icon_with_caption, 'click', @author_click)\r
210         @trigger('ready')\r
211     })\r
212   \r
213   render: () ->\r
214     this.$el.html('')\r
215     this.$el.append(@visible.render().el)\r
216     this.$el.append(@author_icon_with_caption.render().el)\r
217     this\r
218   \r
219   author_click: () ->\r
220     @trigger('http_get', @author_icon_with_caption.url())\r
221   \r
222 class Pettanr.Views.Common.Leaf\r
223 class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary\r
224   \r
225   initialize: (options) ->\r
226     super(options)\r
227     @item = options.item\r
228     @binder_item_name = options.binder_item_name\r
229     @destination_item_name = options.destination_item_name\r
230     @binder_view = new Tag.Span({})\r
231     @destination_view = new Tag.Span({})\r
232     @load()\r
233   \r
234   load: () ->\r
235     @listenTo(this, 'load_binder', @load_destination)\r
236     @listenTo(this, 'load_destination', @ready)\r
237     @load_binder()\r
238   \r
239   ready: () ->\r
240     @trigger('ready')\r
241   \r
242   load_binder: () ->\r
243     @item.get_parent(@binder_item_name, this, {\r
244       success: (@binder) =>\r
245         @binder_icon = @binder.icon_view(true)\r
246         @listenTo(@binder_icon, 'click', @binder_click)\r
247         @binder.get_parent('author', this, {\r
248           success: (@binder_author) =>\r
249             @binder_author_icon_with_caption = @binder_author.icon_with_caption_view(true, 'name', 12)\r
250             @listenTo(@binder_author_icon_with_caption, 'click', @binder_author_click)\r
251             @binder_view.$el.append(@binder_icon.render().el)\r
252             @binder_view.$el.append(@binder_author_icon_with_caption.render().el)\r
253             @trigger('load_binder')\r
254         })\r
255     })\r
256   \r
257   load_destination: () ->\r
258     @item.get_parent(@destination_item_name, this, {\r
259       success: (@destination) =>\r
260         @destination_icon = @destination.icon_view(true)\r
261         @listenTo(@destination_icon, 'click', @destination_click)\r
262         @destination.get_parent('author', this, {\r
263           success: (@destination_author) =>\r
264             @destination_author_icon_with_caption = @destination_author.icon_with_caption_view(true, 'name', 12)\r
265             @listenTo(@destination_author_icon_with_caption, 'click', @destination_author_click)\r
266             @destination_view.$el.append(@destination_icon.render().el)\r
267             @destination_view.$el.append(@destination_author_icon_with_caption.render().el)\r
268             @trigger('load_destination')\r
269         })\r
270     })\r
271   \r
272   render: () ->\r
273     this.$el.html('')\r
274     this.$el.append(@binder_view.render().el)\r
275     this.$el.append(@destination_view.render().el)\r
276     this\r
277   \r
278   binder_click: () ->\r
279     @trigger('http_get', @binder_icon.url())\r
280   \r
281   destination_click: () ->\r
282     @trigger('http_get', @destination_icon.url())\r
283   \r
284   binder_author_click: () ->\r
285     @trigger('http_get', @binder_author_icon_with_caption.url())\r
286   \r
287   destination_author_click: () ->\r
288     @trigger('http_get', @destination_author_icon_with_caption.url())\r
289   \r
290 class Pettanr.Views.Common.Credits extends Pettanr.View\r
291   tagName: 'div'\r
292   className: 'credits'\r
293   \r
294   initialize: (options) ->\r
295     @parent = options.parent\r
296     @licensed_pictures = {}\r
297   \r
298   clear: () ->\r
299     this.$el.html('')\r
300   \r
301   render: () ->\r
302     this.$el.html('')\r
303     this\r
304   \r
305   push: (retrievers) ->\r
306     _.each retrievers, (retriever, pid) =>\r
307       Pettanr.Picture.retrieve(pid, this, {\r
308         success: (picture) =>\r
309           pid = picture.get('id')\r
310           return if @licensed_pictures[pid]\r
311           @licensed_pictures[pid] = picture\r
312           credit = picture.credit_view()\r
313           @listenTo(credit, 'click:icon', @click_credit_icon)\r
314           this.$el.append(credit.render().el)\r
315       })\r
316   \r
317   click_credit_icon: (item) ->\r
318     @trigger('click:credit:icon', item)\r
319   \r