class Pettanr.Views.Common @replace_empty: (caption) -> if Pettanr.is_blank(caption) empty = new Pettanr.Views.Common.EmptyCaption() empty.render().el else caption class Pettanr.Views.Common.LoadIcon extends Tag.Img initialize: () -> @attr = {} @width = Manifest.manifest().magic_numbers['thumbnail_width'] @height = Manifest.manifest().magic_numbers['thumbnail_height'] @width = Pettanr.to_i(@width/2) @height = Pettanr.to_i(@height/2) @attr['src'] = '/images/loading.gif' @attr['width'] = @width @attr['height'] = @height @attr['alt'] = 'Loading' @attr['title'] = 'Loading' opt = { attr: @attr, } super(opt) class Pettanr.Views.Common.EmptyCaption extends Backbone.View tagName: 'div' className: 'empty' render: () -> this.$el.html('empty') this class Pettanr.Views.Common.Icon extends Backbone.View tagName: 'span' initialize: (options) -> @item = options.item @half = options.half @icon_url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')}) @icon = new Pettanr.Image.Icon({item: @item, half: @half}) @icon_button = new Tag.A({ attr: {href: '/' + @icon_url}, class_name: 'icon', content: @icon.render().el }) @listenTo(@icon_button, 'click', @click) render: () -> this.$el.html(@icon_button.render().el) this click: () -> @trigger('click') url: () -> @icon_url class Pettanr.Views.Common.Caption extends Backbone.View tagName: 'span' initialize: (options) -> @item = options.item @column_name = options.column_name @length = options.length @name = Pettanr.truncate(@item.get(@column_name), @length) @url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')}) @linked_name = new Tag.A({ attr: {href: '/' + @url}, content: _.escape(@name) }) @listenTo(@linked_name, 'click', @click) render: () -> this.$el.html(@linked_name.render().el) this click: () -> @trigger('click') url: () -> @url class Pettanr.Views.Common.IconWithCaption extends Backbone.View tagName: 'span' initialize: (options) -> @item = options.item @half = options.half @column_name = options.column_name @length = options.length @icon = new Pettanr.Views.Common.Icon({item: @item, half: @half}) @caption = new Pettanr.Views.Common.Caption({item: @item, column_name: @column_name, length: @length}) @listenTo(@icon, 'click', @click) @listenTo(@caption, 'click', @click) render: () -> this.$el.html('') this.$el.append(@icon.render().el) this.$el.append(@caption.render().el) this click: () -> @trigger('click') url: () -> @icon.url() class Pettanr.Views.Common.Summary extends Backbone.View initialize: (options) -> @clear() @listenTo(this, 'ready', @render) clear: () -> icon = new Pettanr.Views.Common.LoadIcon() this.$el.html(icon.render().el) this render: () -> this.$el.html('') this class Pettanr.Views.Common.Binder class Pettanr.Views.Common.Binder.Summary extends Pettanr.Views.Common.Summary initialize: (options) -> super(options) @item = options.item @visible_t = options.visible_t @visible_column_name = options.visible_column_name @load() load: () -> @visible = new Tag.Div({ content: Pettanr.AppHelper.t_selected_item(@visible_t, @item.get(@visible_column_name)) }) @author = @item.author() @author.fetch({cache: true}).done => @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12) @listenTo(@author_icon_with_caption, 'click', @author_click) @trigger('ready') render: () -> this.$el.html('') this.$el.append(@visible.render().el) this.$el.append(@author_icon_with_caption.render().el) this author_click: () -> @trigger('navigate', @author_icon_with_caption.url()) class Pettanr.Views.Common.Leaf class Pettanr.Views.Common.Leaf.Summary extends Pettanr.Views.Common.Summary initialize: (options) -> super(options) @item = options.item @binder_item_name = options.binder_item_name @destination_item_name = options.destination_item_name @binder_view = new Tag.Span({}) @destination_view = new Tag.Span({}) @load() load: () -> @listenTo(this, 'load_binder', @load_destination) @listenTo(this, 'load_destination', @ready) @load_binder() ready: () -> @trigger('ready') load_binder: () -> @binder = @item[@binder_item_name]() @binder.fetch({cache: true}).done => @binder_icon = @binder.icon_view(true) @listenTo(@binder_icon, 'click', @binder_click) @binder_author = @binder.author() @binder_author.fetch({cache: true}).done => @binder_author_icon_with_caption = @binder_author.icon_with_caption_view(true, 'name', 12) @listenTo(@binder_author_icon_with_caption, 'click', @binder_author_click) @binder_view.$el.append(@binder_icon.render().el) @binder_view.$el.append(@binder_author_icon_with_caption.render().el) @trigger('load_binder') load_destination: () -> @destination = @item[@destination_item_name]() @destination.fetch({cache: true}).done => @destination_icon = @destination.icon_view(true) @listenTo(@destination_icon, 'click', @destination_click) @destination_author = @destination.author() @destination_author.fetch({cache: true}).done => @destination_author_icon_with_caption = @destination_author.icon_with_caption_view(true, 'name', 12) @listenTo(@destination_author_icon_with_caption, 'click', @destination_author_click) @destination_view.$el.append(@destination_icon.render().el) @destination_view.$el.append(@destination_author_icon_with_caption.render().el) @trigger('load_destination') render: () -> this.$el.html('') this.$el.append(@binder_view.render().el) this.$el.append(@destination_view.render().el) this binder_click: () -> @trigger('navigate', @binder_icon.url()) destination_click: () -> @trigger('navigate', @destination_icon.url()) binder_author_click: () -> @trigger('navigate', @binder_author_icon_with_caption.url()) destination_author_click: () -> @trigger('navigate', @destination_author_icon_with_caption.url())