\r
initialize: (options) ->\r
super(options)\r
- tab = new Editor.EditorModule.DockModule.RootBay({\r
+ @root_bay = new Editor.EditorModule.DockModule.RootBay({\r
parent: this, index: 0, name: 'panel'\r
})\r
@add_tab(\r
- tab, \r
+ @root_bay, \r
new Editor.EditorModule.DockModule.TabModule.RootBayLabel({\r
- parent: tab, caption: 'panel'\r
+ parent: @root_bay, caption: 'panel'\r
}), \r
new Editor.EditorModule.DockModule.TabModule.RootBayBody({\r
- parent: tab\r
+ parent: @root_bay\r
})\r
)\r
- tab = new Editor.EditorModule.DockModule.ElementBay({\r
+ @element_bay = new Editor.EditorModule.DockModule.ElementBay({\r
parent: this, index: 1, name: 'elements'\r
})\r
@add_tab(\r
- tab, \r
+ @element_bay, \r
new Editor.EditorModule.DockModule.TabModule.ElementBayLabel({\r
- parent: tab, caption: 'elements'\r
+ parent: @element_bay, caption: 'elements'\r
}), \r
new Editor.EditorModule.DockModule.TabModule.ElementBayBody({\r
- parent: tab\r
+ parent: @element_bay\r
})\r
)\r
- tab = new Editor.EditorModule.DockModule.ScenarioBay({\r
+ @scenario_bay = new Editor.EditorModule.DockModule.ScenarioBay({\r
parent: this, index: 2, name: 'scenario'\r
})\r
@add_tab(\r
- tab, \r
+ @scenario_bay, \r
new Editor.EditorModule.DockModule.TabModule.ScenarioBayLabel({\r
- parent: tab, caption: 'scenario'\r
+ parent: @scenario_bay, caption: 'scenario'\r
}), \r
new Editor.EditorModule.DockModule.TabModule.ScenarioBayBody({\r
- parent: tab\r
- })\r
- )\r
- tab = new Editor.EditorModule.DockModule.PriorityBay({\r
- parent: this, index: 3, name: 'priority'\r
- })\r
- @add_tab(\r
- tab, \r
- new Editor.EditorModule.DockModule.TabModule.PriorityBayLabel({\r
- parent: tab, caption: 'priority'\r
- }), \r
- new Editor.EditorModule.DockModule.TabModule.PriorityBayBody({\r
- parent: tab\r
- })\r
- )\r
- tab = new Editor.EditorModule.DockModule.NewBay({\r
- parent: this, index: 4, name: 'new'\r
- })\r
- @add_tab(\r
- tab, \r
- new Editor.EditorModule.DockModule.TabModule.NewBayLabel({\r
- parent: tab, caption: 'new'\r
- }), \r
- new Editor.EditorModule.DockModule.TabModule.NewBayBody({\r
- parent: tab\r
+ parent: @scenario_bay\r
})\r
)\r
+ @listenTo(@root_bay.body, 'put', @put)\r
\r
render: () ->\r
this.$el.html('')\r
this.$el.append(tab.render().el)\r
this\r
\r
+ add_element: (element) ->\r
+ @element_bay.add_element(element)\r
+ \r
editor: () ->\r
@parent\r
\r
dom_labels_class: () ->\r
@dom_class() + '-labels'\r
\r
+ put: () ->\r
+ @trigger('put')\r
+ false\r
+ \r
+ save: (options) ->\r
+ attrs = @save_data()\r
+ @root_bay.body.form.save(attrs, options)\r
+ \r
+ save_data: () ->\r
+ attrs = @root_bay.save_data()\r
+ _.extend(attrs, @element_bay.save_data())\r
+ attrs\r
+ \r
+ valid: () ->\r
+ @root_bay.body.form.valid()\r
+ \r
+ invalid: () ->\r
+ @root_bay.body.form.invalid()\r
+ \r
class Editor.EditorModule.DockModule.RootBay extends Editor.EditorModule.DockModule.SimpleBay\r
\r
render: () ->\r
@body.render()\r
\r
+ save_data: () ->\r
+ @body.form.save_data()\r
+ \r
class Editor.EditorModule.DockModule.TabModule.RootBayLabel extends Editor.EditorModule.DockModule.TabModule.BayLabel\r
\r
class Editor.EditorModule.DockModule.TabModule.RootBayBody extends Editor.EditorModule.DockModule.TabModule.BayBody\r
\r
initialize: (options) ->\r
super(options)\r
- @form = new Locmare.Bucket.factory(\r
- @root_item().item_name(), \r
- @root_item(), \r
- @mounted(), \r
- 'default', \r
- @dock().editor().operators\r
- )\r
- @bucket = new Editor.EditorModule.DockModule.FormBucket({\r
- parent: this, form: @form\r
+ @form = Locmare.Form.factory({\r
+ form_name: @root_item().item_name(), \r
+ use_name: 'default' \r
+ item: @root_item(), \r
+ mounted: @mounted(), \r
+ submit: 'default' \r
+ operators: @dock().editor().operators,\r
+ action: '/' + @root_item().table_name() + '/' + Pettanr.to_s(@root_item().get('id'))\r
})\r
+ @listenTo(@form, 'put', @put)\r
\r
render: () ->\r
super()\r
@el.className = @bay().body.dom_class()\r
- this.$el.html(@bucket.render().el)\r
+ this.$el.html(@form.render().el)\r
this\r
\r
mounted: () ->\r
root_item: () ->\r
@dock().root_item()\r
\r
+ put: () ->\r
+ @trigger('put')\r
+ false\r
+ \r
class Editor.EditorModule.DockModule.ElementBay extends Editor.EditorModule.DockModule.BoardBay\r
\r
initialize: (options) ->\r
super(options)\r
- i = 0\r
- _.each @elements(), (element) =>\r
- tab = new Editor.EditorModule.DockModule.ElementBoard({\r
- parent: this, index: i, name: element.item_name(), element: element\r
- })\r
- @add_tab(\r
- tab, \r
- new Editor.EditorModule.DockModule.TabModule.ElementBoardLabel({parent: tab, name: element.item_name()}), \r
- new Editor.EditorModule.DockModule.TabModule.ElementBoardBody({parent: tab})\r
- )\r
- i++\r
+ @elements_tabs = new Editor.EditorModule.DockModule.ElementBay.ElementsTabs({\r
+ })\r
+ @listenTo(@elements_tabs, 'sorted', @sorted)\r
+ \r
+ add_element: (element) ->\r
+ index = element.get('z') - 1\r
+ tab = new Editor.EditorModule.DockModule.ElementBoard({\r
+ parent: this, index: index, name: element.item_name(), element: element\r
+ })\r
+ bb = new Editor.EditorModule.DockModule.TabModule.ElementBoardBody({parent: tab})\r
+ @add_tab(\r
+ tab, \r
+ new Editor.EditorModule.DockModule.TabModule.ElementBoardLabel({parent: tab, name: element.item_name()}), \r
+ bb\r
+ )\r
+ @elements_tabs.add_element_tab(tab)\r
+ @elements_tabs.$el.tabs('refresh')\r
+ bb.form\r
+ \r
+ add_new_tab: () ->\r
+ tab = new Editor.EditorModule.DockModule.NewElementBoard({\r
+ parent: this, index: 0, name: 'new'\r
+ })\r
+ bb = new Editor.EditorModule.DockModule.TabModule.NewElementBoardBody({parent: tab})\r
+ @add_tab(\r
+ tab, \r
+ new Editor.EditorModule.DockModule.TabModule.NewElementBoardLabel({parent: tab}), \r
+ bb\r
+ )\r
+ @elements_tabs.add_element_tab(tab)\r
\r
render: () ->\r
this.$el.html('')\r
this.$el.attr('id', @body.dom_id())\r
- elements_tabs = new Editor.EditorModule.DockModule.ElementBay.ElementsTabs({\r
- tabs: @tabs\r
- })\r
- this.$el.append(elements_tabs.render().el)\r
- elements_tabs.$el.tabs()\r
- elements_tabs.$el.addClass('ui-tabs-vertical ui-helper-clearfix')\r
- $("li", elements_tabs.$el).removeClass('ui-corner-top')\r
- $("li", elements_tabs.$el).addClass('ui-corner-left')\r
+ this.$el.append(@elements_tabs.render().el)\r
+ @elements_tabs.$el.tabs()\r
+ # @add_new_tab()\r
this\r
\r
- elements: () ->\r
- @root_item().scenario_elements()\r
+ sorted: () ->\r
+ # data-z copy to model\r
+ _.each @tabs, (tab) ->\r
+ if tab.element # without new_tab\r
+ z = parseInt(tab.label.$el.attr('data-z'))\r
+ tab.element.set({\r
+ z: z\r
+ }, {silent: true})\r
+ tab.element.trigger('sort')\r
+ \r
+ panel_body: () ->\r
+ @dock().editor().body\r
+ \r
+ save_data: () ->\r
+ attrs = {}\r
+ _.each @tabs, (tab) ->\r
+ return if not tab.element # without new element tab\r
+ form = tab.body.form\r
+ name = form.item.table_name() + '_attributes'\r
+ attrs[name] ||= []\r
+ attrs[name].push(form.save_data())\r
+ attrs\r
\r
class Editor.EditorModule.DockModule.ElementBay.ElementsTabs extends Backbone.View\r
tagName: 'div'\r
\r
initialize: (options) ->\r
super(options)\r
- @tabs = options.tabs\r
+ @inner_elements_tabs = new Editor.EditorModule.DockModule.ElementBay.InnerElementsTabs({\r
+ })\r
+ @listenTo(@inner_elements_tabs, 'sorted', @sorted)\r
\r
render: () ->\r
this.$el.html('')\r
- labels = _.map @tabs, (tab) =>\r
- tab.label\r
- inner_elements_tabs = new Editor.EditorModule.DockModule.ElementBay.InnerElementsTabs({\r
- labels: labels\r
- })\r
- this.$el.append(inner_elements_tabs.render().el)\r
- _.each @tabs, (tab) =>\r
- this.$el.append(tab.body.render().el)\r
+ this.$el.append(@inner_elements_tabs.render().$el)\r
this\r
\r
+ add_element_tab: (tab) ->\r
+ @inner_elements_tabs.add_label(tab.label)\r
+ this.$el.append(tab.body.render().$el)\r
+ \r
+ sorted: () ->\r
+ # data-z copy to model\r
+ @trigger('sorted')\r
+ \r
class Editor.EditorModule.DockModule.ElementBay.InnerElementsTabs extends Backbone.View\r
tagName: 'ul'\r
\r
initialize: (options) ->\r
super(options)\r
- @labels = options.labels\r
+ @labels = []\r
\r
render: () ->\r
this.$el.html('')\r
- _.each @labels, (label) =>\r
- this.$el.append(label.render().el)\r
+ this.$el.addClass('inner-elements-tabs')\r
+ _.each @zorderd_labels(), (label) =>\r
+ this.$el.append(label.render().$el)\r
+ _this = this\r
+ this.$el.sortable {\r
+ update: (event, ui) ->\r
+ z = 1\r
+ $('.z-label', $(@)).map ->\r
+ $(@).attr('data-z', z)\r
+ z++\r
+ _this.trigger('sorted')\r
+ }\r
this\r
\r
+ zorderd_labels: () ->\r
+ res = []\r
+ _.each @labels, (label) =>\r
+ res[label.z()] = label\r
+ res\r
+ \r
+ add_label: (label) ->\r
+ #z = label.z()\r
+ @labels.push(label) # insert array\r
+ @render()\r
+ label.add_label()\r
+ \r
class Editor.EditorModule.DockModule.TabModule.ElementBayLabel extends Editor.EditorModule.DockModule.TabModule.BayLabel\r
\r
class Editor.EditorModule.DockModule.TabModule.ElementBayBody extends Editor.EditorModule.DockModule.TabModule.BayBody\r
@element = options.element\r
\r
dom_id: () ->\r
- super() + '-' + @element.get('id') + '-' # use tab index\r
+ super() + '-' + @element.get('id') # use tab index\r
\r
class Editor.EditorModule.DockModule.TabModule.ElementBoardLabel extends Editor.EditorModule.DockModule.TabModule.BoardLabel\r
\r
+ render: () ->\r
+ super()\r
+ this.$el.attr('data-z', @z())\r
+ this.$el.removeClass('ui-corner-top')\r
+ this.$el.addClass('ui-corner-left z-label')\r
+ _this = this\r
+ this.$el.mouseover -> \r
+ _this.element().trigger('active')\r
+ this.$el.mouseout -> \r
+ _this.element().trigger('inactive')\r
+ this\r
+ \r
+ z: () ->\r
+ @element().get('z')\r
+ \r
+ add_label: () ->\r
+ this.$el.attr('id', @dom_id())\r
+ \r
class Editor.EditorModule.DockModule.TabModule.ElementBoardBody extends Editor.EditorModule.DockModule.TabModule.BoardBody\r
\r
initialize: (options) ->\r
super(options)\r
- @form = Locmare.Bucket.factory(\r
- @element().item_name(), \r
- @element(), \r
- @mounted(), \r
- null, \r
- @dock().editor().operators\r
- )\r
- @bucket = new Editor.EditorModule.DockModule.FormBucket({\r
- parent: this, form: @form\r
+ @form = Locmare.Form.factory({\r
+ form_name: @element().item_name(), \r
+ use_name: 'default' \r
+ item: @element(), \r
+ mounted: @mounted(), \r
+ submit: null, \r
+ operators: @dock().editor().operators,\r
+ action: '/' + @element().table_name() + '/' + Pettanr.to_s(@element().get('id'))\r
})\r
\r
render: () ->\r
this.$el.attr('id', @dom_id())\r
- this.$el.html(@bucket.render().el)\r
+ this.$el.html(@form.render().el)\r
this\r
\r
+ add_element: (element) ->\r
+ @form.add_element(element)\r
+ \r
mounted: () ->\r
true\r
\r
element: () ->\r
@parent.element\r
\r
+class Editor.EditorModule.DockModule.NewElementBoard extends Editor.EditorModule.DockModule.Board\r
+ \r
+ initialize: (options) ->\r
+ super(options)\r
+ @panel = @parent.dock().editor().panel\r
+ \r
+class Editor.EditorModule.DockModule.TabModule.NewElementBoardLabel extends Editor.EditorModule.DockModule.TabModule.BoardLabel\r
+ \r
+ render: () ->\r
+ super()\r
+ this.$el.attr('data-z', @z())\r
+ this.$el.removeClass('ui-corner-top')\r
+ this.$el.addClass('ui-corner-left')\r
+ this\r
+ \r
+ face: () ->\r
+ this.$el.append()\r
+ icon = new Pettanr.Image.SymbolImg({attr: {src: '/images/new.gif'}})\r
+ linked_elements_tab = new Tag.A({\r
+ attr: {href: '#' + @board().body.dom_id() },\r
+ content: icon.render().el\r
+ })\r
+ this.$el.append(linked_elements_tab.render().el)\r
+ \r
+ z: () ->\r
+ 0\r
+ \r
+ add_label: () ->\r
+ this.$el.attr('id', @dom_id())\r
+ \r
+class Editor.EditorModule.DockModule.TabModule.NewElementBoardBody extends Editor.EditorModule.DockModule.TabModule.BoardBody\r
+ className: 'new-element-board-body'\r
+ \r
+ initialize: (options) ->\r
+ super(options)\r
+ \r
+ render: () ->\r
+ this.$el.attr('id', @dom_id())\r
+ @buttons = new Editor.EditorModule.DockModule.NewElementButtons({\r
+ parent: this, element_models: @element_models()\r
+ })\r
+ @form_wrapper = new Editor.EditorModule.DockModule.NewElementFormWrapper({\r
+ parent: this\r
+ })\r
+ this.$el.append(@buttons.render().el)\r
+ this.$el.append(@form_wrapper.clear().el)\r
+ this\r
+ \r
+ panel: () ->\r
+ @parent.panel\r
+ \r
+ element_models: () ->\r
+ @panel().my_class().child_models()\r
+ \r
+class Editor.EditorModule.DockModule.NewElementButtons extends Backbone.View\r
+ tagName: 'div'\r
+ className: 'new-element-buttons'\r
+ \r
+ initialize: (options) ->\r
+ super(options)\r
+ @parent = options.parent\r
+ @element_models = options.element_models\r
+ \r
+ render: () ->\r
+ _.each @element_models, (model) =>\r
+ button = new Editor.EditorModule.DockModule.NewElementButton({\r
+ parent: this, model: model\r
+ })\r
+ this.$el.append(button.render().el)\r
+ this\r
+ \r
+class Editor.EditorModule.DockModule.NewElementButton extends Backbone.View\r
+ tagName: 'div'\r
+ \r
+ initialize: (options) ->\r
+ super(options)\r
+ @parent = options.parent\r
+ @model = options.model\r
+ \r
+ render: () ->\r
+ this.$el.html('')\r
+ icon = new Pettanr.Image.Icon({item: @model})\r
+ linked_icon = new Editor.EditorModule.DockModule.NewElementLinkedButton({\r
+ attr: {href: '#event' },\r
+ content: icon.render().el,\r
+ handler_name: 'click'\r
+ })\r
+ @listenTo(linked_icon, 'click', @click)\r
+ this.$el.append(linked_icon.render().el)\r
+ this\r
+ \r
+ click: () ->\r
+ @set_dialog()\r
+ @set_form()\r
+ @dialog().$el.dialog('open')\r
+ \r
+ set_dialog: () ->\r
+ @params = {\r
+ controller: @model.path_name(), action: 'index',\r
+ page_size: 6\r
+ }\r
+ @list = Locmare.ListGroup.list(\r
+ @model.path_name(), 'index', @operators(), @params\r
+ )\r
+ @list.open(() =>\r
+ pager = Locmare.ListGroupModule.LibModule.Pager.factory(@list.page_status, @params)\r
+ f = new Locmare.Filer({\r
+ el: @dialog().$el,\r
+ item_name: @model.item_name(), \r
+ items: @list.items(), \r
+ pager: pager, \r
+ operators: @operators()\r
+ })\r
+ )\r
+ this\r
+ \r
+ set_form: () ->\r
+ @form_wrapper().select(@model)\r
+ \r
+ operators: () ->\r
+ @editor().operators\r
+ \r
+ form_wrapper: () ->\r
+ @parent.parent.form_wrapper\r
+ \r
+ dock: () ->\r
+ @parent.parent.dock()\r
+ \r
+ dialog: () ->\r
+ @editor().dialog\r
+ \r
+ editor: () ->\r
+ @dock().parent\r
+ \r
+class Editor.EditorModule.DockModule.NewElementLinkedButton extends Tag.A\r
+ \r
+ click: () ->\r
+ @trigger('click')\r
+ return false\r
+ \r
+class Editor.EditorModule.DockModule.NewElementFormWrapper extends Backbone.View\r
+ tagName: 'div'\r
+ \r
+ initialize: (options) ->\r
+ super(options)\r
+ @parent = options.parent\r
+ \r
+ clear: () ->\r
+ this.$el.html('new form')\r
+ this\r
+ \r
+ render: () ->\r
+ this.$el.html(@model.item_name())\r
+ \r
+ select: (model) ->\r
+ @model = model\r
+ @render()\r
+ \r
class Editor.EditorModule.DockModule.ScenarioBay extends Editor.EditorModule.DockModule.BoardBay\r
\r
initialize: (options) ->\r