X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=app%2Fassets%2Fjavascripts%2Feditor%2Fpanel_editor%2Fdock.js.coffee;h=2df7e39c9b1a3d907ae75b4a6249a438ed0c1627;hp=6fb3de4560f5497cd3b4bebfe5e64a8a15db7cf9;hb=ae200a3226cc6407ab381a81ed65f5d7ee557449;hpb=8c860bbc3faaff8c7a458b28f1cac7e30ff490df diff --git a/app/assets/javascripts/editor/panel_editor/dock.js.coffee b/app/assets/javascripts/editor/panel_editor/dock.js.coffee index 6fb3de45..2df7e39c 100644 --- a/app/assets/javascripts/editor/panel_editor/dock.js.coffee +++ b/app/assets/javascripts/editor/panel_editor/dock.js.coffee @@ -4,66 +4,50 @@ class Editor.PanelEditor.Dock extends Editor.EditorModule.DockBase initialize: (options) -> super(options) - tab = new Editor.EditorModule.DockModule.RootBay({ + @root_bay = new Editor.EditorModule.DockModule.RootBay({ parent: this, index: 0, name: 'panel' }) @add_tab( - tab, + @root_bay, new Editor.EditorModule.DockModule.TabModule.RootBayLabel({ - parent: tab, caption: 'panel' + parent: @root_bay, caption: 'panel' }), new Editor.EditorModule.DockModule.TabModule.RootBayBody({ - parent: tab + parent: @root_bay }) ) - tab = new Editor.EditorModule.DockModule.ElementBay({ + @element_bay = new Editor.EditorModule.DockModule.ElementBay({ parent: this, index: 1, name: 'elements' }) @add_tab( - tab, + @element_bay, new Editor.EditorModule.DockModule.TabModule.ElementBayLabel({ - parent: tab, caption: 'elements' + parent: @element_bay, caption: 'elements' }), new Editor.EditorModule.DockModule.TabModule.ElementBayBody({ - parent: tab + parent: @element_bay }) ) - tab = new Editor.EditorModule.DockModule.ScenarioBay({ + @scenario_bay = new Editor.EditorModule.DockModule.ScenarioBay({ parent: this, index: 2, name: 'scenario' }) @add_tab( - tab, + @scenario_bay, new Editor.EditorModule.DockModule.TabModule.ScenarioBayLabel({ - parent: tab, caption: 'scenario' + parent: @scenario_bay, caption: 'scenario' }), new Editor.EditorModule.DockModule.TabModule.ScenarioBayBody({ - parent: tab - }) - ) - tab = new Editor.EditorModule.DockModule.PriorityBay({ - parent: this, index: 3, name: 'priority' - }) - @add_tab( - tab, - new Editor.EditorModule.DockModule.TabModule.PriorityBayLabel({ - parent: tab, caption: 'priority' - }), - new Editor.EditorModule.DockModule.TabModule.PriorityBayBody({ - parent: tab - }) - ) - tab = new Editor.EditorModule.DockModule.NewBay({ - parent: this, index: 4, name: 'new' - }) - @add_tab( - tab, - new Editor.EditorModule.DockModule.TabModule.NewBayLabel({ - parent: tab, caption: 'new' - }), - new Editor.EditorModule.DockModule.TabModule.NewBayBody({ - parent: tab + parent: @scenario_bay }) ) + @listenTo(@root_bay.body, 'http_post', @http_post) + @listenTo(@root_bay.body, 'save:success', @post_success) + @listenTo(@root_bay.body, 'save:fail', @post_fail) + @listenTo(@element_bay, 'add:credit', @add_credit) + @listenTo(@element_bay, 'pick', @pick) + @listenTo(@element_bay, 'dialog:open', @open_dialog) + @listenTo(@element_bay, 'dialog:close', @close_dialog) + @listenTo(@element_bay, 'destroy', @destroy) render: () -> this.$el.html('') @@ -71,11 +55,18 @@ class Editor.PanelEditor.Dock extends Editor.EditorModule.DockBase tab.label labels = new Tag.Ul({contents: l, class_name: @dom_labels_class()}) this.$el.append(labels.render().el) - _this = this - _.each @tabs, (tab) -> - _this.$el.append(tab.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 @@ -88,336 +79,41 @@ class Editor.PanelEditor.Dock extends Editor.EditorModule.DockBase dom_labels_class: () -> @dom_class() + '-labels' -class Editor.EditorModule.DockModule.RootBay extends Editor.EditorModule.DockModule.SimpleBay - - render: () -> - @body.render() - -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 = new Locmare.Bucket.factory( - @root_item().item_name(), - @root_item(), - @mounted(), - 'default', - @dock().editor().operators - ) - @bucket = new Editor.EditorModule.DockModule.FormBucket({ - parent: this, form: @form - }) - - render: () -> - super() - @el.className = @bay().body.dom_class() - this.$el.html(@bucket.render().el) - this - - mounted: () -> - true - - dock: () -> - @parent.dock() - - root_item: () -> - @dock().root_item() - -class Editor.EditorModule.DockModule.ElementBay extends Editor.EditorModule.DockModule.BoardBay - - initialize: (options) -> - super(options) - _this = this - i = 0 - _.each @elements(), (element) -> - tab = new Editor.EditorModule.DockModule.ElementBoard({ - parent: _this, index: i, name: element.item_name(), element: element - }) - _this.add_tab( - tab, - new Editor.EditorModule.DockModule.TabModule.ElementBoardLabel({parent: tab, name: element.item_name()}), - new Editor.EditorModule.DockModule.TabModule.ElementBoardBody({parent: tab}) - ) - i++ - - render: () -> - this.$el.html('') - this.$el.attr('id', @body.dom_id()) - elements_tabs = new Editor.EditorModule.DockModule.ElementBay.ElementsTabs({ - tabs: @tabs - }) - this.$el.append(elements_tabs.render().el) - elements_tabs.$el.tabs() - elements_tabs.$el.addClass('ui-tabs-vertical ui-helper-clearfix') - $("li", elements_tabs.$el).removeClass('ui-corner-top') - $("li", elements_tabs.$el).addClass('ui-corner-left') - this - - elements: () -> - @root_item().scenario_elements() - -class Editor.EditorModule.DockModule.ElementBay.ElementsTabs extends Backbone.View - tagName: 'div' - className: 'elements_tabs ui-tabs-vertical ui-helper-clearfix' - - initialize: (options) -> - super(options) - @tabs = options.tabs - - render: () -> - this.$el.html('') - _this = this - labels = _.map @tabs, (tab) -> - tab.label - inner_elements_tabs = new Editor.EditorModule.DockModule.ElementBay.InnerElementsTabs({ - labels: labels - }) - this.$el.append(inner_elements_tabs.render().el) - _.each @tabs, (tab) -> - _this.$el.append(tab.body.render().el) - this - -class Editor.EditorModule.DockModule.ElementBay.InnerElementsTabs extends Backbone.View - tagName: 'ul' - - initialize: (options) -> - super(options) - @labels = options.labels - - render: () -> - this.$el.html('') - _this = this - _.each @labels, (label) -> - _this.$el.append(label.render().el) - this - -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 - -class Editor.EditorModule.DockModule.TabModule.ElementBoardBody extends Editor.EditorModule.DockModule.TabModule.BoardBody - - initialize: (options) -> - super(options) - @form = Locmare.Bucket.factory( - @element().item_name(), - @element(), - @mounted(), - null, - @dock().editor().operators - ) - @bucket = new Editor.EditorModule.DockModule.FormBucket({ - parent: this, form: @form - }) - - render: () -> - this.$el.attr('id', @dom_id()) - this.$el.html(@bucket.render().el) - this - - mounted: () -> - true - - element: () -> - @parent.element - -class Editor.EditorModule.DockModule.ScenarioBay extends Editor.EditorModule.DockModule.BoardBay - - initialize: (options) -> - super(options) - _this = this - i = 0 - _.each @elements(), (element) -> - tab = new Editor.EditorModule.DockModule.ScenarioBoard({ - parent: _this, index: i, name: element.item_name(), element: element - }) - _this.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()) - _this = this - 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('') - _this = this - _.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) - _this = this - i = 0 - _.each @elements(), (element) -> - tab = new Editor.EditorModule.DockModule.PriorityBoard({ - parent: _this, index: i, name: element.item_name(), element: element - }) - _this.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()) - _this = this - 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('') - _this = this - _.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: () -> + http_post: (url, root_form) -> + @trigger('http_post', url, this) # send dock false -class Editor.EditorModule.DockModule.TabModule.PriorityBoardLabel extends Editor.EditorModule.DockModule.TabModule.BoardLabel + post_success: (model, response) -> + @trigger('save:success', model, response) - with_destroy_button: () -> - false + post_fail: (model, response) -> + @trigger('save:fail', response) -class Editor.EditorModule.DockModule.TabModule.PriorityBoardBody extends Editor.EditorModule.DockModule.TabModule.BoardBody + add_credit: (element) -> + @trigger('add:credit', element) - 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 + save: () -> + # merge panel and elements + attrs = @root_bay.save_data() + _.extend(attrs, @element_bay.save_data()) + $.extend(true, attrs, @scenario_bay.save_data()) # deep merge by jQuery + # save json data by panel form + @root_bay.body.form.save(attrs) - -class Editor.EditorModule.DockModule.TabModule.NewBayLabel extends Editor.EditorModule.DockModule.TabModule.BayLabel + pick: (new_item) -> + @scenario_bay.pick(new_item) + @trigger('add:element', new_item) - -class Editor.EditorModule.DockModule.TabModule.NewBayBody extends Editor.EditorModule.DockModule.TabModule.BayBody + open_dialog: (dialog) -> + @trigger('dialog:open', dialog) - initialize: (options) -> - super(options) + close_dialog: (dialog) -> + @trigger('dialog:close', dialog) -class Editor.EditorModule.DockModule.NewBoard extends Editor.EditorModule.DockModule.Board + destroy: (element) -> + @trigger('destroy', element) + @scenario_bay.remove_element(element) -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 + quit: () -> + @root_bay.body.form.quit()