class Editor.EditorModule.DockModule.ScenarioBay extends Editor.EditorModule.DockModule.SimpleBay initialize: (options) -> super(options) render: () -> @body.render() add_element: (element) -> @body.add_element(element) remove_element: (element) -> @body.remove_element(element) init_tabs: () -> list = @root_item().scenario_elements() _.each list, (element) => @add_element(element) pick: (new_item) -> t = @length() new_item.set({t: t}, {silent: true}) @add_element(new_item) save_data: () -> @body.save_data() length: () -> @body.length() 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) @elements = new Editor.EditorModule.DockModule.ScenarioBay.Elements({ parent: this, }) @listenTo(@elements, 'sorted', @sorted) add_element: (element) -> @elements.add_element(element) remove_element: (element) -> @elements.remove_element(element) @sorted() # recalc t render: () -> super() this.$el.append(@elements.render().el) @delegateEvents({'activate': 'activate'}) this activate: () -> @elements.refresh() sorted: () -> # data-t copy to model _.each @elements.element_lis, (element_li) => t = parseInt(element_li.$el.attr('data-t')) element_li.element.set({ t: t }, {silent: true}) element_li.element.trigger('sort') panel_body: () -> @dock().editor().body length: () -> @elements.element_lis.length save_data: () -> attrs = {} _.each @elements.element_lis, (element_li) -> form = element_li.body.form name = form.item.table_name() + '_attributes' attrs[name] ||= [] attrs[name].push(form.save_data()) attrs