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=596f29f74dd7aaab24eb35f44fd423841db67290;hb=ae200a3226cc6407ab381a81ed65f5d7ee557449;hpb=ce9b38c6259758f06a443f08701d7a5102696b0f diff --git a/app/assets/javascripts/editor/panel_editor/dock.js.coffee b/app/assets/javascripts/editor/panel_editor/dock.js.coffee index 596f29f7..2df7e39c 100644 --- a/app/assets/javascripts/editor/panel_editor/dock.js.coffee +++ b/app/assets/javascripts/editor/panel_editor/dock.js.coffee @@ -40,7 +40,14 @@ class Editor.PanelEditor.Dock extends Editor.EditorModule.DockBase parent: @scenario_bay }) ) - @listenTo(@root_bay.body, 'put', @put) + @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('') @@ -52,8 +59,13 @@ class Editor.PanelEditor.Dock extends Editor.EditorModule.DockBase this.$el.append(tab.render().el) this - add_element: (element) -> - @element_bay.add_element(element) + init_tabs: () -> + @element_bay.init_tabs() + @scenario_bay.init_tabs() + this.$el.tabs({ + activate: (e, ui) -> + ui.newPanel.trigger('activate') + }) editor: () -> @parent @@ -67,586 +79,41 @@ class Editor.PanelEditor.Dock extends Editor.EditorModule.DockBase dom_labels_class: () -> @dom_class() + '-labels' - put: () -> - @trigger('put') - false - - 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(), - 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') + http_post: (url, root_form) -> + @trigger('http_post', url, this) # send dock 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 - $('li', $(@)).map -> - $(@).attr('data-z', z) - z++ - _this.trigger('sorted') - } - this - - zorderd_labels: () -> - res = [] - _.each @labels, (label) => - res[label.z()] = label - res + post_success: (model, response) -> + @trigger('save:success', model, response) - add_label: (label) -> - #z = label.z() - @labels.push(label) # insert array - @render() - label.add_label() + post_fail: (model, response) -> + @trigger('save:fail', response) -class Editor.EditorModule.DockModule.TabModule.ElementBayLabel extends Editor.EditorModule.DockModule.TabModule.BayLabel + add_credit: (element) -> + @trigger('add:credit', element) -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') - _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 - - initialize: (options) -> - super(options) - - render: () -> - this.$el.attr('id', @dom_id()) - @new_element_pocket = new Editor.EditorModule.DockModule.NewElementPocket({ - parent: this - }) - this.$el.append(@new_element_pocket.render().el) - this - -class Editor.EditorModule.DockModule.NewElementPocket extends Editor.EditorModule.DockModule.Pocket - - initialize: (options) -> - super(options) - @button_wrapper = new Editor.EditorModule.DockModule.NewElementPocket.ButtonWrapper({ - parent: this - }) - - render: () -> - this.$el.html('') - this.$el.append(@button_wrapper.clear().el) - @add_tabs() - _.each @tabs, (tab) => - this.$el.append(tab.body.render().el) - @button_wrapper.render() - this.$el.tabs() - this - - add_tabs: () -> - index = 0 - _.each @element_models(), (model) => - tab = new Editor.EditorModule.DockModule.NewElementPocketTab({ - parent: this, index: index, name: model.item_name(), model: model - }) - bb = new Editor.EditorModule.DockModule.TabModule.NewElementPocketBody({ - parent: tab - }) - bl = new Editor.EditorModule.DockModule.TabModule.NewElementPocketLabel({ - parent: tab - }) - @add_tab(tab, bl, bb) - @button_wrapper.add_label(bl) - index++ - - panel: () -> - @parent.parent.panel - - element_models: () -> - @panel().my_class().child_models() - -class Editor.EditorModule.DockModule.NewElementPocket.ButtonWrapper extends Backbone.View - tagName: 'div' - className: 'new_elements_tabs ui-tabs-vertical ui-helper-clearfix' - - initialize: (options) -> - super(options) - @parent = options.parent - @buttons = new Editor.EditorModule.DockModule.NewElementPocket.Buttons({ - parent: this - }) - - clear: () -> - this.$el.html('') - this - - render: () -> - this.$el.append(@buttons.render().$el) - this - - add_label: (label) -> - @buttons.add_label(label) - -class Editor.EditorModule.DockModule.NewElementPocket.Buttons extends Backbone.View - tagName: 'ul' - - initialize: (options) -> - super(options) - @parent = options.parent - @labels = [] - - render: () -> - this.$el.html('') - this.$el.addClass('inner-new-elements-tabs') - _.each @labels, (label) => - this.$el.append(label.render().$el) - this - - add_label: (label) -> - @labels.push(label) - -class Editor.EditorModule.DockModule.TabModule.NewElementPocketLabel extends Editor.EditorModule.DockModule.TabModule.PocketLabel - - render: () -> - super() - this.$el.removeClass('ui-corner-top') - this.$el.addClass('ui-corner-left') - this - - add_label: () -> - this.$el.attr('id', @dom_id()) - -class Editor.EditorModule.DockModule.TabModule.NewElementPocketBody extends Editor.EditorModule.DockModule.TabModule.PocketBody - - initialize: (options) -> - super(options) - - render: () -> - this.$el.attr('id', @dom_id()) - @params = {controller: @model().path_name(), action: 'index'} - @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: '#' + @dom_id(), - item_name: @model().item_name(), - items: @list.items(), - pager: pager, - operators: @operators() - }) - ) - this - - operators: () -> - @editor().operators - - model: () -> - @pocket_tab().model - - editor: () -> - @dock().parent - -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 + 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.NewBayBody extends Editor.EditorModule.DockModule.TabModule.BayBody + pick: (new_item) -> + @scenario_bay.pick(new_item) + @trigger('add:element', new_item) - initialize: (options) -> - super(options) + open_dialog: (dialog) -> + @trigger('dialog:open', dialog) -class Editor.EditorModule.DockModule.NewBoard extends Editor.EditorModule.DockModule.Board + close_dialog: (dialog) -> + @trigger('dialog:close', dialog) -class Editor.EditorModule.DockModule.TabModule.NewBoardLabel extends Editor.EditorModule.DockModule.TabModule.BoardLabel + destroy: (element) -> + @trigger('destroy', element) + @scenario_bay.remove_element(element) -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()