diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js')
-rw-r--r-- | js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js | 382 |
1 files changed, 382 insertions, 0 deletions
diff --git a/js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js b/js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js new file mode 100644 index 00000000..57187af1 --- /dev/null +++ b/js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js | |||
@@ -0,0 +1,382 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | /* | ||
8 | Panel Container - A container for other panels | ||
9 | */ | ||
10 | var Montage = require("montage/core/core").Montage; | ||
11 | var Component = require("montage/ui/component").Component; | ||
12 | var PropertiesPanel = require("js/panels/Properties/properties-panel").PropertiesPanel; | ||
13 | var ColorPanel = require("js/panels/Color/ColorPanel").ColorPanel; | ||
14 | var CSSPanel = require("js/panels/CSSPanel/CSSPanel").CSSPanel; | ||
15 | var ComponentsPanel = require("js/panels/Components/ComponentsPanel").ComponentsPanel; | ||
16 | var ProjectPanel = require("js/panels/Project/ProjectPanel").ProjectPanel; | ||
17 | var MaterialsPanel = require("js/panels/Materials/MaterialsPanel").MaterialsPanel; | ||
18 | |||
19 | exports.PanelContainer = Montage.create(Component, { | ||
20 | lastOffset: { | ||
21 | value:null | ||
22 | }, | ||
23 | _collapsedHeight: { | ||
24 | value: 26 | ||
25 | }, | ||
26 | _isFirstAdjustableNonCollapsed: { | ||
27 | value:true | ||
28 | }, | ||
29 | _spaceAvailable: { | ||
30 | value:null | ||
31 | }, | ||
32 | _panelSelected : { | ||
33 | value: null | ||
34 | }, | ||
35 | _isFirstDraw: { | ||
36 | value: false | ||
37 | }, | ||
38 | _panels: { | ||
39 | value: [] | ||
40 | }, | ||
41 | |||
42 | skipPanelIndex: { | ||
43 | value: null | ||
44 | }, | ||
45 | |||
46 | initPanelOrder: { | ||
47 | value: ['PropertiesPanel','ColorPanel','ComponentsPanel','ProjectPanel','CSSPanel','MaterialsPanel'] | ||
48 | }, | ||
49 | |||
50 | panelOrder: { | ||
51 | value: [] | ||
52 | }, | ||
53 | |||
54 | deserializedFromTemplate : { | ||
55 | value: function() { | ||
56 | this.eventManager.addEventListener( "appLoaded", this, false); | ||
57 | |||
58 | } | ||
59 | }, | ||
60 | |||
61 | handleAppLoaded: { | ||
62 | value: function() { | ||
63 | //Panels Loading | ||
64 | this.lastOffset = this.element.offsetHeight; | ||
65 | if( this.application.ninja.settings.getSetting(this.element.id, "panelOrder") != null) { | ||
66 | this.initPanelOrder = this.application.ninja.settings.getSetting(this.element.id, "panelOrder") | ||
67 | } | ||
68 | // if Panels already loaded no need to load again. | ||
69 | for(var i = 0; i < this.initPanelOrder.length; i++) { | ||
70 | this.addPanel(eval(this.initPanelOrder[i])); | ||
71 | this.panelOrder.push(this.initPanelOrder[i]); | ||
72 | this.application.ninja.settings.setSetting(this.element.id, "panelOrder", this.panelOrder); | ||
73 | } | ||
74 | |||
75 | var hideSplitter = true; | ||
76 | |||
77 | var that = this; | ||
78 | this._panels.forEach(function(obj) { | ||
79 | |||
80 | var panelMenuName = obj.panelName.substring(0, obj.panelName.indexOf('/') !== -1 ? obj.panelName.indexOf('/'): obj.panelName.length) + "Panel"; | ||
81 | |||
82 | that.application.ninja.appModel[panelMenuName] = obj.visible; | ||
83 | |||
84 | if (obj.visible) { | ||
85 | hideSplitter = false; | ||
86 | } | ||
87 | }); | ||
88 | |||
89 | if (hideSplitter) { | ||
90 | this.panelSplitter.toggle(); | ||
91 | this.panelSplitter.disabled = true; | ||
92 | } | ||
93 | |||
94 | this.needsDraw = true; | ||
95 | |||
96 | this.addEventListener("change@appModel.PropertiesPanel", this, false); | ||
97 | this.addEventListener("change@appModel.ProjectPanel", this, false); | ||
98 | this.addEventListener("change@appModel.ColorPanel", this, false); | ||
99 | this.addEventListener("change@appModel.ComponentsPanel", this, false); | ||
100 | this.addEventListener("change@appModel.CSSPanel", this, false); | ||
101 | this.addEventListener("change@appModel.MaterialsPanel", this, false); | ||
102 | } | ||
103 | }, | ||
104 | |||
105 | handleEvent: { | ||
106 | value: function(e) { | ||
107 | this.togglePanel(e.propertyName); | ||
108 | } | ||
109 | }, | ||
110 | |||
111 | addPanel: { | ||
112 | value: function(panel) { | ||
113 | if (panel.init) { | ||
114 | panel.init(); | ||
115 | } | ||
116 | this._panels.push(panel); | ||
117 | if (this.panelSplitter.disabled) { | ||
118 | this.panelSplitter.disabled = false; | ||
119 | this.panelSplitter.toggle(); | ||
120 | } | ||
121 | } | ||
122 | }, | ||
123 | handlePanelCollapsed: { | ||
124 | value: function(e) { | ||
125 | |||
126 | for(var i=0; i < this._panels.length; i++) { | ||
127 | if (e._event.detail.panelBase._uuid == this._panels[i]._uuid) { | ||
128 | this.skipPanelIndex = i; | ||
129 | this.handlePanelResized(i, true); | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | }, | ||
134 | |||
135 | handlePanelResizedStart : { | ||
136 | value: function(e) { | ||
137 | for (var i = 0; i < this._panels.length; i++) { | ||
138 | if ( e._event.detail.element.parentNode.uuid == this.repeater.childComponents[i].element.uuid) { | ||
139 | this.handlePanelResized(i); | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | }, | ||
144 | |||
145 | handlePanelResizedEnd : { | ||
146 | value: function(e) { | ||
147 | for (var i = 0; i < this._panels.length; i++) { | ||
148 | if ( e._event.detail.element.parentNode.uuid == this.repeater.childComponents[i].element.uuid) { | ||
149 | this.handlePanelResized(); | ||
150 | } | ||
151 | } | ||
152 | } | ||
153 | }, | ||
154 | |||
155 | handlePanelResizing: { | ||
156 | value:function(e) { | ||
157 | this.resizedRedraw(); | ||
158 | } | ||
159 | }, | ||
160 | |||
161 | canFlex: { | ||
162 | value: function(panel) { | ||
163 | if (panel.isStatic) { | ||
164 | return false; | ||
165 | } | ||
166 | |||
167 | return !(panel.collapsed || panel.forcedCollapse); | ||
168 | |||
169 | } | ||
170 | }, | ||
171 | |||
172 | handlePanelResized: { | ||
173 | value: function(selectedPanelIndex, collapsing) { | ||
174 | minHeights = 0; | ||
175 | needsLocks = true; | ||
176 | |||
177 | if (collapsing) { | ||
178 | if (this._panels.length -1 == selectedPanelIndex) { | ||
179 | needsLocks = false; | ||
180 | } else { | ||
181 | needsLocks = false; | ||
182 | for (var i = 0; i < this._panels.length; i++) { | ||
183 | if ( i > selectedPanelIndex) { | ||
184 | if (this.canFlex(this._panels[i])) { | ||
185 | needsLocks = true; | ||
186 | } | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | for (var i = 0; i < this._panels.length; i++) { | ||
192 | if (this._panels[i].collapsed || this._panels[i].forcedCollapse) { | ||
193 | minHeights += this._collapsedHeight; | ||
194 | } else { | ||
195 | if (i < selectedPanelIndex && needsLocks) { | ||
196 | this._panels[i].isLocked = true; | ||
197 | this.repeater.childComponents[i].needsDraw = true; | ||
198 | minHeights += this.repeater.childComponents[i].element.offsetHeight; | ||
199 | } else { | ||
200 | this._panels[i].isLocked = false; | ||
201 | this.repeater.childComponents[i].needsDraw = true; | ||
202 | minHeights += this._panels[i].minHeight; | ||
203 | } | ||
204 | } | ||
205 | } | ||