]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - src/Toolkit.js
bump version to 2.5-4
[proxmox-widget-toolkit.git] / src / Toolkit.js
CommitLineData
bb64de6e
DM
1// ExtJS related things
2
3 // do not send '_dc' parameter
4Ext.Ajax.disableCaching = false;
5
30076ed6
TL
6// FIXME: HACK! Makes scrolling in number spinner work again. fixed in ExtJS >= 6.1
7if (Ext.isFirefox) {
8 Ext.$eventNameMap.DOMMouseScroll = 'DOMMouseScroll';
9}
10
bb64de6e
DM
11// custom Vtypes
12Ext.apply(Ext.form.field.VTypes, {
01031528 13 IPAddress: function(v) {
bb64de6e
DM
14 return Proxmox.Utils.IP4_match.test(v);
15 },
01031528 16 IPAddressText: gettext('Example') + ': 192.168.1.1',
05a977a2 17 IPAddressMask: /[\d.]/i,
bb64de6e 18
01031528 19 IPCIDRAddress: function(v) {
05a977a2 20 let result = Proxmox.Utils.IP4_cidr_match.exec(v);
bb64de6e
DM
21 // limits according to JSON Schema see
22 // pve-common/src/PVE/JSONSchema.pm
01031528 23 return result !== null && result[1] >= 8 && result[1] <= 32;
bb64de6e 24 },
05a977a2
TL
25 IPCIDRAddressText: gettext('Example') + ': 192.168.1.1/24<br>' + gettext('Valid CIDR Range') + ': 8-32',
26 IPCIDRAddressMask: /[\d./]/i,
bb64de6e 27
01031528 28 IP6Address: function(v) {
bb64de6e
DM
29 return Proxmox.Utils.IP6_match.test(v);
30 },
01031528 31 IP6AddressText: gettext('Example') + ': 2001:DB8::42',
bb64de6e
DM
32 IP6AddressMask: /[A-Fa-f0-9:]/,
33
01031528 34 IP6CIDRAddress: function(v) {
05a977a2 35 let result = Proxmox.Utils.IP6_cidr_match.exec(v);
bb64de6e
DM
36 // limits according to JSON Schema see
37 // pve-common/src/PVE/JSONSchema.pm
01031528 38 return result !== null && result[1] >= 8 && result[1] <= 128;
bb64de6e 39 },
05a977a2
TL
40 IP6CIDRAddressText: gettext('Example') + ': 2001:DB8::42/64<br>' + gettext('Valid CIDR Range') + ': 8-128',
41 IP6CIDRAddressMask: /[A-Fa-f0-9:/]/,
bb64de6e 42
01031528 43 IP6PrefixLength: function(v) {
bb64de6e
DM
44 return v >= 0 && v <= 128;
45 },
01031528
TL
46 IP6PrefixLengthText: gettext('Example') + ': X, where 0 <= X <= 128',
47 IP6PrefixLengthMask: /[0-9]/,
bb64de6e 48
01031528 49 IP64Address: function(v) {
bb64de6e
DM
50 return Proxmox.Utils.IP64_match.test(v);
51 },
01031528 52 IP64AddressText: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
05a977a2 53 IP64AddressMask: /[A-Fa-f0-9.:]/,
bb64de6e 54
577b6c75 55 IP64CIDRAddress: function(v) {
05a977a2 56 let result = Proxmox.Utils.IP64_cidr_match.exec(v);
577b6c75
ML
57 if (result === null) {
58 return false;
59 }
60 if (result[1] !== undefined) {
61 return result[1] >= 8 && result[1] <= 128;
62 } else if (result[2] !== undefined) {
63 return result[2] >= 8 && result[2] <= 32;
64 } else {
65 return false;
66 }
67 },
68 IP64CIDRAddressText: gettext('Example') + ': 192.168.1.1/24 2001:DB8::42/64',
05a977a2 69 IP64CIDRAddressMask: /[A-Fa-f0-9.:/]/,
577b6c75 70
bb64de6e
DM
71 MacAddress: function(v) {
72 return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v);
73 },
74 MacAddressMask: /[a-fA-F0-9:]/,
75 MacAddressText: gettext('Example') + ': 01:23:45:67:89:ab',
76
01031528 77 MacPrefix: function(v) {
add18fad 78 return (/^[a-f0-9][02468ace](?::[a-f0-9]{2}){0,2}:?$/i).test(v);
8f449655
TL
79 },
80 MacPrefixMask: /[a-fA-F0-9:]/,
ffe26505 81 MacPrefixText: gettext('Example') + ': 02:8f - ' + gettext('only unicast addresses are allowed'),
8f449655 82
bb64de6e
DM
83 BridgeName: function(v) {
84 return (/^vmbr\d{1,4}$/).test(v);
85 },
8aefd47c
AD
86 VlanName: function(v) {
87 if (Proxmox.Utils.VlanInterface_match.test(v)) {
88 return true;
89 } else if (Proxmox.Utils.Vlan_match.test(v)) {
90 return true;
91 }
92 return true;
93 },
bb64de6e
DM
94 BridgeNameText: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
95
96 BondName: function(v) {
97 return (/^bond\d{1,4}$/).test(v);
98 },
99 BondNameText: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
100
101 InterfaceName: function(v) {
102 return (/^[a-z][a-z0-9_]{1,20}$/).test(v);
103 },
05a977a2
TL
104 InterfaceNameText: gettext("Allowed characters") + ": 'a-z', '0-9', '_'<br />" +
105 gettext("Minimum characters") + ": 2<br />" +
106 gettext("Maximum characters") + ": 21<br />" +
bb64de6e
DM
107 gettext("Must start with") + ": 'a-z'",
108
01031528 109 StorageId: function(v) {
05a977a2 110 return (/^[a-z][a-z0-9\-_.]*[a-z0-9]$/i).test(v);
bb64de6e 111 },
05a977a2
TL
112 StorageIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'<br />" +
113 gettext("Minimum characters") + ": 2<br />" +
bb64de6e
DM
114 gettext("Must start with") + ": 'A-Z', 'a-z'<br />" +
115 gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />",
116
01031528 117 ConfigId: function(v) {
05a977a2 118 return (/^[a-z][a-z0-9_]+$/i).test(v);
bb64de6e 119 },
05a977a2
TL
120 ConfigIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'<br />" +
121 gettext("Minimum characters") + ": 2<br />" +
bb64de6e
DM
122 gettext("Must start with") + ": " + gettext("letter"),
123
01031528 124 HttpProxy: function(v) {
bb64de6e
DM
125 return (/^http:\/\/.*$/).test(v);
126 },
127 HttpProxyText: gettext('Example') + ": http://username:password&#64;host:port/",
128
129 DnsName: function(v) {
130 return Proxmox.Utils.DnsName_match.test(v);
131 },
132 DnsNameText: gettext('This is not a valid DNS name'),
133
134 // workaround for https://www.sencha.com/forum/showthread.php?302150
135 proxmoxMail: function(v) {
05a977a2 136 return (/^(\w+)([-+.][\w]+)*@(\w[-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v);
bb64de6e
DM
137 },
138 proxmoxMailText: gettext('Example') + ": user@example.com",
139
ba916e58
DC
140 DnsOrIp: function(v) {
141 if (!Proxmox.Utils.DnsName_match.test(v) &&
694a76f6 142 !Proxmox.Utils.IP64_match.test(v)) {
ba916e58
DC
143 return false;
144 }
145
146 return true;
147 },
694a76f6 148 DnsOrIpText: gettext('Not a valid DNS name or IP address.'),
ba916e58 149
5252b7f1
DC
150 HostPort: function(v) {
151 return Proxmox.Utils.HostPort_match.test(v) ||
152 Proxmox.Utils.HostPortBrackets_match.test(v) ||
153 Proxmox.Utils.IP6_dotnotation_match.test(v);
154 },
a9bea104 155 HostPortText: gettext('Host/IP address or optional port is invalid'),
5252b7f1 156
bb64de6e 157 HostList: function(v) {
05a977a2
TL
158 let list = v.split(/[ ,;]+/);
159 let i;
bb64de6e 160 for (i = 0; i < list.length; i++) {
05a977a2 161 if (list[i] === '') {
bb64de6e
DM
162 continue;
163 }
164
165 if (!Proxmox.Utils.HostPort_match.test(list[i]) &&
166 !Proxmox.Utils.HostPortBrackets_match.test(list[i]) &&
167 !Proxmox.Utils.IP6_dotnotation_match.test(list[i])) {
168 return false;
169 }
170 }
171
172 return true;
173 },
36704a2f
DM
174 HostListText: gettext('Not a valid list of hosts'),
175
176 password: function(val, field) {
177 if (field.initialPassField) {
05a977a2
TL
178 let pwd = field.up('form').down(`[name=${field.initialPassField}]`);
179 return val === pwd.getValue();
36704a2f
DM
180 }
181 return true;
182 },
183
01031528 184 passwordText: gettext('Passwords do not match'),
dcd5a0c6
SI
185
186 email: function(value) {
df096ae3 187 let emailre = /^[\w+~-]+(\.[\w+~-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/;
dcd5a0c6
SI
188 return emailre.test(value);
189 },
bb64de6e
DM
190});
191
aea77b2c
DC
192// Firefox 52+ Touchscreen bug
193// see https://www.sencha.com/forum/showthread.php?336762-Examples-don-t-work-in-Firefox-52-touchscreen/page2
194// and https://bugzilla.proxmox.com/show_bug.cgi?id=1223
195Ext.define('EXTJS_23846.Element', {
01031528 196 override: 'Ext.dom.Element',
aea77b2c 197}, function(Element) {
05a977a2 198 let supports = Ext.supports,
aea77b2c
DC
199 proto = Element.prototype,
200 eventMap = proto.eventMap,
201 additiveEvents = proto.additiveEvents;
202
203 if (Ext.os.is.Desktop && supports.TouchEvents && !supports.PointerEvents) {
204 eventMap.touchstart = 'mousedown';
205 eventMap.touchmove = 'mousemove';
206 eventMap.touchend = 'mouseup';
207 eventMap.touchcancel = 'mouseup';
208
209 additiveEvents.mousedown = 'mousedown';
210 additiveEvents.mousemove = 'mousemove';
211 additiveEvents.mouseup = 'mouseup';
212 additiveEvents.touchstart = 'touchstart';
213 additiveEvents.touchmove = 'touchmove';
214 additiveEvents.touchend = 'touchend';
215 additiveEvents.touchcancel = 'touchcancel';
216
217 additiveEvents.pointerdown = 'mousedown';
218 additiveEvents.pointermove = 'mousemove';
219 additiveEvents.pointerup = 'mouseup';
220 additiveEvents.pointercancel = 'mouseup';
221 }
222});
223
224Ext.define('EXTJS_23846.Gesture', {
01031528 225 override: 'Ext.event.publisher.Gesture',
aea77b2c 226}, function(Gesture) {
05a977a2 227 let gestures = Gesture.instance;
aea77b2c
DC
228
229 if (Ext.supports.TouchEvents && !Ext.isWebKit && Ext.os.is.Desktop) {
05a977a2
TL
230 gestures.handledDomEvents.push('mousedown', 'mousemove', 'mouseup');
231 gestures.registerEvents();
aea77b2c
DC
232 }
233});
234
acfbf255
DC
235Ext.define('EXTJS_18900.Pie', {
236 override: 'Ext.chart.series.Pie',
237
238 // from 6.0.2
01031528 239 betweenAngle: function(x, a, b) {
05a977a2 240 let pp = Math.PI * 2,
acfbf255
DC
241 offset = this.rotationOffset;
242
243 if (a === b) {
244 return false;
245 }
246
247 if (!this.getClockwise()) {
248 x *= -1;
249 a *= -1;
250 b *= -1;
251 a -= offset;
252 b -= offset;
253 } else {
254 a += offset;
255 b += offset;
256 }
257
258 x -= a;
259 b -= a;
260
261 // Normalize, so that both x and b are in the [0,360) interval.
262 x %= pp;
263 b %= pp;
264 x += pp;
265 b += pp;
266 x %= pp;
267 b %= pp;
268
269 // Because 360 * n angles will be normalized to 0,
270 // we need to treat b === 0 as a special case.
271 return x < b || b === 0;
272 },
273});
274
3c158249
TL
275// we always want the number in x.y format and never in, e.g., x,y
276Ext.define('PVE.form.field.Number', {
277 override: 'Ext.form.field.Number',
01031528 278 submitLocaleSeparator: false,
3c158249
TL
279});
280
bb64de6e
DM
281// ExtJs 5-6 has an issue with caching
282// see https://www.sencha.com/forum/showthread.php?308989
283Ext.define('Proxmox.UnderlayPool', {
284 override: 'Ext.dom.UnderlayPool',
285
01031528 286 checkOut: function() {
05a977a2 287 let cache = this.cache,
bb64de6e
DM
288 len = cache.length,
289 el;
290
291 // do cleanup because some of the objects might have been destroyed
292 while (len--) {
293 if (cache[len].destroyed) {
294 cache.splice(len, 1);
295 }
296 }
297 // end do cleanup
298
299 el = cache.shift();
300
301 if (!el) {
302 el = Ext.Element.create(this.elementConfig);
303 el.setVisibilityMode(2);
304 //<debug>
305 // tell the spec runner to ignore this element when checking if the dom is clean
306 el.dom.setAttribute('data-sticky', true);
307 //</debug>
308 }
309
310 return el;
01031528 311 },
bb64de6e
DM
312});
313
a2d8b9a9
DC
314// 'Enter' in Textareas and aria multiline fields should not activate the
315// defaultbutton, fixed in extjs 6.0.2
316Ext.define('PVE.panel.Panel', {
317 override: 'Ext.panel.Panel',
318
319 fireDefaultButton: function(e) {
320 if (e.target.getAttribute('aria-multiline') === 'true' ||
321 e.target.tagName === "TEXTAREA") {
322 return true;
323 }
324 return this.callParent(arguments);
01031528 325 },
a2d8b9a9
DC
326});
327
bb64de6e
DM
328// if the order of the values are not the same in originalValue and value
329// extjs will not overwrite value, but marks the field dirty and thus
330// the reset button will be enabled (but clicking it changes nothing)
331// so if the arrays are not the same after resetting, we
332// clear and set it
333Ext.define('Proxmox.form.ComboBox', {
334 override: 'Ext.form.field.ComboBox',
335
336 reset: function() {
337 // copied from combobox
05a977a2 338 let me = this;
bb64de6e 339 me.callParent();
bb64de6e
DM
340
341 // clear and set when not the same
05a977a2
TL
342 let value = me.getValue();
343 if (Ext.isArray(me.originalValue) && Ext.isArray(value) &&
344 !Ext.Array.equals(value, me.originalValue)) {
bb64de6e
DM
345 me.clearValue();
346 me.setValue(me.originalValue);
347 }
50032132
DC
348 },
349
350 // we also want to open the trigger on editable comboboxes by default
351 initComponent: function() {
352 let me = this;
353 me.callParent();
354
355 if (me.editable) {
356 // The trigger.picker causes first a focus event on the field then
357 // toggles the selection picker. Thus skip expanding in this case,
358 // else our focus listener expands and the picker.trigger then
359 // collapses it directly afterwards.
360 Ext.override(me.triggers.picker, {
361 onMouseDown: function(e) {
362 // copied "should we focus" check from Ext.form.trigger.Trigger
363 if (e.pointerType !== 'touch' && !this.field.owns(Ext.Element.getActiveElement())) {
364 me.skip_expand_on_focus = true;
365 }
366 this.callParent(arguments);
01031528 367 },
50032132
DC
368 });
369
370 me.on("focus", function(combobox) {
371 if (!combobox.isExpanded && !combobox.skip_expand_on_focus) {
372 combobox.expand();
373 }
374 combobox.skip_expand_on_focus = false;
375 });
376 }
377 },
bb64de6e
DM
378});
379
47d1c80c
TL
380// when refreshing a grid/tree view, restoring the focus moves the view back to
381// the previously focused item. Save scroll position before refocusing.
382Ext.define(null, {
383 override: 'Ext.view.Table',
384
385 jumpToFocus: false,
386
387 saveFocusState: function() {
05a977a2
TL
388 let me = this,
389 store = me.dataSource,
390 actionableMode = me.actionableMode,
391 navModel = me.getNavigationModel(),
392 focusPosition = actionableMode ? me.actionPosition : navModel.getPosition(true),
393 refocusRow, refocusCol;
394
395 if (focusPosition) {
396 // Separate this from the instance that the nav model is using.
397 focusPosition = focusPosition.clone();
398
399 // Exit actionable mode.
400 // We must inform any Actionables that they must relinquish control.
401 // Tabbability must be reset.
402 if (actionableMode) {
403 me.ownerGrid.setActionableMode(false);
404 }
47d1c80c 405
05a977a2
TL
406 // Blur the focused descendant, but do not trigger focusLeave.
407 me.el.dom.focus();
408
409 // Exiting actionable mode navigates to the owning cell, so in either focus mode we must
410 // clear the navigation position
411 navModel.setPosition();
412
413 // The following function will attempt to refocus back in the same mode to the same cell
414 // as it was at before based upon the previous record (if it's still inthe store), or the row index.
415 return function() {
416 // If we still have data, attempt to refocus in the same mode.
417 if (store.getCount()) {
418 // Adjust expectations of where we are able to refocus according to what kind of destruction
419 // might have been wrought on this view's DOM during focus save.
420 refocusRow = Math.min(focusPosition.rowIdx, me.all.getCount() - 1);
421 refocusCol = Math.min(focusPosition.colIdx,
422 me.getVisibleColumnManager().getColumns().length - 1);
423 refocusRow = store.contains(focusPosition.record) ? focusPosition.record : refocusRow;
424 focusPosition = new Ext.grid.CellContext(me).setPosition(refocusRow, refocusCol);
425
426 if (actionableMode) {
427 me.ownerGrid.setActionableMode(true, focusPosition);
428 } else {
429 me.cellFocused = true;
47d1c80c
TL
430
431 // we sometimes want to scroll back to where we were
05a977a2
TL
432 let x = me.getScrollX();
433 let y = me.getScrollY();
47d1c80c 434
05a977a2
TL
435 // Pass "preventNavigation" as true so that that does not cause selection.
436 navModel.setPosition(focusPosition, null, null, null, true);
47d1c80c
TL
437
438 if (!me.jumpToFocus) {
01031528 439 me.scrollTo(x, y);
47d1c80c 440 }
05a977a2
TL
441 }
442 } else { // No rows - focus associated column header
443 focusPosition.column.focus();
444 }
445 };
446 }
447 return Ext.emptyFn;
01031528 448 },
47d1c80c
TL
449});
450
bb64de6e
DM
451// should be fixed with ExtJS 6.0.2, see:
452// https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll
453Ext.define('Proxmox.Datepicker', {
454 override: 'Ext.picker.Date',
01031528 455 hideMode: 'visibility',
bb64de6e
DM
456});
457
a55813d6
DM
458// ExtJS 6.0.1 has no setSubmitValue() (although you find it in the docs).
459// Note: this.submitValue is a boolean flag, whereas getSubmitValue() returns
460// data to be submitted.
1d9804a9
DM
461Ext.define('Proxmox.form.field.Text', {
462 override: 'Ext.form.field.Text',
463
464 setSubmitValue: function(v) {
465 this.submitValue = v;
466 },
1d9804a9
DM
467});
468
1fb41f2e
TL
469// this should be fixed with ExtJS 6.0.2
470// make mousescrolling work in firefox in the containers overflowhandler
471Ext.define(null, {
472 override: 'Ext.layout.container.boxOverflow.Scroller',
473
474 createWheelListener: function() {
05a977a2 475 let me = this;
1fb41f2e 476 if (Ext.isFirefox) {
01031528 477 me.wheelListener = me.layout.innerCt.on('wheel', me.onMouseWheelFirefox, me, { destroyable: true });
1fb41f2e 478 } else {
01031528 479 me.wheelListener = me.layout.innerCt.on('mousewheel', me.onMouseWheel, me, { destroyable: true });
1fb41f2e
TL
480 }
481 },
482
483 // special wheel handler for firefox. differs from the default onMouseWheel
484 // handler by using deltaY instead of wheelDeltaY and no normalizing,
485 // because it is already
486 onMouseWheelFirefox: function(e) {
487 e.stopEvent();
05a977a2 488 let delta = e.browserEvent.deltaY || 0;
1fb41f2e 489 this.scrollBy(delta * this.wheelIncrement, false);
01031528 490 },
1fb41f2e
TL
491
492});
493
312310e0
DC
494// add '@' to the valid id
495Ext.define('Proxmox.validIdReOverride', {
496 override: 'Ext.Component',
05a977a2 497 validIdRe: /^[a-z_][a-z0-9\-_@]*$/i,
312310e0
DC
498});
499
98d894d8
DC
500Ext.define('Proxmox.selection.CheckboxModel', {
501 override: 'Ext.selection.CheckboxModel',
502
1f628e9c 503 // [P] use whole checkbox cell to multiselect, not only the checkbox
98d894d8 504 checkSelector: '.x-grid-cell-row-checker',
1f628e9c 505
ea2b3fd7
TL
506 // TODO: remove all optimizations below to an override for parent 'Ext.selection.Model' ??
507
1f628e9c
TL
508 // [ P: optimized to remove all records at once as single remove is O(n^3) slow ]
509 // records can be an index, a record or an array of records
510 doDeselect: function(records, suppressEvent) {
511 var me = this,
512 selected = me.selected,
513 i = 0,
514 len, record,
515 commit;
516 if (me.locked || !me.store) {
517 return false;
518 }
519 if (typeof records === "number") {
520 // No matching record, jump out
521 record = me.store.getAt(records);
522 if (!record) {
523 return false;
524 }
525 records = [
526 record,
527 ];
528 } else if (!Ext.isArray(records)) {
529 records = [
530 records,
531 ];
532 }
533 // [P] a beforedeselection, triggered by me.onSelectChange below, can block removal by
534 // returning false, thus the original implementation removed only here in the commit fn,
535 // which has an abysmal performance O(n^3). As blocking removal is not the norm, go do the
536 // reverse, record blocked records and remove them from the to-be-removed array before
537 // applying it. A FF86 i9-9900K on 10k records goes from >40s to ~33ms for >90% deselection
538 let committed = false;
539 commit = function() {
540 committed = true;
541 if (record === me.selectionStart) {
542 me.selectionStart = null;
543 }
544 };
545 let removalBlocked = [];
546 len = records.length;
547 me.suspendChanges();
548 for (; i < len; i++) {
549 record = records[i];
550 if (me.isSelected(record)) {
551 committed = false;
552 me.onSelectChange(record, false, suppressEvent, commit);
553 if (!committed) {
554 removalBlocked.push(record);
555 }
556 if (me.destroyed) {
557 return false;
558 }
559 }
560 }
561 if (removalBlocked.length > 0) {
562 records.remove(removalBlocked);
563 }
564 selected.remove(records); // [P] FAST(er)
565 me.lastSelected = selected.last();
566 me.resumeChanges();
567 // fire selchange if there was a change and there is no suppressEvent flag
568 me.maybeFireSelectionChange(records.length > 0 && !suppressEvent);
ea2b3fd7
TL
569 return records.length;
570 },
571
572
573 doMultiSelect: function(records, keepExisting, suppressEvent) {
574 var me = this,
575 selected = me.selected,
576 change = false,
577 result, i, len, record, commit;
578
579 if (me.locked) {
580 return;
581 }
582
583 records = !Ext.isArray(records) ? [records] : records;
584 len = records.length;
585 if (!keepExisting && selected.getCount() > 0) {
586 result = me.deselectDuringSelect(records, suppressEvent);
587 if (me.destroyed) {
588 return;
589 }
590 if (result[0]) {
591 // We had a failure during selection, so jump out
592 // Fire selection change if we did deselect anything
593 me.maybeFireSelectionChange(result[1] > 0 && !suppressEvent);
594 return;
595 } else {
596 // Means something has been deselected, so we've had a change
597 change = result[1] > 0;
598 }
599 }
600
601 let gotBlocked, blockedRecords = [];
602 commit = function() {
603 if (!selected.getCount()) {
604 me.selectionStart = record;
605 }
606 gotBlocked = false;
607 change = true;
608 };
609
610 for (i = 0; i < len; i++) {
611 record = records[i];
612 if (me.isSelected(record)) {
613 continue;
614 }
615
616 gotBlocked = true;
617 me.onSelectChange(record, true, suppressEvent, commit);
618 if (me.destroyed) {
619 return;
620 }
621 if (gotBlocked) {
622 blockedRecords.push(record);
623 }
624 }
625 if (blockedRecords.length > 0) {
626 records.remove(blockedRecords);
627 }
628 selected.add(records);
629 me.lastSelected = record;
630
631 // fire selchange if there was a change and there is no suppressEvent flag
632 me.maybeFireSelectionChange(change && !suppressEvent);
633 },
634 deselectDuringSelect: function(toSelect, suppressEvent) {
635 var me = this,
636 selected = me.selected.getRange(),
637 changed = 0,
638 failed = false;
639 // Prevent selection change events from firing, will happen during select
640 me.suspendChanges();
641 me.deselectingDuringSelect = true;
642 let toDeselect = selected.filter(item => !Ext.Array.contains(toSelect, item));
643 if (toDeselect.length > 0) {
644 changed = me.doDeselect(toDeselect, suppressEvent);
645 if (!changed) {
646 failed = true;
647 }
648 if (me.destroyed) {
649 failed = true;
650 changed = 0;
651 }
652 }
653 me.deselectingDuringSelect = false;
654 me.resumeChanges();
655 return [
656 failed,
657 changed,
658 ];
1f628e9c 659 },
98d894d8
DC
660});
661
bb64de6e
DM
662// force alert boxes to be rendered with an Error Icon
663// since Ext.Msg is an object and not a prototype, we need to override it
664// after the framework has been initiated
665Ext.onReady(function() {
bb64de6e 666 Ext.override(Ext.Msg, {
05a977a2 667 alert: function(title, message, fn, scope) { // eslint-disable-line consistent-return
bb64de6e 668 if (Ext.isString(title)) {
05a977a2 669 let config = {
bb64de6e
DM
670 title: title,
671 message: message,
672 icon: this.ERROR,
673 buttons: this.OK,
674 fn: fn,
01031528
TL
675 scope: scope,
676 minWidth: this.minWidth,
bb64de6e
DM
677 };
678 return this.show(config);
679 }
01031528 680 },
bb64de6e 681 });
bb64de6e
DM
682});
683Ext.define('Ext.ux.IFrame', {
684 extend: 'Ext.Component',
685
686 alias: 'widget.uxiframe',
687
688 loadMask: 'Loading...',
689
690 src: 'about:blank',
691
692 renderTpl: [
01031528 693 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>',
bb64de6e
DM
694 ],
695 childEls: ['iframeEl'],
696
01031528 697 initComponent: function() {
bb64de6e
DM
698 this.callParent();
699
700 this.frameName = this.frameName || this.id + '-frame';
701 },
702
01031528 703 initEvents: function() {
05a977a2 704 let me = this;
bb64de6e
DM
705 me.callParent();
706 me.iframeEl.on('load', me.onLoad, me);
707 },
708
709 initRenderData: function() {
710 return Ext.apply(this.callParent(), {
711 src: this.src,
01031528 712 frameName: this.frameName,
bb64de6e
DM
713 });
714 },
715
716 getBody: function() {
05a977a2 717 let doc = this.getDoc();
bb64de6e
DM
718 return doc.body || doc.documentElement;
719 },
720
721 getDoc: function() {
722 try {
723 return this.getWin().document;
724 } catch (ex) {
725 return null;
726 }
727 },
728
729 getWin: function() {
05a977a2 730 let me = this,
bb64de6e
DM
731 name = me.frameName,
732 win = Ext.isIE
733 ? me.iframeEl.dom.contentWindow
734 : window.frames[name];
735 return win;
736 },
737
738 getFrame: function() {
05a977a2 739 let me = this;
bb64de6e
DM
740 return me.iframeEl.dom;
741 },
742
01031528 743 beforeDestroy: function() {
bb64de6e
DM
744 this.cleanupListeners(true);
745 this.callParent();
746 },
747
01031528 748 cleanupListeners: function(destroying) {
05a977a2 749 let doc, prop;
bb64de6e
DM
750
751 if (this.rendered) {
752 try {
753 doc = this.getDoc();
754 if (doc) {
bb64de6e 755 Ext.get(doc).un(this._docListeners);
bb64de6e
DM
756 if (destroying && doc.hasOwnProperty) {
757 for (prop in doc) {
05a977a2 758 if (Object.prototype.hasOwnProperty.call(doc, prop)) {
bb64de6e
DM
759 delete doc[prop];
760 }
761 }
762 }
763 }
05a977a2
TL
764 } catch (e) {
765 // do nothing
766 }
bb64de6e
DM
767 }
768 },
769
770 onLoad: function() {
05a977a2 771 let me = this,
bb64de6e
DM
772 doc = me.getDoc(),
773 fn = me.onRelayedEvent;
774
775 if (doc) {
776 try {
777 // These events need to be relayed from the inner document (where they stop
778 // bubbling) up to the outer document. This has to be done at the DOM level so
779 // the event reaches listeners on elements like the document body. The effected
780 // mechanisms that depend on this bubbling behavior are listed to the right
781 // of the event.
bb64de6e
DM
782 Ext.get(doc).on(
783 me._docListeners = {
784 mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
785 mousemove: fn, // window resize drag detection
01031528
TL
786 mouseup: fn, // window resize termination
787 click: fn, // not sure, but just to be safe
788 dblclick: fn, // not sure again
789 scope: me,
790 },
bb64de6e 791 );
01031528 792 } catch (e) {
bb64de6e
DM
793 // cannot do this xss
794 }
795
796 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
797 Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me);
798
799 this.el.unmask();
800 this.fireEvent('load', this);
bb64de6e 801 } else if (me.src) {
bb64de6e
DM
802 this.el.unmask();
803 this.fireEvent('error', this);
804 }
bb64de6e
DM
805 },
806
01031528 807 onRelayedEvent: function(event) {
bb64de6e
DM
808 // relay event from the iframe's document to the document that owns the iframe...
809
05a977a2 810 let iframeEl = this.iframeEl,
bb64de6e
DM
811
812 // Get the left-based iframe position
813 iframeXY = iframeEl.getTrueXY(),
814 originalEventXY = event.getXY(),
815
816 // Get the left-based XY position.
817 // This is because the consumer of the injected event will
818 // perform its own RTL normalization.
819 eventXY = event.getTrueXY();
820
821 // the event from the inner document has XY relative to that document's origin,
822 // so adjust it to use the origin of the iframe in the outer document:
823 event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]];
824
825 event.injectEvent(iframeEl); // blame the iframe for the event...
826
827 event.xy = originalEventXY; // restore the original XY (just for safety)
828 },
829
01031528 830 load: function(src) {
05a977a2 831 let me = this,
bb64de6e
DM
832 text = me.loadMask,
833 frame = me.getFrame();
834
835 if (me.fireEvent('beforeload', me, src) !== false) {
836 if (text && me.el) {
837 me.el.mask(text);
838 }
839
01031528 840 frame.src = me.src = src || me.src;
bb64de6e 841 }
01031528 842 },
bb64de6e 843});