1 |
d2a8c3fd
|
Marc NICOLAS
|
Ext.define('sitools.extension.model.OChartModel', {
|
2 |
|
|
extend: 'Ext.selection.DataViewModel',
|
3 |
|
|
|
4 |
|
|
requires: [
|
5 |
|
|
'Ext.util.KeyNav',
|
6 |
|
|
'Ext.util.KeyMap'
|
7 |
|
|
],
|
8 |
|
|
|
9 |
|
|
destroy: function () {
|
10 |
|
|
var me = this;
|
11 |
|
|
if (me.keyMap) {
|
12 |
|
|
me.keyMap.destroy();
|
13 |
|
|
}
|
14 |
|
|
|
15 |
|
|
me.callParent(arguments);
|
16 |
|
|
},
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
refresh: function () {
|
22 |
|
|
var me = this,
|
23 |
|
|
store = me.store,
|
24 |
|
|
rec,
|
25 |
|
|
toBeSelected = [],
|
26 |
|
|
toBeReAdded = [],
|
27 |
|
|
oldSelections = me.getSelection(),
|
28 |
|
|
len = oldSelections.length,
|
29 |
|
|
view = me.view,
|
30 |
|
|
selection,
|
31 |
|
|
change,
|
32 |
|
|
i = 0,
|
33 |
|
|
lastFocused = me.getLastFocused();
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
if (!store) {
|
37 |
|
|
return;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
for (; i < len; i++) {
|
43 |
|
|
selection = oldSelections[i];
|
44 |
|
|
if (view.getNode(selection)) {
|
45 |
|
|
toBeSelected.push(selection);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
else if (!me.pruneRemoved) {
|
50 |
|
|
|
51 |
|
|
rec = store.getById(selection.getId());
|
52 |
|
|
if (rec) {
|
53 |
|
|
toBeSelected.push(rec);
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
else {
|
57 |
|
|
toBeReAdded.push(selection)
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
if (me.mode === 'SINGLE' && toBeReAdded.length) {
|
63 |
|
|
break;
|
64 |
|
|
}
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
if (me.selected.getCount() != (toBeSelected.length + toBeReAdded.length)) {
|
70 |
|
|
change = true;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
me.clearSelections();
|
74 |
|
|
|
75 |
|
|
if (view.getNode(lastFocused)) {
|
76 |
|
|
|
77 |
|
|
me.setLastFocused(lastFocused, true);
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
if (toBeSelected.length) {
|
81 |
|
|
|
82 |
|
|
me.doSelect(toBeSelected, false, true);
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
if (toBeReAdded.length) {
|
87 |
|
|
me.selected.addAll(toBeReAdded);
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
if (!me.lastSelected) {
|
91 |
|
|
me.lastSelected = toBeReAdded[toBeReAdded.length - 1];
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
me.maybeFireSelectionChange(change);
|
96 |
|
|
},
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
deselectAll: function (suppressEvent) {
|
102 |
|
|
var me = this,
|
103 |
|
|
selections = me.getSelection(),
|
104 |
|
|
selIndexes = {},
|
105 |
|
|
store = me.store,
|
106 |
|
|
start = selections.length,
|
107 |
|
|
i, l, rec;
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
for (i = 0, l = selections.length; i < l; i++) {
|
116 |
|
|
rec = selections[i];
|
117 |
|
|
|
118 |
|
|
selIndexes[rec.internalId] = rec.get('index');
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
selections = Ext.Array.sort(selections, function (r1, r2) {
|
124 |
|
|
var idx1 = selIndexes[r1.internalId],
|
125 |
|
|
idx2 = selIndexes[r2.internalId];
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
return idx1 < idx2 ? -1 : 1;
|
129 |
|
|
});
|
130 |
|
|
|
131 |
|
|
if (me.suspendChanges) me.suspendChanges();
|
132 |
|
|
me.doDeselect(selections, suppressEvent);
|
133 |
|
|
if (me.resumeChanges) me.resumeChanges();
|
134 |
|
|
|
135 |
|
|
if (!suppressEvent) {
|
136 |
|
|
me.maybeFireSelectionChange(me.getSelection().length !== start);
|
137 |
|
|
}
|
138 |
|
|
},
|
139 |
|
|
|
140 |
|
|
initKeyNav: function (view) {
|
141 |
|
|
var me = this;
|
142 |
|
|
|
143 |
|
|
if (!view.rendered) {
|
144 |
|
|
view.on({
|
145 |
|
|
render: Ext.Function.bind(me.initKeyNav, me, [view]),
|
146 |
|
|
single: true
|
147 |
|
|
});
|
148 |
|
|
return;
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
view.el.set({
|
152 |
|
|
tabIndex: -1
|
153 |
|
|
});
|
154 |
|
|
|
155 |
|
|
me.keyNav = new Ext.util.KeyNav({
|
156 |
|
|
target: view.el,
|
157 |
|
|
ignoreInputFields: true,
|
158 |
|
|
down: Ext.pass(me.onNavKey, ['down'], me),
|
159 |
|
|
right: Ext.pass(me.onNavKey, ['right'], me),
|
160 |
|
|
left: Ext.pass(me.onNavKey, ['left'], me),
|
161 |
|
|
up: Ext.pass(me.onNavKey, ['up'], me),
|
162 |
|
|
scope: me
|
163 |
|
|
});
|
164 |
|
|
|
165 |
|
|
me.keyMap = Ext.create('Ext.util.KeyMap', {
|
166 |
|
|
target: view.el,
|
167 |
|
|
binding: [
|
168 |
|
|
{
|
169 |
|
|
key: Ext.EventObject.NUM_PLUS,
|
170 |
|
|
ctrl: false,
|
171 |
|
|
shift: false,
|
172 |
|
|
fn: me.onKeyExpand,
|
173 |
|
|
scope: me
|
174 |
|
|
}, {
|
175 |
|
|
key: Ext.EventObject.NUM_MINUS,
|
176 |
|
|
ctrl: false,
|
177 |
|
|
shift: false,
|
178 |
|
|
fn: me.onKeyCollapse,
|
179 |
|
|
scope: me
|
180 |
|
|
}
|
181 |
|
|
]
|
182 |
|
|
});
|
183 |
|
|
},
|
184 |
|
|
|
185 |
|
|
onNavKey: function (direction) {
|
186 |
|
|
var me = this,
|
187 |
|
|
view = me.view,
|
188 |
|
|
store = view.store,
|
189 |
|
|
selected = me.getLastSelected(),
|
190 |
|
|
root = view.getRootNode(),
|
191 |
|
|
record, node;
|
192 |
|
|
|
193 |
|
|
if (!selected) {
|
194 |
|
|
if (!root) return;
|
195 |
|
|
|
196 |
|
|
selected = root;
|
197 |
|
|
if (!view.rootVisible) {
|
198 |
|
|
selected = root.firstChild;
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
if (selected) {
|
202 |
|
|
me.select(selected);
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
return;
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
direction = direction || 'right';
|
209 |
|
|
switch (direction) {
|
210 |
|
|
case 'left':
|
211 |
|
|
record = selected.previousSibling;
|
212 |
|
|
break;
|
213 |
|
|
case 'right':
|
214 |
|
|
record = selected.nextSibling;
|
215 |
|
|
break;
|
216 |
|
|
case 'up':
|
217 |
|
|
if (selected == root) {
|
218 |
|
|
record = null;
|
219 |
|
|
break;
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
record = selected.parentNode;
|
223 |
|
|
|
224 |
|
|
if (!view.rootVisible && record == root) {
|
225 |
|
|
record = null;
|
226 |
|
|
}
|
227 |
|
|
break;
|
228 |
|
|
case 'down':
|
229 |
|
|
record = selected.firstChild;
|
230 |
|
|
if (!record && !selected.isLeaf()) {
|
231 |
|
|
record = selected;
|
232 |
|
|
}
|
233 |
|
|
break;
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
if (!record) return;
|
237 |
|
|
|
238 |
|
|
if (direction == 'down' && !selected.isExpanded()) {
|
239 |
|
|
selected.expand(false, function (rec) {
|
240 |
|
|
me.select(record);
|
241 |
|
|
view.hideTools();
|
242 |
|
|
if (Ext.versions.extjs.isLessThan('4.2.0')) {
|
243 |
|
|
view.focusNode(record);
|
244 |
|
|
}
|
245 |
|
|
}, me);
|
246 |
|
|
}
|
247 |
|
|
else {
|
248 |
|
|
me.select(record);
|
249 |
|
|
view.hideTools();
|
250 |
|
|
if (Ext.versions.extjs.isLessThan('4.2.0')) {
|
251 |
|
|
view.focusNode(record);
|
252 |
|
|
}
|
253 |
|
|
}
|
254 |
|
|
},
|
255 |
|
|
|
256 |
|
|
onKeyExpand: function () {
|
257 |
|
|
var me = this,
|
258 |
|
|
view = me.view,
|
259 |
|
|
selected = me.getSelection(),
|
260 |
|
|
len = selected.length,
|
261 |
|
|
i;
|
262 |
|
|
|
263 |
|
|
for (i = 0; i < len; ++i) {
|
264 |
|
|
selected[i].expand();
|
265 |
|
|
}
|
266 |
|
|
},
|
267 |
|
|
|
268 |
|
|
onKeyCollapse: function () {
|
269 |
|
|
var me = this,
|
270 |
|
|
view = me.view,
|
271 |
|
|
selected = me.getSelection(),
|
272 |
|
|
len = selected.length,
|
273 |
|
|
i;
|
274 |
|
|
|
275 |
|
|
for (i = 0; i < len; ++i) {
|
276 |
|
|
selected[i].collapse();
|
277 |
|
|
}
|
278 |
|
|
},
|
279 |
|
|
|
280 |
|
|
onContainerClick: function () {
|
281 |
|
|
if (!this.view.dragging && this.deselectOnContainerClick) {
|
282 |
|
|
this.deselectAll();
|
283 |
|
|
}
|
284 |
|
|
}
|
285 |
|
|
});
|