OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[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.BackIcon extends Pettanr.Views.Common.EmptyIcon\r
56   \r
57   file_name: () ->\r
58     '/images/back.png'\r
59   \r
60 class Pettanr.Views.Common.ForwardIcon extends Pettanr.Views.Common.EmptyIcon\r
61   \r
62   file_name: () ->\r
63     '/images/forward.png'\r
64   \r
65 class Pettanr.Views.Common.RootIcon extends Pettanr.Views.Common.EmptyIcon\r
66   \r
67   file_name: () ->\r
68     '/images/root.png'\r
69   \r
70 class Pettanr.Views.Common.EmptyCaption extends Backbone.View\r
71   tagName: 'div'\r
72   className: 'empty'\r
73   \r
74   render: () ->\r
75     this.$el.html('empty')\r
76     this\r
77   \r
78 class Pettanr.Views.Common.Icon extends Backbone.View\r
79   tagName: 'span'\r
80   \r
81   initialize: (options) ->\r
82     @item = options.item\r
83     @half = options.half\r
84     @icon_url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
85     @icon = new Pettanr.Image.Icon({item: @item, half: @half})\r
86     @icon_button = new Tag.A({\r
87       attr: {href: '/' + @icon_url}, \r
88       class_name: 'icon',\r
89       content: @icon.render().el\r
90     })\r
91     @listenTo(@icon_button, 'click', @click)\r
92   \r
93   render: () ->\r
94     this.$el.html(@icon_button.render().el)\r
95     this\r
96   \r
97   click: () ->\r
98     @trigger('click')\r
99   \r
100   url: () ->\r
101     @icon_url\r
102   \r
103 class Pettanr.Views.Common.Caption extends Backbone.View\r
104   tagName: 'span'\r
105   \r
106   initialize: (options) ->\r
107     @item = options.item\r
108     @column_name = options.column_name\r
109     @length = options.length\r
110     @name = Pettanr.truncate(@item.get(@column_name), @length)\r
111     @url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
112     @linked_name = new Tag.A({\r
113       attr: {href: '/' + @url}, \r
114       content: _.escape(@name)\r
115     })\r
116     @listenTo(@linked_name, 'click', @click)\r
117   \r
118   render: () ->\r
119     this.$el.html(@linked_name.render().el)\r
120     this\r
121   \r
122   click: () ->\r
123     @trigger('click')\r
124   \r
125   url: () ->\r
126     @url\r
127   \r
128 class Pettanr.Views.Common.IconWithCaption extends Backbone.View\r
129   tagName: 'span'\r
130   \r
131   initialize: (options) ->\r
132     @item = options.item\r
133     @half = options.half\r
134     @column_name = options.column_name\r
135     @length = options.length\r
136     @icon = new Pettanr.Views.Common.Icon({item: @item, half: @half})\r
137     @caption = new Pettanr.Views.Common.Caption({item: @item, column_name: @column_name, length: @length})\r
138     @listenTo(@icon, 'click', @click)\r
139     @listenTo(@caption, 'click', @click)\r
140   \r
141   render: () ->\r
142     this.$el.html('')\r
143     this.$el.append(@icon.render().el)\r
144     this.$el.append(@caption.render().el)\r
145     this\r
146   \r
147   click: () ->\r
148     @trigger('click')\r
149   \r
150   url: () ->\r
151     @icon.url()\r
152   \r
153 class Pettanr.Views.Common.Summary extends Backbone.View\r
154   \r
155   initialize: (options) ->\r
156     @clear()\r
157     @listenTo(this, 'ready', @render)\r
158   \r
159   clear: () ->\r
160     icon = new Pettanr.Views.Common.LoadIcon()\r
161     this.$el.html(icon.render().el)\r
162     this\r
163   \r
164   render: () ->\r
165     this.$el.html('')\r
166     this\r
167   \r
168 class Pettanr.Views.Common.Binder\r
169 class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary\r
170   \r
171   initialize: (options) ->\r
172     super(options)\r
173     @item = options.item\r
174     @visible_t = options.visible_t\r
175     @visible_column_name = options.visible_column_name\r
176     @load()\r
177   \r
178   load: () ->\r
179     @visible = new Tag.Div({\r
180       content: Pettanr.AppHelper.t_selected_item(@visible_t, @item.get(@visible_column_name))\r
181     })\r
182     @author = @item.author()\r
183     @author.fetch({cache: true}).done =>\r
184       @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12)\r
185       @listenTo(@author_icon_with_caption, 'click', @author_click)\r
186       @trigger('ready')\r
187   \r
188   render: () ->\r
189     this.$el.html('')\r
190     this.$el.append(@visible.render().el)\r
191     this.$el.append(@author_icon_with_caption.render().el)\r
192     this\r
193   \r
194   author_click: () ->\r
195     @trigger('http_get', @author_icon_with_caption.url())\r
196   \r
197 class Pettanr.Views.Common.Leaf\r
198 class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary\r
199   \r
200   initialize: (options) ->\r
201     super(options)\r
202     @item = options.item\r
203     @binder_item_name = options.binder_item_name\r
204     @destination_item_name = options.destination_item_name\r
205     @binder_view = new Tag.Span({})\r
206     @destination_view = new Tag.Span({})\r
207     @load()\r
208   \r
209   load: () ->\r
210     @listenTo(this, 'load_binder', @load_destination)\r
211     @listenTo(this, 'load_destination', @ready)\r
212     @load_binder()\r
213   \r
214   ready: () ->\r
215     @trigger('ready')\r
216   \r
217   load_binder: () ->\r
218     @binder = @item[@binder_item_name]()\r
219     @binder.fetch({cache: true}).done =>\r
220       @binder_icon = @binder.icon_view(true)\r
221       @listenTo(@binder_icon, 'click', @binder_click)\r
222       @binder_author = @binder.author()\r
223       @binder_author.fetch({cache: true}).done =>\r
224         @binder_author_icon_with_caption = @binder_author.icon_with_caption_view(true, 'name', 12)\r
225         @listenTo(@binder_author_icon_with_caption, 'click', @binder_author_click)\r
226         @binder_view.$el.append(@binder_icon.render().el)\r
227         @binder_view.$el.append(@binder_author_icon_with_caption.render().el)\r
228         @trigger('load_binder')\r
229   \r
230   load_destination: () ->\r
231     @destination = @item[@destination_item_name]()\r
232     @destination.fetch({cache: true}).done =>\r
233       @destination_icon = @destination.icon_view(true)\r
234       @listenTo(@destination_icon, 'click', @destination_click)\r
235       @destination_author = @destination.author()\r
236       @destination_author.fetch({cache: true}).done =>\r
237         @destination_author_icon_with_caption = @destination_author.icon_with_caption_view(true, 'name', 12)\r
238         @listenTo(@destination_author_icon_with_caption, 'click', @destination_author_click)\r
239         @destination_view.$el.append(@destination_icon.render().el)\r
240         @destination_view.$el.append(@destination_author_icon_with_caption.render().el)\r
241         @trigger('load_destination')\r
242   \r
243   render: () ->\r
244     this.$el.html('')\r
245     this.$el.append(@binder_view.render().el)\r
246     this.$el.append(@destination_view.render().el)\r
247     this\r
248   \r
249   binder_click: () ->\r
250     @trigger('http_get', @binder_icon.url())\r
251   \r
252   destination_click: () ->\r
253     @trigger('http_get', @destination_icon.url())\r
254   \r
255   binder_author_click: () ->\r
256     @trigger('http_get', @binder_author_icon_with_caption.url())\r
257   \r
258   destination_author_click: () ->\r
259     @trigger('http_get', @destination_author_icon_with_caption.url())\r
260   \r