OSDN Git Service

fix: cache
[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(@root_bay.body, 'save:success', @post_success)\r
45     @listenTo(@root_bay.body, 'save:fail', @post_fail)\r
46     @listenTo(@element_bay, 'add:credit', @add_credit)\r
47     @listenTo(@element_bay, 'pick', @pick)\r
48   \r
49   render: () ->\r
50     this.$el.html('')\r
51     l = _.map @tabs, (tab) ->\r
52       tab.label\r
53     labels = new Tag.Ul({contents: l, class_name: @dom_labels_class()})\r
54     this.$el.append(labels.render().el)\r
55     _.each @tabs, (tab) =>\r
56       this.$el.append(tab.render().el)\r
57     this\r
58   \r
59   init_tabs: () ->\r
60     @element_bay.init_tabs()\r
61     @scenario_bay.init_tabs()\r
62     this.$el.tabs({\r
63       activate: (e, ui) ->\r
64         ui.newPanel.trigger('activate')\r
65     })\r
66   \r
67   editor: () ->\r
68     @parent\r
69   \r
70   dom_id: () ->\r
71     @editor().dom_id() + '-dock'\r
72   \r
73   dom_class: () ->\r
74     @editor().dom_class() + '-dock'\r
75   \r
76   dom_labels_class: () ->\r
77     @dom_class() + '-labels'\r
78   \r
79   http_post: (url, root_form) ->\r
80     @trigger('http_post', url, this)  # send dock\r
81     false\r
82   \r
83   post_success: (model, response) ->\r
84     @trigger('save:success', model, response)\r
85   \r
86   post_fail: (model, response) ->\r
87     @trigger('save:fail', response)\r
88   \r
89   add_credit: (element) ->\r
90     @trigger('add:credit', element)\r
91   \r
92   save: () ->\r
93     # merge panel and elements\r
94     attrs = @root_bay.save_data()\r
95     _.extend(attrs, @element_bay.save_data())\r
96     # save json data by panel form\r
97     @root_bay.body.form.save(attrs)\r
98   \r
99   pick: (new_item) ->\r
100     t = @scenario_bay.length()\r
101     z = @element_bay.new_tab.label.z() + 1\r
102     new_item.set({z: z, t: t}, {silent: true})\r
103     @scenario_bay.add_element(new_item)\r
104     @trigger('add:element', new_item)\r
105   \r
106   quit: () ->\r
107     @root_bay.body.form.quit()\r
108   \r