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, 'put', @put) 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 add_element: (element) -> @element_bay.add_element(element) editor: () -> @parent dom_id: () -> @editor().dom_id() + '-dock' dom_class: () -> @editor().dom_class() + '-dock' dom_labels_class: () -> @dom_class() + '-labels' put: () -> @trigger('put') false save: (options) -> attrs = @save_data() @root_bay.body.form.save(attrs, options) save_data: () -> attrs = @root_bay.save_data() _.extend(attrs, @element_bay.save_data()) attrs valid: () -> @root_bay.body.form.valid() invalid: () -> @root_bay.body.form.invalid() 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(), 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, 'put', @put) 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() put: () -> @trigger('put') 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') bb.form 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('') this.$el.attr('id', @body.dom_id()) this.$el.append(@elements_tabs.render().el) @elements_tabs.$el.tabs() # @add_new_tab() this 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(), item: @element(), mounted: @mounted(), submit: null, operators: @dock().editor().operators, action: '/' + @element().table_name() + '/' + Pettanr.to_s(@element().get('id')) }) render: () -> this.$el.attr('id', @dom_id()) this.$el.html(@form.render().el) this add_element: (element) -> @form.add_element(element) mounted: () -> true 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: () -> this.$el.append() 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() }) @form_wrapper = new Editor.EditorModule.DockModule.NewElementFormWrapper({ parent: this }) this.$el.append(@buttons.render().el) this.$el.append(@form_wrapper.clear().el) this panel: () -> @parent.panel element_models: () -> @panel().my_class().child_models() 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 }) this.$el.append(button.render().el) this 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: '#event' }, content: icon.render().el, handler_name: 'click' }) @listenTo(linked_icon, 'click', @click) this.$el.append(linked_icon.render().el) this click: () -> @set_dialog() @set_form() @dialog().$el.dialog('open') set_dialog: () -> @params = { controller: @model.path_name(), action: 'index', page_size: 6 } @list = Locmare.ListGroup.list( @model.path_name(), 'index', @operators(), @params ) @list.open(() => pager = Locmare.ListGroupModule.LibModule.Pager.factory(@list.page_status, @params) f = new Locmare.Filer({ el: @dialog().$el, item_name: @model.item_name(), items: @list.items(), pager: pager, operators: @operators() }) ) this set_form: () -> @form_wrapper().select(@model) operators: () -> @editor().operators form_wrapper: () -> @parent.parent.form_wrapper dock: () -> @parent.parent.dock() dialog: () -> @editor().dialog editor: () -> @dock().parent class Editor.EditorModule.DockModule.NewElementLinkedButton extends Tag.A click: () -> @trigger('click') return false class Editor.EditorModule.DockModule.NewElementFormWrapper extends Backbone.View tagName: 'div' initialize: (options) -> super(options) @parent = options.parent clear: () -> this.$el.html('new form') this render: () -> this.$el.html(@model.item_name()) select: (model) -> @model = model @render() class Editor.EditorModule.DockModule.ScenarioBay extends Editor.EditorModule.DockModule.BoardBay initialize: (options) -> super(options) i = 0 _.each @elements(), (element) => tab = new Editor.EditorModule.DockModule.ScenarioBoard({ parent: this, index: i, name: element.item_name(), element: element }) @add_tab( tab, new Editor.EditorModule.DockModule.TabModule.ScenarioBoardLabel({parent: tab, caption: element.item_name()}), new Editor.EditorModule.DockModule.TabModule.ScenarioBoardBody({parent: tab}) ) i++ render: () -> this.$el.html('') this.$el.attr('id', @body.dom_id()) elements_tabs = new Editor.EditorModule.DockModule.ScenarioBay.ScenarioTabs({ tabs: @tabs }) this.$el.append(elements_tabs.render().el) _.each @tabs, (tab) => this.$el.append(tab.body.render().el) elements_tabs.$el.tabs() this elements: () -> @root_item().scenario_elements() class_name: () -> "tsort-box" class Editor.EditorModule.DockModule.ScenarioBay.ScenarioTabs extends Backbone.View tagName: 'ul' className: 'tsort' initialize: (options) -> super(options) @tabs = options.tabs render: () -> this.$el.html('') _.each @tabs, (tab) => this.$el.append(tab.label.render().el) this 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) class Editor.EditorModule.DockModule.ScenarioBoard extends Editor.EditorModule.DockModule.Board initialize: (options) -> super(options) @element = options.element class Editor.EditorModule.DockModule.TabModule.ScenarioBoardLabel extends Editor.EditorModule.DockModule.TabModule.BoardLabel with_destroy_button: () -> false class Editor.EditorModule.DockModule.TabModule.ScenarioBoardBody extends Editor.EditorModule.DockModule.TabModule.BoardBody initialize: (options) -> super(options) @bucket = new Editor.EditorModule.DockModule.ScenarioBucket({ parent: this }) class Editor.EditorModule.DockModule.PriorityBay extends Editor.EditorModule.DockModule.BoardBay initialize: (options) -> super(options) i = 0 _.each @elements(), (element) => tab = new Editor.EditorModule.DockModule.PriorityBoard({ parent: this, index: i, name: element.item_name(), element: element }) @add_tab( tab, new Editor.EditorModule.DockModule.TabModule.PriorityBoardLabel({parent: tab, name: element.item_name()}), new Editor.EditorModule.DockModule.TabModule.PriorityBoardBody({parent: tab}) ) i++ render: () -> this.$el.html('') this.$el.attr('id', @body.dom_id()) elements_tabs = new Editor.EditorModule.DockModule.PriorityBay.PriorityTabs({ tabs: @tabs }) this.$el.append(elements_tabs.render().el) _.each @tabs, (tab) => this.$el.append(tab.body.render().el) elements_tabs.$el.tabs() this elements: () -> @root_item().scenario_elements() class_name: () -> "zsort-box" class Editor.EditorModule.DockModule.PriorityBay.PriorityTabs extends Backbone.View tagName: 'ul' className: 'zsort' initialize: (options) -> super(options) @tabs = options.tabs render: () -> this.$el.html('') _.each @tabs, (tab) => this.$el.append(tab.label.render().el) this class Editor.EditorModule.DockModule.TabModule.PriorityBayLabel extends Editor.EditorModule.DockModule.TabModule.BayLabel class Editor.EditorModule.DockModule.TabModule.PriorityBayBody extends Editor.EditorModule.DockModule.TabModule.BayBody initialize: (options) -> super(options) class Editor.EditorModule.DockModule.PriorityBoard extends Editor.EditorModule.DockModule.Board initialize: (options) -> super(options) @element = options.element mounted: () -> false class Editor.EditorModule.DockModule.TabModule.PriorityBoardLabel extends Editor.EditorModule.DockModule.TabModule.BoardLabel with_destroy_button: () -> false class Editor.EditorModule.DockModule.TabModule.PriorityBoardBody extends Editor.EditorModule.DockModule.TabModule.BoardBody initialize: (options) -> super(options) @bucket = new Editor.EditorModule.DockModule.PriorityBucket({ parent: this }) # 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 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