diff options
author | Nivesh Rajbhandari | 2012-03-12 16:25:28 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-03-12 16:25:28 -0700 |
commit | 5fb358d9e80a364d5f300d60b7a9fe0f773741e7 (patch) | |
tree | 2c4d5292b19c91697dffb542f369ec9dcb340f77 /js/panels/PanelContainer.reel/PanelContainer.js | |
parent | 5f9b67be3b8bdb391d021103c6bcee6be2f6cdf4 (diff) | |
parent | 69d90467865a1384725b2301901be2180c5a841f (diff) | |
download | ninja-5fb358d9e80a364d5f300d60b7a9fe0f773741e7.tar.gz |
Merge branch 'refs/heads/ninja-internal' into ToolFixes
Diffstat (limited to 'js/panels/PanelContainer.reel/PanelContainer.js')
-rwxr-xr-x | js/panels/PanelContainer.reel/PanelContainer.js | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/js/panels/PanelContainer.reel/PanelContainer.js b/js/panels/PanelContainer.reel/PanelContainer.js new file mode 100755 index 00000000..c40bbc21 --- /dev/null +++ b/js/panels/PanelContainer.reel/PanelContainer.js | |||
@@ -0,0 +1,236 @@ | |||
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 | Component = require("montage/ui/component").Component; | ||
12 | |||
13 | exports.PanelContainer = Montage.create(Component, { | ||
14 | |||
15 | panelData: { | ||
16 | value: null | ||
17 | }, | ||
18 | |||
19 | // This will hold the current loaded panels. | ||
20 | panels: { | ||
21 | value: [] | ||
22 | }, | ||
23 | |||
24 | currentPanelState: { | ||
25 | value: {} | ||
26 | }, | ||
27 | |||
28 | templateDidLoad: { | ||
29 | value: function() { | ||
30 | |||
31 | var pLen, storedData; | ||
32 | |||
33 | // Loop through the panels to add to the repetition and get the saved state | ||
34 | pLen = this.panelData.panels.length; | ||
35 | |||
36 | // Get the saved panel state | ||
37 | storedData = this.application.localStorage.getItem("panels"); | ||
38 | |||
39 | for(var i = 0; i < pLen; i++) { | ||
40 | |||
41 | var p = this.panelData.panels[i]; | ||
42 | |||
43 | this['panel_'+i].name = p.name; | ||
44 | this['panel_'+i].height = p.height; | ||
45 | this['panel_'+i].minHeight= p.minHeight; | ||
46 | this['panel_'+i].maxHeight = p.maxHeight; | ||
47 | this['panel_'+i].flexible = p.flexible; | ||
48 | this['panel_'+i].modulePath = p.modulePath; | ||
49 | this['panel_'+i].moduleName = p.moduleName; | ||
50 | this['panel_'+i].disabled = true; | ||
51 | |||
52 | this.currentPanelState[p.name] = {}; | ||
53 | this.currentPanelState.version = "1.0"; | ||
54 | |||
55 | if(storedData && storedData[p.name]) { | ||
56 | this['panel_'+i].collapsed = storedData[p.name].collapsed; | ||
57 | } | ||
58 | |||
59 | this.currentPanelState[p.name].collapsed = this['panel_'+i].collapsed; | ||
60 | |||
61 | // Check if current panel is open when feature is enabled | ||
62 | this.panels.push(this['panel_'+i]); | ||
63 | } | ||
64 | |||
65 | this.application.localStorage.setItem("panels", this.currentPanelState); | ||
66 | |||
67 | |||
68 | this.eventManager.addEventListener( "onOpenDocument", this, false); | ||
69 | this.eventManager.addEventListener( "closeDocument", this, false); | ||
70 | } | ||
71 | }, | ||
72 | |||
73 | prepareForDraw: { | ||
74 | value: function() { | ||
75 | window.addEventListener("resize", this, false); | ||
76 | } | ||
77 | }, | ||
78 | |||
79 | handlePanelResizing: { | ||
80 | value: function(e) { | ||
81 | this._setPanelsSizes(e.target); | ||
82 | } | ||
83 | }, | ||
84 | |||
85 | handleResize: { | ||
86 | value: function(e) { | ||
87 | this._redrawPanels(null, true); | ||
88 | } | ||
89 | }, | ||
90 | |||
91 | handleOnOpenDocument: { | ||
92 | value: function(){ | ||
93 | this.panels.forEach(function(obj) { | ||
94 | obj.disabled = false; | ||
95 | }); | ||
96 | } | ||
97 | }, | ||
98 | |||
99 | handleCloseDocument: { | ||
100 | value: function(){ | ||
101 | if(!this.application.ninja.documentController.activeDocument) { | ||
102 | this.panels.forEach(function(obj) { | ||
103 | obj.disabled = true; | ||
104 | }); | ||
105 | } | ||
106 | } | ||
107 | }, | ||
108 | |||
109 | handleDropped: { | ||
110 | value: function(e) { | ||
111 | var draggedIndex, droppedIndex = 0, len = this.panels.length; | ||
112 | |||
113 | // console.log(e._event.draggedComponent); | ||
114 | for(var i = 0; i < len; i++) { | ||
115 | if(this.panels[i].name === e._event.draggedComponent.name) { | ||
116 | draggedIndex = i; // Actual component being dragged | ||
117 | } | ||
118 | |||
119 | if(this.panels[i].name === e._target.name) { | ||
120 | droppedIndex = i; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | if(draggedIndex !== droppedIndex) { | ||
125 | // switch panels | ||
126 | if (droppedIndex === draggedIndex +1) { | ||
127 | if(this.panels[droppedIndex].element.nextSibling) { | ||
128 | this.panels[droppedIndex].element.parentNode.insertBefore(this.panels[draggedIndex].element, this.panels[droppedIndex].element.nextSibling); | ||
129 | } else { | ||
130 | return this.appendChild(this.panels[draggedIndex].element); | ||
131 | } | ||
132 | } else { | ||
133 | |||
134 | this.panels[droppedIndex].element.parentNode.insertBefore(this.panels[draggedIndex].element, this.panels[droppedIndex].element); | ||
135 | } | ||
136 | var panelRemoved = this.panels.splice(draggedIndex, 1); | ||
137 | this.panels.splice(droppedIndex, 0, panelRemoved[0]); | ||
138 | |||
139 | } | ||
140 | |||
141 | } | ||
142 | }, | ||
143 | |||
144 | _setPanelsSizes: { | ||
145 | value: function(panelActivated) { | ||
146 | var len = this.panels.length, setLocked = true; | ||
147 | |||
148 | for(var i = 0; i < len; i++) { | ||
149 | if(this.panels[i] === panelActivated || panelActivated === null) { | ||
150 | setLocked = false; | ||
151 | } | ||
152 | |||
153 | this.panels[i].locked = setLocked; | ||
154 | this.panels[i].needsDraw = true; | ||
155 | } | ||
156 | } | ||
157 | }, | ||
158 | |||
159 | _redrawPanels: { | ||
160 | value: function(panelActivated, unlockPanels) { | ||
161 | var maxHeight = this.element.offsetHeight, setLocked = true; | ||
162 | var len = this.panels.length; | ||
163 | |||
164 | if(unlockPanels === true) { | ||
165 | setLocked = false; | ||
166 | } | ||
167 | |||
168 | var childrensMinHeights = (len * 26); | ||
169 | if (panelActivated) { | ||
170 | if (!panelActivated.collapsed) { | ||
171 | childrensMinHeights+= panelActivated.minHeight -26; | ||
172 | } | ||
173 | } | ||
174 | |||
175 | for(var i = 0; i < len; i++) { | ||
176 | var obj = this['panel_'+i]; | ||
177 | |||
178 | if(obj === panelActivated) { | ||
179 | setLocked = false; | ||
180 | } else if(obj.collapsed) { | ||
181 | //Collapsed Ignore the rest of the code | ||
182 | } else { | ||
183 | if (setLocked) { | ||
184 | if((maxHeight - childrensMinHeights) - obj.height > 0 ) { | ||
185 | childrensMinHeights += obj.height - 26; | ||
186 | } else { | ||
187 | this.currentPanelState[obj.name].collapsed = obj.collapsed = true; | ||
188 | this.application.localStorage.setItem("panels", this.currentPanelState); | ||
189 | } | ||
190 | } else { | ||
191 | if ((maxHeight - childrensMinHeights) - obj.minHeight > 0 ) { | ||
192 | childrensMinHeights += obj.minHeight - 26; | ||
193 | } else { | ||
194 | this.currentPanelState[obj.name].collapsed = obj.collapsed = true; | ||
195 | this.application.localStorage.setItem("panels", this.currentPanelState); | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | obj.locked = setLocked; | ||
200 | } | ||
201 | } | ||
202 | }, | ||
203 | |||
204 | handleAction: { | ||
205 | value: function(e) { | ||
206 | var unlockPanels = true; | ||
207 | var afterPanel = false; | ||
208 | var panelName = e.target.parentComponent.name; | ||
209 | |||
210 | this.panels.forEach(function(obj) { | ||
211 | if(afterPanel) { | ||
212 | if(obj.flexible && obj.collapsed === false) { | ||
213 | unlockPanels = false; | ||
214 | } | ||
215 | } | ||
216 | if (obj.name === panelName) { | ||