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
9 class Pettanr.Views.Common.Logo extends Tag.Span
\r
13 title = Manifest.manifest().magic_numbers['profile']['users']['caption']
\r
14 @logo_button = new Tag.A({
\r
17 content: _.escape(title)
\r
19 @listenTo(@logo_button, 'click', @click)
\r
22 this.$el.html(@logo_button.render().el)
\r
29 class Pettanr.Views.Common.EmptyIcon extends Tag.Img
\r
31 initialize: (options) ->
\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
50 class Pettanr.Views.Common.LoadIcon extends Pettanr.Views.Common.EmptyIcon
\r
53 '/images/loading.gif'
\r
55 class Pettanr.Views.Common.RootIcon extends Pettanr.Views.Common.EmptyIcon
\r
60 class Pettanr.Views.Common.PickIcon extends Backbone.View
\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
73 @el.className = @class_name if @class_name
\r
75 @listenTo(@button, 'click', @click)
\r
76 this.$el.append(@button.render().el)
\r
83 new Pettanr.Image.SymbolImg({attr: {src: '/images/' + @name + '.gif'}, half: @half})
\r
88 content: @icon().render().el
\r
92 @trigger('click', this)
\r
94 class Pettanr.Views.Common.EmptyCaption extends Backbone.View
\r
99 this.$el.html('empty')
\r
102 class Pettanr.Views.Common.Icon extends Backbone.View
\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
115 @listenTo(@icon_button, 'click', @click)
\r
118 this.$el.html(@icon_button.render().el)
\r
127 class Pettanr.Views.Common.Caption extends Backbone.View
\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
140 @listenTo(@linked_name, 'click', @click)
\r
143 this.$el.html(@linked_name.render().el)
\r
152 class Pettanr.Views.Common.IconWithCaption extends Backbone.View
\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
167 this.$el.append(@icon.render().el)
\r
168 this.$el.append(@caption.render().el)
\r
177 class Pettanr.Views.Common.Summary extends Backbone.View
\r
179 initialize: (options) ->
\r
181 @listenTo(this, 'ready', @render)
\r
184 icon = new Pettanr.Views.Common.LoadIcon()
\r
185 this.$el.html(icon.render().el)
\r
192 class Pettanr.Views.Common.Binder
\r
193 class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary
\r
195 initialize: (options) ->
\r
197 @item = options.item
\r
198 @visible_t = options.visible_t
\r
199 @visible_column_name = options.visible_column_name
\r
203 @visible = new Tag.Div({
\r
204 content: Pettanr.AppHelper.t_selected_item(@visible_t, @item.get(@visible_column_name))
\r
206 @empty_author = @item.author()
\r
207 @author = Pettanr.cache.restore(@empty_author)
\r
209 # got cached author
\r
212 # built empty author
\r
213 @author = @empty_author
\r
214 @author.fetch({cache: true}).done =>
\r
215 Pettanr.cache.store(@author)
\r
220 this.$el.append(@visible.render().el)
\r
221 this.$el.append(@author_icon_with_caption.render().el)
\r
224 render_author: () ->
\r
225 @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12)
\r
226 @listenTo(@author_icon_with_caption, 'click', @author_click)
\r
229 author_click: () ->
\r
230 @trigger('http_get', @author_icon_with_caption.url())
\r
232 class Pettanr.Views.Common.Leaf
\r
233 class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary
\r
235 initialize: (options) ->
\r
237 @item = options.item
\r
238 @binder_item_name = options.binder_item_name
\r
239 @destination_item_name = options.destination_item_name
\r
240 @binder_view = new Tag.Span({})
\r
241 @destination_view = new Tag.Span({})
\r
245 @listenTo(this, 'load_binder', @load_destination)
\r
246 @listenTo(this, 'load_destination', @ready)
\r
253 @binder = @item[@binder_item_name]()
\r
254 @binder.fetch({cache: true}).done =>
\r
255 @binder_icon = @binder.icon_view(true)
\r
256 @listenTo(@binder_icon, 'click', @binder_click)
\r
257 @binder_author = @binder.author()
\r
258 @binder_author.fetch({cache: true}).done =>
\r
259 @binder_author_icon_with_caption = @binder_author.icon_with_caption_view(true, 'name', 12)
\r
260 @listenTo(@binder_author_icon_with_caption, 'click', @binder_author_click)
\r
261 @binder_view.$el.append(@binder_icon.render().el)
\r
262 @binder_view.$el.append(@binder_author_icon_with_caption.render().el)
\r
263 @trigger('load_binder')
\r
265 load_destination: () ->
\r
266 @destination = @item[@destination_item_name]()
\r
267 @destination.fetch({cache: true}).done =>
\r
268 @destination_icon = @destination.icon_view(true)
\r
269 @listenTo(@destination_icon, 'click', @destination_click)
\r
270 @destination_author = @destination.author()
\r
271 @destination_author.fetch({cache: true}).done =>
\r
272 @destination_author_icon_with_caption = @destination_author.icon_with_caption_view(true, 'name', 12)
\r
273 @listenTo(@destination_author_icon_with_caption, 'click', @destination_author_click)
\r
274 @destination_view.$el.append(@destination_icon.render().el)
\r
275 @destination_view.$el.append(@destination_author_icon_with_caption.render().el)
\r
276 @trigger('load_destination')
\r
280 this.$el.append(@binder_view.render().el)
\r
281 this.$el.append(@destination_view.render().el)
\r
284 binder_click: () ->
\r
285 @trigger('http_get', @binder_icon.url())
\r
287 destination_click: () ->
\r
288 @trigger('http_get', @destination_icon.url())
\r
290 binder_author_click: () ->
\r
291 @trigger('http_get', @binder_author_icon_with_caption.url())
\r
293 destination_author_click: () ->
\r
294 @trigger('http_get', @destination_author_icon_with_caption.url())
\r