class Editor.PanelEditor.Dock extends Editor.EditorModule.DockBase tagName: 'div' className: 'dock' initialize: (options) -> super(options) @root_bay = new Editor.EditorModule.DockModule.RootBay({ parent: this, index: 0, name: 'panel' }) @add_tab( @root_bay, new Editor.EditorModule.DockModule.TabModule.RootBayLabel({ parent: @root_bay, caption: 'panel' }), new Editor.EditorModule.DockModule.TabModule.RootBayBody({ parent: @root_bay }) ) @element_bay = new Editor.EditorModule.DockModule.ElementBay({ parent: this, index: 1, name: 'elements' }) @add_tab( @element_bay, new Editor.EditorModule.DockModule.TabModule.ElementBayLabel({ parent: @element_bay, caption: 'elements' }), new Editor.EditorModule.DockModule.TabModule.ElementBayBody({ parent: @element_bay }) ) @scenario_bay = new Editor.EditorModule.DockModule.ScenarioBay({ parent: this, index: 2, name: 'scenario' }) @add_tab( @scenario_bay, new Editor.EditorModule.DockModule.TabModule.ScenarioBayLabel({ parent: @scenario_bay, caption: 'scenario' }), new Editor.EditorModule.DockModule.TabModule.ScenarioBayBody({ parent: @scenario_bay }) ) @listenTo(@root_bay.body, 'http_post', @http_post) @listenTo(@element_bay, 'add:credit', @add_credit) render: () -> this.$el.html('') l = _.map @tabs, (tab) -> tab.label labels = new Tag.Ul({contents: l, class_name: @dom_labels_class()}) this.$el.append(labels.render().el) _.each @tabs, (tab) => this.$el.append(tab.render().el) this init_tabs: () -> @element_bay.init_tabs() @scenario_bay.init_tabs() this.$el.tabs({ activate: (e, ui) -> ui.newPanel.trigger('activate') }) editor: () -> @parent dom_id: () -> @editor().dom_id() + '-dock' dom_class: () -> @editor().dom_class() + '-dock' dom_labels_class: () -> @dom_class() + '-labels' http_post: (url, root_form) -> @trigger('http_post', url, this) # send dock false add_credit: (element) -> @trigger('add:credit', element) save_data: () -> attrs = @root_bay.save_data() _.extend(attrs, @element_bay.save_data()) attrs class Editor.EditorModule.DockModule.RootBay extends Editor.EditorModule.DockModule.SimpleBay render: () -> @body.render() save_data: () -> @body.form.save_data() class Editor.EditorModule.DockModule.TabModule.RootBayLabel extends Editor.EditorModule.DockModule.TabModule.BayLabel class Editor.EditorModule.DockModule.TabModule.RootBayBody extends Editor.EditorModule.DockModule.TabModule.BayBody initialize: (options) -> super(options) @form = Locmare.Form.factory({ form_name: @root_item().item_name(), use_name: 'default' item: @root_item(), mounted: @mounted(), submit: 'default' operators: @dock().editor().operators, action: '/' + @root_item().table_name() + '/' + Pettanr.to_s(@root_item().get('id')) }) @listenTo(@form, 'http_post', @http_post) render: () -> super() @el.className = @bay().body.dom_class() this.$el.html(@form.render().el) this mounted: () -> true dock: () -> @parent.dock() root_item: () -> @dock().root_item() http_post: (url, root_form) -> @trigger('http_post', url, root_form) false class Editor.EditorModule.DockModule.ElementBay extends Editor.EditorModule.DockModule.BoardBay initialize: (options) -> super(options) @elements_tabs = new Editor.EditorModule.DockModule.ElementBay.ElementsTabs({ }) @listenTo(@elements_tabs, 'sorted', @sorted) add_element: (element) -> index = element.get('z') - 1 tab = new Editor.EditorModule.DockModule.ElementBoard({ parent: this, index: index, name: element.item_name(), element: element }) bb = new Editor.EditorModule.DockModule.TabModule.ElementBoardBody({parent: tab}) @add_tab( tab, new Editor.EditorModule.DockModule.TabModule.ElementBoardLabel({parent: tab, name: element.item_name()}), bb ) @elements_tabs.add_element_tab(tab) @elements_tabs.$el.tabs('refresh') if element.constructor.has_picture() @trigger('add:credit', element) add_new_tab: () -> tab = new Editor.EditorModule.DockModule.NewElementBoard({ parent: this, index: 0, name: 'new' }) bb = new Editor.EditorModule.DockModule.TabModule.NewElementBoardBody({parent: tab}) @add_tab( tab, new Editor.EditorModule.DockModule.TabModule.NewElementBoardLabel({parent: tab}), bb ) @elements_tabs.add_element_tab(tab) render: () -> this.$el.html('') @delegateEvents({'activate': 'activate'}) this.$el.attr('id', @body.dom_id()) this.$el.append(@elements_tabs.render().el) _this = this @elements_tabs.$el.tabs({ activate: (e, ui) -> ui.newPanel.trigger('activate') }) this init_tabs: () -> @add_new_tab() list = @root_item().zorderd_elements() _.each list, (element) => @add_element(element) activate: () -> _.each @tabs, (tab) -> return if not tab.element # without new element tab if tab.body.$el.css('display') != 'none' tab.body.refresh() sorted: () -> # data-z copy to model _.each @tabs, (tab) -> if tab.element # without new_tab z = parseInt(tab.label.$el.attr('data-z')) tab.element.set({ z: z }, {silent: true}) tab.element.trigger('sort') panel_body: () -> @dock().editor().body save_data: () -> attrs = {} _.each @tabs, (tab) -> return if not tab.element # without new element tab form = tab.body.form name = form.item.table_name() + '_attributes' attrs[name] ||= [] attrs[name].push(form.save_data()) attrs class Editor.EditorModule.DockModule.ElementBay.ElementsTabs extends Backbone.View tagName: 'div' className: 'elements_tabs ui-tabs-vertical ui-helper-clearfix' initialize: (options) -> super(options) @inner_elements_tabs = new Editor.EditorModule.DockModule.ElementBay.InnerElementsTabs({ }) @listenTo(@inner_elements_tabs, 'sorted', @sorted) render: () -> this.$el.html('') this.$el.append(@inner_elements_tabs.render().$el) this add_element_tab: (tab) -> @inner_elements_tabs.add_label(tab.label) this.$el.append(tab.body.render().$el) sorted: () -> # data-z copy to model @trigger('sorted') class Editor.EditorModule.DockModule.ElementBay.InnerElementsTabs extends Backbone.View tagName: 'ul' initialize: (options) -> super(options) @labels = [] render: () -> this.$el.html('') this.$el.addClass('inner-elements-tabs') _.each @zorderd_labels(), (label) => this.$el.append(label.render().$el) _this = this this.$el.sortable { update: (event, ui) -> z = 1 $('.z-label', $(@)).map -> $(@).attr('data-z', z) z++ _this.trigger('sorted') } this zorderd_labels: () -> res = [] _.each @labels, (label) => res[label.z()] = label res add_label: (label) -> #z = label.z() @labels.push(label) # insert array @render() label.add_label() class Editor.EditorModule.DockModule.TabModule.ElementBayLabel extends Editor.EditorModule.DockModule.TabModule.BayLabel class Editor.EditorModule.DockModule.TabModule.ElementBayBody extends Editor.EditorModule.DockModule.TabModule.BayBody render: () -> @body.render() class Editor.EditorModule.DockModule.ElementBoard extends Editor.EditorModule.DockModule.Board initialize: (options) -> super(options) @element = options.element dom_id: () -> super() + '-' + @element.get('id') # use tab index class Editor.EditorModule.DockModule.TabModule.ElementBoardLabel extends Editor.EditorModule.DockModule.TabModule.BoardLabel render: () -> super() this.$el.attr('data-z', @z()) this.$el.removeClass('ui-corner-top') this.$el.addClass('ui-corner-left z-label') _this = this this.$el.mouseover -> _this.element().trigger('active') this.$el.mouseout -> _this.element().trigger('inactive') this z: () -> @element().get('z') add_label: () -> this.$el.attr('id', @dom_id()) class Editor.EditorModule.DockModule.TabModule.ElementBoardBody extends Editor.EditorModule.DockModule.TabModule.BoardBody initialize: (options) -> super(options) @form = Locmare.Form.factory({ form_name: @element().item_name(), use_name: 'default' item: @element(), element_form: true, submit: null, operators: @dock().editor().operators, }) render: () -> @delegateEvents({'activate': 'activate'}) this.$el.attr('id', @dom_id()) this.$el.html(@form.render().el) this add_element: (element) -> @form.add_element(element) activate: () -> @refresh() refresh: () -> @form.refresh() element: () -> @parent.element class Editor.EditorModule.DockModule.NewElementBoard extends Editor.EditorModule.DockModule.Board initialize: (options) -> super(options) @panel = @parent.dock().editor().panel class Editor.EditorModule.DockModule.TabModule.NewElementBoardLabel extends Editor.EditorModule.DockModule.TabModule.BoardLabel render: () -> super() this.$el.attr('data-z', @z()) this.$el.removeClass('ui-corner-top') this.$el.addClass('ui-corner-left') this face: () -> icon = new Pettanr.Image.SymbolImg({attr: {src: '/images/new.gif'}}) linked_elements_tab = new Tag.A({ attr: {href: '#' + @board().body.dom_id() }, content: icon.render().el }) this.$el.append(linked_elements_tab.render().el) z: () -> 0 add_label: () -> this.$el.attr('id', @dom_id()) class Editor.EditorModule.DockModule.TabModule.NewElementBoardBody extends Editor.EditorModule.DockModule.TabModule.BoardBody className: 'new-element-board-body' initialize: (options) -> super(options) render: () -> this.$el.attr('id', @dom_id()) @buttons = new Editor.EditorModule.DockModule.NewElementButtons({ parent: this, element_models: @element_models() }) @listenTo(@buttons, 'click', @click_button) this.$el.append(@buttons.render().el) this panel: () -> @parent.panel element_models: () -> @panel().my_class().child_models() click_button: (model) -> @new_element.remove() if @new_element @new_element = new Pettanr.Views[model.singular()].NewElement({ parent: this, target_model: model }) this.$el.append(@new_element.render().el) class Editor.EditorModule.DockModule.NewElementButtons extends Backbone.View tagName: 'div' className: 'new-element-buttons' initialize: (options) -> super(options) @parent = options.parent @element_models = options.element_models render: () -> _.each @element_models, (model) => button = new Editor.EditorModule.DockModule.NewElementButton({ parent: this, model: model }) @listenTo(button, 'click', @click) this.$el.append(button.render().el) this click: (model) -> @trigger('click', model) class Editor.EditorModule.DockModule.NewElementButton extends Backbone.View tagName: 'div' initialize: (options) -> super(options) @parent = options.parent @model = options.model render: () -> this.$el.html('') icon = new Pettanr.Image.Icon({item: @model}) linked_icon = new Editor.EditorModule.DockModule.NewElementLinkedButton({ attr: {href: '#' }, content: icon.render().el }) @listenTo(linked_icon, 'click', @click) this.$el.append(linked_icon.render().el) this click: () -> @trigger('click', @model) class Editor.EditorModule.DockModule.NewElementLinkedButton extends Tag.A click: () -> @trigger('click') return false class Editor.EditorModule.DockModule.ScenarioBay extends Editor.EditorModule.DockModule.SimpleBay initialize: (options) -> super(options) render: () -> @body.render() add_element: (element) -> @body.add_element(element) init_tabs: () -> list = @root_item().scenario_elements() _.each list, (element) => @add_element(element) save_data: () -> @body.form.save_data() class Editor.EditorModule.DockModule.TabModule.ScenarioBayLabel extends Editor.EditorModule.DockModule.TabModule.BayLabel class Editor.EditorModule.DockModule.TabModule.ScenarioBayBody extends Editor.EditorModule.DockModule.TabModule.BayBody initialize: (options) -> super(options) @elements = new Editor.EditorModule.DockModule.ScenarioBay.Elements({ parent: this, }) @listenTo(@elements, 'sorted', @sorted) add_element: (element) -> @elements.add_element(element) render: () -> super() this.$el.append(@elements.render().el) @delegateEvents({'activate': 'activate'}) this activate: () -> @elements.refresh() sorted: () -> # data-t copy to model _.each @elements.element_lis, (element_li) => t = parseInt(element_li.$el.attr('data-t')) element_li.element.set({ t: t }, {silent: true}) element_li.element.trigger('sort') panel_body: () -> @dock().editor().body save_data: () -> attrs = {} _.each @tabs, (tab) -> return if not tab.element # without new element tab form = tab.body.form name = form.item.table_name() + '_attributes' attrs[name] ||= [] attrs[name].push(form.save_data()) attrs class Editor.EditorModule.DockModule.ScenarioBay.Elements extends Backbone.View tagName: 'ul' className: 'scenarios_elements' initialize: (options) -> super(options) @parent = options.parent @element_lis = [] render: () -> this.$el.html('') _.each @scenario_elements(), (element_li) => this.$el.append(element_li.render().$el) _this = this this.$el.sortable { update: (event, ui) -> t = 0 $('.t-label', $(@)).map -> $(@).attr('data-t', t) t++ _this.trigger('sorted') } this refresh: () -> _.each @element_lis, (element_li) => element_li.refresh() scenario_elements: () -> res = [] _.each @element_lis, (element_li) => res[element_li.t()] = element_li res add_element: (element) -> e = new Editor.EditorModule.DockModule.ScenarioBay.Element({ parent: this, element: element }) @element_lis.push(e) # insert array @render() e sorted: () -> # data-t copy to model @trigger('sorted') class Editor.EditorModule.DockModule.ScenarioBay.Element extends Backbone.View tagName: 'li' className: 't-label' initialize: (options) -> super(options) @parent = options.parent @element = options.element render: () -> this.$el.html('') this.$el.attr('data-t', @t()) @label = new Editor.EditorModule.DockModule.ScenarioBay.ElementLabel({ parent: this, }) @body = new Editor.EditorModule.DockModule.ScenarioBay.ElementBody({ parent: this, }) this.$el.append(@label.render().$el) this.$el.append(@body.render().$el) rb = new Tag.RowBreak() this.$el.append(rb.render().el) this refresh: () -> @body.form.refresh() t: () -> @element.get('t') dom_id: () -> super() + '-' + @element.get('id') # use tab index class Editor.EditorModule.DockModule.ScenarioBay.ElementLabel extends Backbone.View className: 'scenario-label' initialize: (options) -> super(options) @parent = options.parent render: () -> this.$el.append(@element().element_face().render().el) _this = this this.$el.mouseover -> _this.element().trigger('active') this.$el.mouseout -> _this.element().trigger('inactive') this element: () -> @parent.element elements: () -> @parent.parent bay: () -> @elements().parent dock: () -> @bay().dock() class Editor.EditorModule.DockModule.ScenarioBay.ElementBody extends Backbone.View initialize: (options) -> super(options) @parent = options.parent @form = Locmare.Form.factory({ form_name: @element().item_name(), use_name: 'scenario' item: @element(), element_form: true, submit: null, operators: @dock().editor().operators, }) render: () -> this.$el.html(@form.render().el) this element: () -> @parent.element elements: () -> @parent.parent bay: () -> @elements().parent dock: () -> @bay().dock() mounted: () -> true element: () -> @parent.element class Editor.EditorModule.DockModule.NewBay extends Editor.EditorModule.DockModule.BoardBay class Editor.EditorModule.DockModule.TabModule.NewBayLabel extends Editor.EditorModule.DockModule.TabModule.BayLabel class Editor.EditorModule.DockModule.TabModule.NewBayBody extends Editor.EditorModule.DockModule.TabModule.BayBody initialize: (options) -> super(options) class Editor.EditorModule.DockModule.NewBoard extends Editor.EditorModule.DockModule.Board class Editor.EditorModule.DockModule.TabModule.NewBoardLabel extends Editor.EditorModule.DockModule.TabModule.BoardLabel class Editor.EditorModule.DockModule.TabModule.NewBoardBody extends Editor.EditorModule.DockModule.TabModule.BoardBody initialize: (options) -> super(options) # form_manager = Pettanr::Application::manifest.form_managers[self.root_item.form_name] # form = form_manager.open self.root_item, @dock_body.dock.editor.operators, mounted # bucket = Bucket.new self,form