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.LoadIcon extends Tag.Img
\r
13 @width = Manifest.manifest().magic_numbers['thumbnail_width']
\r
14 @height = Manifest.manifest().magic_numbers['thumbnail_height']
\r
15 @width = Pettanr.to_i(@width/2)
\r
16 @height = Pettanr.to_i(@height/2)
\r
17 @attr['src'] = '/images/loading.gif'
\r
18 @attr['width'] = @width
\r
19 @attr['height'] = @height
\r
20 @attr['alt'] = 'Loading'
\r
21 @attr['title'] = 'Loading'
\r
27 class Pettanr.Views.Common.EmptyCaption extends Backbone.View
\r
32 this.$el.html('empty')
\r
35 class Pettanr.Views.Common.Icon extends Backbone.View
\r
38 initialize: (options) ->
\r
39 @item = options.item
\r
40 @half = options.half
\r
41 @icon_url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})
\r
42 @icon = new Pettanr.Image.Icon({item: @item, half: @half})
\r
43 @icon_button = new Tag.A({
\r
44 attr: {href: '/' + @icon_url},
\r
46 content: @icon.render().el
\r
48 @listenTo(@icon_button, 'click', @click)
\r
51 this.$el.html(@icon_button.render().el)
\r
60 class Pettanr.Views.Common.Caption extends Backbone.View
\r
63 initialize: (options) ->
\r
64 @item = options.item
\r
65 @column_name = options.column_name
\r
66 @length = options.length
\r
67 @name = Pettanr.truncate(@item.get(@column_name), @length)
\r
68 @url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})
\r
69 @linked_name = new Tag.A({
\r
70 attr: {href: '/' + @url},
\r
71 content: _.escape(@name)
\r
73 @listenTo(@linked_name, 'click', @click)
\r
76 this.$el.html(@linked_name.render().el)
\r
85 class Pettanr.Views.Common.IconWithCaption extends Backbone.View
\r
88 initialize: (options) ->
\r
89 @item = options.item
\r
90 @half = options.half
\r
91 @column_name = options.column_name
\r
92 @length = options.length
\r
93 @icon = new Pettanr.Views.Common.Icon({item: @item, half: @half})
\r
94 @caption = new Pettanr.Views.Common.Caption({item: @item, column_name: @column_name, length: @length})
\r
95 @listenTo(@icon, 'click', @click)
\r
96 @listenTo(@caption, 'click', @click)
\r
100 this.$el.append(@icon.render().el)
\r
101 this.$el.append(@caption.render().el)
\r
110 class Pettanr.Views.Common.Summary extends Backbone.View
\r
112 initialize: (options) ->
\r
114 @listenTo(this, 'ready', @render)
\r
117 icon = new Pettanr.Views.Common.LoadIcon()
\r
118 this.$el.html(icon.render().el)
\r
125 class Pettanr.Views.Common.Binder
\r
126 class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary
\r
128 initialize: (options) ->
\r
130 @item = options.item
\r
131 @visible_t = options.visible_t
\r
132 @visible_column_name = options.visible_column_name
\r
136 @visible = new Tag.Div({
\r
137 content: Pettanr.AppHelper.t_selected_item(@visible_t, @item.get(@visible_column_name))
\r
139 @author = @item.author()
\r
140 @author.fetch({cache: true}).done =>
\r
141 @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12)
\r
142 @listenTo(@author_icon_with_caption, 'click', @author_click)
\r
147 this.$el.append(@visible.render().el)
\r
148 this.$el.append(@author_icon_with_caption.render().el)
\r
151 author_click: () ->
\r
152 @trigger('navigate', @author_icon_with_caption.url())
\r
154 class Pettanr.Views.Common.Leaf
\r
155 class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary
\r
157 initialize: (options) ->
\r
159 @item = options.item
\r
160 @binder_item_name = options.binder_item_name
\r
161 @destination_item_name = options.destination_item_name
\r
162 @binder_view = new Tag.Span({})
\r
163 @destination_view = new Tag.Span({})
\r
167 @listenTo(this, 'load_binder', @load_destination)
\r
168 @listenTo(this, 'load_destination', @ready)
\r
175 @binder = @item[@binder_item_name]()
\r
176 @binder.fetch({cache: true}).done =>
\r
177 @binder_icon = @binder.icon_view(true)
\r
178 @listenTo(@binder_icon, 'click', @binder_click)
\r
179 @binder_author = @binder.author()
\r
180 @binder_author.fetch({cache: true}).done =>
\r
181 @binder_author_icon_with_caption = @binder_author.icon_with_caption_view(true, 'name', 12)
\r
182 @listenTo(@binder_author_icon_with_caption, 'click', @binder_author_click)
\r
183 @binder_view.$el.append(@binder_icon.render().el)
\r
184 @binder_view.$el.append(@binder_author_icon_with_caption.render().el)
\r
185 @trigger('load_binder')
\r
187 load_destination: () ->
\r
188 @destination = @item[@destination_item_name]()
\r
189 @destination.fetch({cache: true}).done =>
\r
190 @destination_icon = @destination.icon_view(true)
\r
191 @listenTo(@destination_icon, 'click', @destination_click)
\r
192 @destination_author = @destination.author()
\r
193 @destination_author.fetch({cache: true}).done =>
\r
194 @destination_author_icon_with_caption = @destination_author.icon_with_caption_view(true, 'name', 12)
\r
195 @listenTo(@destination_author_icon_with_caption, 'click', @destination_author_click)
\r
196 @destination_view.$el.append(@destination_icon.render().el)
\r
197 @destination_view.$el.append(@destination_author_icon_with_caption.render().el)
\r
198 @trigger('load_destination')
\r
202 this.$el.append(@binder_view.render().el)
\r
203 this.$el.append(@destination_view.render().el)
\r
206 binder_click: () ->
\r
207 @trigger('navigate', @binder_icon.url())
\r
209 destination_click: () ->
\r
210 @trigger('navigate', @destination_icon.url())
\r
212 binder_author_click: () ->
\r
213 @trigger('navigate', @binder_author_icon_with_caption.url())
\r
215 destination_author_click: () ->
\r
216 @trigger('navigate', @destination_author_icon_with_caption.url())
\r