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.Logo extends Tag.Span id: 'logo' initialize: () -> title = Manifest.manifest().magic_numbers['profile']['users']['caption'] @logo_button = new Tag.A({ attr: {href: '/'}, class_name: 'logo', content: _.escape(title) }) @listenTo(@logo_button, 'click', @click) render: () -> this.$el.html(@logo_button.render().el) this click: () -> @trigger('click') class Pettanr.Views.Common.EmptyIcon extends Tag.Img initialize: (options) -> @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'] = @file_name() @attr['width'] = @width @attr['height'] = @height @attr['alt'] = 'Loading' @attr['title'] = 'Loading' opt = { attr: @attr, } super(opt) file_name: () -> '/images/empty.gif' class Pettanr.Views.Common.LoadIcon extends Pettanr.Views.Common.EmptyIcon file_name: () -> '/images/loading.gif' class Pettanr.Views.Common.RootIcon extends Pettanr.Views.Common.EmptyIcon file_name: () -> '/images/root.png' class Pettanr.Views.Common.PickIcon extends Backbone.View initialize: (options) -> @class_name = options.class_name @name = options.name @half = options.half @button = if @is_button() @linked_icon() else @icon() render: () -> this.$el.html('') @el.className = @class_name if @class_name if @is_button() @listenTo(@button, 'click', @click) this.$el.append(@button.render().el) this is_button: () -> @name != 'none' icon: () -> new Pettanr.Image.SymbolImg({attr: {src: '/images/' + @name + '.gif'}, half: @half}) linked_icon: () -> new Tag.A({ attr: {href: '#'}, content: @icon().render().el }) click: () -> @trigger('click', this) 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)) }) retriever = @item.author() @listenTo(retriever, 'retrieve', @retrieve_author) retriever.retrieve() render: () -> this.$el.html('') this.$el.append(@visible.render().el) this.$el.append(@author_icon_with_caption.render().el) this retrieve_author: (@author) -> @author_icon_with_caption = @author.icon_with_caption_view(true, 'name', 12) @listenTo(@author_icon_with_caption, 'click', @author_click) @trigger('ready') author_click: () -> @trigger('http_get', @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: () -> retriever = @item[@binder_item_name]() @listenTo(retriever, 'retrieve', @retrieve_binder) retriever.retrieve() retrieve_binder: (@binder) -> @binder_icon = @binder.icon_view(true) @listenTo(@binder_icon, 'click', @binder_click) retriever = @binder.author() @listenTo(retriever, 'retrieve', @retrieve_binder_author) retriever.retrieve() retrieve_binder_author: (@binder_author) -> @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: () -> retriever = @item[@destination_item_name]() @listenTo(retriever, 'retrieve', @retrieve_destination) retriever.retrieve() retrieve_destination: (@destination) -> @destination_icon = @destination.icon_view(true) @listenTo(@destination_icon, 'click', @destination_click) retriever = @destination.author() @listenTo(retriever, 'retrieve', @retrieve_destination_author) retriever.retrieve() retrieve_destination_author: (@destination_author) -> @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('http_get', @binder_icon.url()) destination_click: () -> @trigger('http_get', @destination_icon.url()) binder_author_click: () -> @trigger('http_get', @binder_author_icon_with_caption.url()) destination_author_click: () -> @trigger('http_get', @destination_author_icon_with_caption.url())