# panel: panel item # operators: operators # spot: no opacity element class Pettanr.Views.Panel.Body extends Backbone.View tagName: 'div' initialize: (options) -> @panel = options.panel @operators = options.operators @spot = options.spot @class_name = 'pettanr-comic-panel' @collect_views() render: () -> this.$el.addClass(@class_name) @restyle() #this.$el.html('') if not @is_visible() tag = new Tag.Div({ content: I18n.t('panels.hidden'), class_name: 'hidden' }) this.$el.html(tag.render().el) this collect_views: () -> @views = [] if @is_visible() _.each @panel.scenario_elements(), (element) => @add_element(element) restyle: () -> attr = {style: Pettanr.to_style(@style())} this.$el.attr(attr) is_visible: () -> @panel.is_visible(@operators) render_element: (index) -> add_element: (element) -> index = element.get('z') - 1 c = @element_class(element) view = new c({element: element, root: @panel, spot: @spot}) @views[index] = view if @is_visible() this.$el.append(view.render().el) view element_class: (element) -> Pettanr.Views[element.singular()].Element disp: (value) -> Pettanr.to_s(value) + 'px' style: () -> { 'width': @disp(@panel.get('width')), 'height': @disp(@panel.get('height')), 'border-style': 'solid', 'border-width': @disp(@panel.get('border')), 'border-color': 'black', 'background-color': 'white' } class Pettanr.Views.Panel.Body.Edit extends Pettanr.Views.Panel.Body initialize: (options) -> super(options) @listenTo(@panel, 'input:width', @restyle) @listenTo(@panel, 'input:height', @restyle) @listenTo(@panel, 'input:border', @restyle) @listenTo(@panel, 'active', @active) @listenTo(@panel, 'inactive', @inactive) render: () -> super() this.$el.resizable { stop: (event, ui) => w = parseInt(this.$el.width()) h = parseInt(this.$el.height()) @panel.set({width: w, height: h}, {silent: true}) @panel.trigger('resize') , autoHide: true } this is_visible: () -> true # show everytime as editor collect_views: () -> @views = [] # elements collect by dock active: () -> n = @class_name $('.ui-resizable-handle', this.el).map -> if $(@).parent().hasClass(n) $(@).css('display', 'block') inactive: () -> n = @class_name $('.ui-resizable-handle', this.el).map -> if $(@).parent().hasClass(n) $(@).css('display', 'none') element_class: (element) -> Pettanr.Views[element.singular()].Element.Edit class Pettanr.Views.Panel.Footer extends Backbone.View tagName: 'table' className: 'no-border' initialize: (options) -> @panel = options.panel @operators = options.operators @panel_icon = new Pettanr.Views.Panel.Icon({item: @panel, half: true}) @author_icon = new Pettanr.Views.Author.Icon({item: @panel.author(), half: true}) @edit_button = new Pettanr.Views.Show.LinkedEditButton({item: @panel}) @listenTo(@panel_icon, 'click', @click_panel) @listenTo(@author_icon, 'click', @click_author) @listenTo(@edit_button, 'click', @click_edit) render: () -> this.$el.html('') this.$el.append(@panel_icon.render().el) this.$el.append(@author_icon.render().el) this.$el.append( Pettanr.AppHelper.distance_of_time_in_words_to_now(@panel.get('updated_at')) ) if @panel.is_own(@operators) this.$el.append(@edit_button.render().el) this click_panel: () -> @trigger('click:panel') click_author: () -> @trigger('click:author') click_edit: () -> @trigger('click:edit')