1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
</copyright> */
/*
Panel Container - A container for other panels
*/
var Montage = require("montage/core/core").Montage,
Component = require("montage/ui/component").Component;
exports.PanelContainer = Montage.create(Component, {
panelData: {
value: null
},
// This will hold the current loaded panels.
panels: {
value: []
},
currentPanelState: {
value: {}
},
templateDidLoad: {
value: function() {
var pLen, storedData;
// Loop through the panels to add to the repetition and get the saved state
pLen = this.panelData.panels.length;
// Get the saved panel state
storedData = this.application.localStorage.getItem("panels");
for(var i = 0; i < pLen; i++) {
var p = this.panelData.panels[i];
this['panel_'+i].name = p.name;
this['panel_'+i].height = p.height;
this['panel_'+i].minHeight= p.minHeight;
this['panel_'+i].maxHeight = p.maxHeight;
this['panel_'+i].flexible = p.flexible;
this['panel_'+i].modulePath = p.modulePath;
this['panel_'+i].moduleName = p.moduleName;
this.currentPanelState[p.name] = {};
this.currentPanelState.version = "1.0";
if(storedData && storedData[p.name]) {
this['panel_'+i].collapsed = storedData[p.name].collapsed;
}
this.currentPanelState[p.name].collapsed = this['panel_'+i].collapsed;
// Check if current panel is open when feature is enabled
this.panels.push(p);
}
this.application.localStorage.setItem("panels", this.currentPanelState);
}
},
prepareForDraw: {
value: function() {
window.addEventListener("resize", this, false);
}
},
handlePanelResizing: {
value: function(e) {
this._setPanelsSizes(e.target);
}
},
handleResize: {
value: function(e) {
this._setPanelsSizes(null);
}
},
handleDropped: {
value: function(e) {
var draggedIndex, droppedIndex = 0;
for(var i = 0; i< this.repeater.childComponents.length; i++ ) {
if (this.repeater.childComponents[i] === e._event.draggedComponent) {
draggedIndex = i;
}
if (this.repeater.childComponents[i] === e._event.droppedComponent) {
droppedIndex = i;
}
}
var panelRemoved = this.panelController.content.splice(draggedIndex,1);
this.panelController.content.splice(droppedIndex,0, panelRemoved[0]);
//console.log(draggedIndex, droppedIndex);
this._setPanelsSizes(null);
}
},
_setPanelsSizes: {
value: function(panelActivated) {
var len = this.panels.length, setLocked = true;
for(var i = 0; i < len; i++) {
if(this['panel_'+i] === panelActivated || panelActivated === null) {
setLocked = false;
}
this['panel_'+i].locked = setLocked;
this['panel_'+i].needsDraw = true;
}
}
},
_redrawPanels: {
value: function(panelActivated, unlockPanels) {
var maxHeight = this.element.offsetHeight, setLocked = true;
var len = this.panels.length;
if(unlockPanels === true) {
setLocked = false;
}
var childrensMinHeights = ((len - 1) * 26) + panelActivated.minHeight;
for(var i = 0; i < len; i++) {
var obj = this['panel_'+i];
if(obj === panelActivated) {
setLocked = false;
} else if(obj.collapsed) {
//Collapsed Ignore the rest of the code
} else {
if (setLocked) {
if((maxHeight - childrensMinHeights) - obj.height > 0 ) {
childrensMinHeights += obj.height - 26;
} else {
this.currentPanelState[obj.name].collapsed = obj.collapsed = true;
this.application.localStorage.setItem("panels", this.currentPanelState);
}
} else {
if ((maxHeight - childrensMinHeights) - obj.minHeight > 0 ) {
childrensMinHeights += obj.minHeight - 26;
} else {
this.currentPanelState[obj.name].collapsed = obj.collapsed = true;
this.application.localStorage.setItem("panels", this.currentPanelState);
}
}
}
obj.locked = setLocked;
}
}
},
handleAction: {
value: function(e) {
var unlockPanels = true;
var afterPanel = false;
var panelName = e.target.parentComponent.name;
switch(e.target.identifier) {
case "btnCollapse":
this.currentPanelState[e.target.parentComponent.name].collapsed = e.target.parentComponent.collapsed;
this.application.localStorage.setItem("panels", this.currentPanelState);
this._setPanelsSizes(e.target.parentComponent);
this._redrawPanels(e.target.parentComponent, unlockPanels);
break;
case "btnClose":
this.panelController.content.forEach(function(obj) {
if(afterPanel) {
if(obj.flexible) {
unlockPanels = false;
}
}
if (obj.name === panelName) {
afterPanel = true;
this.panelController.removeObjects(obj);
}
});
this._redrawPanels(e.target.parentComponent, unlockPanels);
break;
}
}
}
});
|