--- /dev/null
+class Editor.EditorModule.DockModule.ElementBay extends Editor.EditorModule.DockModule.BoardBay\r
+ \r
+ initialize: (options) ->\r
+ super(options)\r
+ @boards = new Editor.EditorModule.DockModule.ElementBay.Boards({\r
+ parent: this\r
+ })\r
+ @listenTo(@boards, 'sorted', @sorted)\r
+ \r
+ add_element: (element) ->\r
+ index = @tabs.length\r
+ @shift_z()\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({\r
+ parent: tab, \r
+ name: element.item_name()\r
+ }), \r
+ bb\r
+ )\r
+ @boards.add_element_tab(tab)\r
+ @boards.$el.tabs('refresh')\r
+ if element.constructor.has_picture()\r
+ @trigger('add:credit', element)\r
+ \r
+ shift_z: () ->\r
+ new_tab_z = @new_tab.label.z()\r
+ _.each @tabs, (tab) ->\r
+ z = tab.label.z()\r
+ tab.label.$el.attr('data-z', z + 1) if z >= new_tab_z # new tab too\r
+ \r
+ add_new_tab: () ->\r
+ @new_tab = new Editor.EditorModule.DockModule.NewElementBoard({\r
+ parent: this, index: 0, name: 'new'\r
+ })\r
+ bb = new Editor.EditorModule.DockModule.TabModule.NewElementBoardBody({parent: @new_tab})\r
+ @add_tab(\r
+ @new_tab, \r
+ new Editor.EditorModule.DockModule.TabModule.NewElementBoardLabel({\r
+ parent: @new_tab\r
+ }), \r
+ bb\r
+ )\r
+ @listenTo(bb, 'pick', @pick)\r
+ @boards.add_element_tab(@new_tab)\r
+ \r
+ render: () ->\r
+ this.$el.html('')\r
+ @delegateEvents({'activate': 'activate'})\r
+ this.$el.attr('id', @body.dom_id())\r
+ this.$el.append(@boards.render().el)\r
+ _this = this\r
+ @boards.$el.tabs({\r
+ activate: (e, ui) ->\r
+ ui.newPanel.trigger('activate')\r
+ })\r
+ this\r
+ \r
+ init_tabs: () ->\r
+ @add_new_tab()\r
+ list = @root_item().zorderd_elements()\r
+ _.each list, (element) =>\r
+ @add_element(element)\r
+ \r
+ activate: () ->\r
+ _.each @tabs, (tab) ->\r
+ return if not tab.element # without new element tab\r
+ if tab.body.$el.css('display') != 'none'\r
+ tab.body.refresh()\r
+ \r
+ sorted: () ->\r
+ # data-z copy to model\r
+ new_tab_z = @new_tab.label.z()\r
+ _.each @tabs, (tab) ->\r
+ if tab.element # without new_tab\r
+ z = tab.label.z()\r
+ z-- if z > new_tab_z # from 0, 1, new tab, 3... to 1, 2, 3...\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
+ pick: (new_item) ->\r
+ @add_element(new_item)\r
+ @trigger('pick', new_item)\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
+ \r
+ render: () ->\r
+ @body.render()\r
+ \r