OSDN Git Service

fix: new speechballoon
[pettanr/pettanr.git] / app / assets / javascripts / editor / panel_editor / dock.js.coffee
1 class Editor.PanelEditor.Dock extends Editor.EditorModule.DockBase\r
2   tagName: 'div'\r
3   className: 'dock'\r
4   \r
5   initialize: (options) ->\r
6     super(options)\r
7     @root_bay = new Editor.EditorModule.DockModule.RootBay({\r
8       parent: this, index: 0, name: 'panel'\r
9     })\r
10     @add_tab(\r
11       @root_bay, \r
12       new Editor.EditorModule.DockModule.TabModule.RootBayLabel({\r
13         parent: @root_bay, caption: 'panel'\r
14       }), \r
15       new Editor.EditorModule.DockModule.TabModule.RootBayBody({\r
16         parent: @root_bay\r
17       })\r
18     )\r
19     @element_bay = new Editor.EditorModule.DockModule.ElementBay({\r
20       parent: this, index: 1, name: 'elements'\r
21     })\r
22     @add_tab(\r
23       @element_bay, \r
24       new Editor.EditorModule.DockModule.TabModule.ElementBayLabel({\r
25         parent: @element_bay, caption: 'elements'\r
26       }), \r
27       new Editor.EditorModule.DockModule.TabModule.ElementBayBody({\r
28         parent: @element_bay\r
29       })\r
30     )\r
31     @scenario_bay = new Editor.EditorModule.DockModule.ScenarioBay({\r
32       parent: this, index: 2, name: 'scenario'\r
33     })\r
34     @add_tab(\r
35       @scenario_bay, \r
36       new Editor.EditorModule.DockModule.TabModule.ScenarioBayLabel({\r
37         parent: @scenario_bay, caption: 'scenario'\r
38       }), \r
39       new Editor.EditorModule.DockModule.TabModule.ScenarioBayBody({\r
40         parent: @scenario_bay\r
41       })\r
42     )\r
43     @listenTo(@root_bay.body, 'http_post', @http_post)\r
44     @listenTo(@element_bay, 'add:credit', @add_credit)\r
45     @listenTo(@element_bay, 'pick', @pick)\r
46   \r
47   render: () ->\r
48     this.$el.html('')\r
49     l = _.map @tabs, (tab) ->\r
50       tab.label\r
51     labels = new Tag.Ul({contents: l, class_name: @dom_labels_class()})\r
52     this.$el.append(labels.render().el)\r
53     _.each @tabs, (tab) =>\r
54       this.$el.append(tab.render().el)\r
55     this\r
56   \r
57   init_tabs: () ->\r
58     @element_bay.init_tabs()\r
59     @scenario_bay.init_tabs()\r
60     this.$el.tabs({\r
61       activate: (e, ui) ->\r
62         ui.newPanel.trigger('activate')\r
63     })\r
64   \r
65   editor: () ->\r
66     @parent\r
67   \r
68   dom_id: () ->\r
69     @editor().dom_id() + '-dock'\r
70   \r
71   dom_class: () ->\r
72     @editor().dom_class() + '-dock'\r
73   \r
74   dom_labels_class: () ->\r
75     @dom_class() + '-labels'\r
76   \r
77   http_post: (url, root_form) ->\r
78     @trigger('http_post', url, this)  # send dock\r
79     false\r
80   \r
81   add_credit: (element) ->\r
82     @trigger('add:credit', element)\r
83   \r
84   save_data: () ->\r
85     attrs = @root_bay.save_data()\r
86     _.extend(attrs, @element_bay.save_data())\r
87     attrs\r
88   \r
89   pick: (new_item) ->\r
90     t = @scenario_bay.length()\r
91     z = @element_bay.new_tab.label.z() + 1\r
92     new_item.set({z: z, t: t}, {silent: true})\r
93     @scenario_bay.add_element(new_item)\r
94     @trigger('add:element', new_item)\r
95   \r