]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - src/Toolkit.js
acme: allow wildcards as domain
[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
6// custom Vtypes
7Ext.apply(Ext.form.field.VTypes, {
01031528 8 IPAddress: function(v) {
bb64de6e
DM
9 return Proxmox.Utils.IP4_match.test(v);
10 },
01031528 11 IPAddressText: gettext('Example') + ': 192.168.1.1',
05a977a2 12 IPAddressMask: /[\d.]/i,
bb64de6e 13
01031528 14 IPCIDRAddress: function(v) {
05a977a2 15 let result = Proxmox.Utils.IP4_cidr_match.exec(v);
bb64de6e
DM
16 // limits according to JSON Schema see
17 // pve-common/src/PVE/JSONSchema.pm
01031528 18 return result !== null && result[1] >= 8 && result[1] <= 32;
bb64de6e 19 },
05a977a2
TL
20 IPCIDRAddressText: gettext('Example') + ': 192.168.1.1/24<br>' + gettext('Valid CIDR Range') + ': 8-32',
21 IPCIDRAddressMask: /[\d./]/i,
bb64de6e 22
01031528 23 IP6Address: function(v) {
bb64de6e
DM
24 return Proxmox.Utils.IP6_match.test(v);
25 },
01031528 26 IP6AddressText: gettext('Example') + ': 2001:DB8::42',
bb64de6e
DM
27 IP6AddressMask: /[A-Fa-f0-9:]/,
28
01031528 29 IP6CIDRAddress: function(v) {
05a977a2 30 let result = Proxmox.Utils.IP6_cidr_match.exec(v);
bb64de6e
DM
31 // limits according to JSON Schema see
32 // pve-common/src/PVE/JSONSchema.pm
01031528 33 return result !== null && result[1] >= 8 && result[1] <= 128;
bb64de6e 34 },
05a977a2
TL
35 IP6CIDRAddressText: gettext('Example') + ': 2001:DB8::42/64<br>' + gettext('Valid CIDR Range') + ': 8-128',
36 IP6CIDRAddressMask: /[A-Fa-f0-9:/]/,
bb64de6e 37
01031528 38 IP6PrefixLength: function(v) {
bb64de6e
DM
39 return v >= 0 && v <= 128;
40 },
01031528
TL
41 IP6PrefixLengthText: gettext('Example') + ': X, where 0 <= X <= 128',
42 IP6PrefixLengthMask: /[0-9]/,
bb64de6e 43
01031528 44 IP64Address: function(v) {
bb64de6e
DM
45 return Proxmox.Utils.IP64_match.test(v);
46 },
01031528 47 IP64AddressText: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
05a977a2 48 IP64AddressMask: /[A-Fa-f0-9.:]/,
bb64de6e 49
577b6c75 50 IP64CIDRAddress: function(v) {
05a977a2 51 let result = Proxmox.Utils.IP64_cidr_match.exec(v);
577b6c75
ML
52 if (result === null) {
53 return false;
54 }
55 if (result[1] !== undefined) {
56 return result[1] >= 8 && result[1] <= 128;
57 } else if (result[2] !== undefined) {
58 return result[2] >= 8 && result[2] <= 32;
59 } else {
60 return false;
61 }
62 },
63 IP64CIDRAddressText: gettext('Example') + ': 192.168.1.1/24 2001:DB8::42/64',
05a977a2 64 IP64CIDRAddressMask: /[A-Fa-f0-9.:/]/,
577b6c75 65
bb64de6e
DM
66 MacAddress: function(v) {
67 return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v);
68 },
69 MacAddressMask: /[a-fA-F0-9:]/,
70 MacAddressText: gettext('Example') + ': 01:23:45:67:89:ab',
71
01031528 72 MacPrefix: function(v) {
add18fad 73 return (/^[a-f0-9][02468ace](?::[a-f0-9]{2}){0,2}:?$/i).test(v);
8f449655
TL
74 },
75 MacPrefixMask: /[a-fA-F0-9:]/,
ffe26505 76 MacPrefixText: gettext('Example') + ': 02:8f - ' + gettext('only unicast addresses are allowed'),
8f449655 77
bb64de6e
DM
78 BridgeName: function(v) {
79 return (/^vmbr\d{1,4}$/).test(v);
80 },
8aefd47c
AD
81 VlanName: function(v) {
82 if (Proxmox.Utils.VlanInterface_match.test(v)) {
83 return true;
84 } else if (Proxmox.Utils.Vlan_match.test(v)) {
85 return true;
86 }
87 return true;
88 },
bb64de6e
DM
89 BridgeNameText: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
90
91 BondName: function(v) {
92 return (/^bond\d{1,4}$/).test(v);
93 },
94 BondNameText: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
95
96 InterfaceName: function(v) {
97 return (/^[a-z][a-z0-9_]{1,20}$/).test(v);
98 },
05a977a2
TL
99 InterfaceNameText: gettext("Allowed characters") + ": 'a-z', '0-9', '_'<br />" +
100 gettext("Minimum characters") + ": 2<br />" +
101 gettext("Maximum characters") + ": 21<br />" +
bb64de6e
DM
102 gettext("Must start with") + ": 'a-z'",
103
01031528 104 StorageId: function(v) {
05a977a2 105 return (/^[a-z][a-z0-9\-_.]*[a-z0-9]$/i).test(v);
bb64de6e 106 },
05a977a2
TL
107 StorageIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'<br />" +
108 gettext("Minimum characters") + ": 2<br />" +
bb64de6e
DM
109 gettext("Must start with") + ": 'A-Z', 'a-z'<br />" +
110 gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />",
111
01031528 112 ConfigId: function(v) {
05a977a2 113 return (/^[a-z][a-z0-9_]+$/i).test(v);
bb64de6e 114 },
05a977a2
TL
115 ConfigIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'<br />" +
116 gettext("Minimum characters") + ": 2<br />" +
bb64de6e
DM
117 gettext("Must start with") + ": " + gettext("letter"),
118
01031528 119 HttpProxy: function(v) {
bb64de6e
DM
120 return (/^http:\/\/.*$/).test(v);
121 },
122 HttpProxyText: gettext('Example') + ": http://username:password&#64;host:port/",
123
124 DnsName: function(v) {
125 return Proxmox.Utils.DnsName_match.test(v);
126 },
127 DnsNameText: gettext('This is not a valid DNS name'),
128
66c5ceb8
SI
129 DnsNameOrWildcard: function(v) {
130 return Proxmox.Utils.DnsName_or_Wildcard_match.test(v);
131 },
132 DnsNameOrWildcardText: gettext('This is not a valid DNS name'),
133
bb64de6e
DM
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
3c158249
TL
192// we always want the number in x.y format and never in, e.g., x,y
193Ext.define('PVE.form.field.Number', {
194 override: 'Ext.form.field.Number',
01031528 195 submitLocaleSeparator: false,
3c158249
TL
196});
197
bb64de6e
DM
198// ExtJs 5-6 has an issue with caching
199// see https://www.sencha.com/forum/showthread.php?308989
200Ext.define('Proxmox.UnderlayPool', {
201 override: 'Ext.dom.UnderlayPool',
202
01031528 203 checkOut: function() {
05a977a2 204 let cache = this.cache,
bb64de6e
DM
205 len = cache.length,
206 el;
207
208 // do cleanup because some of the objects might have been destroyed
209 while (len--) {
210 if (cache[len].destroyed) {
211 cache.splice(len, 1);
212 }
213 }
214 // end do cleanup
215
216 el = cache.shift();
217
218 if (!el) {
219 el = Ext.Element.create(this.elementConfig);
220 el.setVisibilityMode(2);
221 //<debug>
222 // tell the spec runner to ignore this element when checking if the dom is clean
223 el.dom.setAttribute('data-sticky', true);
224 //</debug>
225 }
226
227 return el;
01031528 228 },
bb64de6e
DM
229});
230
231// if the order of the values are not the same in originalValue and value
232// extjs will not overwrite value, but marks the field dirty and thus
233// the reset button will be enabled (but clicking it changes nothing)
234// so if the arrays are not the same after resetting, we
235// clear and set it
236Ext.define('Proxmox.form.ComboBox', {
237 override: 'Ext.form.field.ComboBox',
238
239 reset: function() {
240 // copied from combobox
05a977a2 241 let me = this;
bb64de6e 242 me.callParent();
bb64de6e
DM
243
244 // clear and set when not the same
05a977a2
TL
245 let value = me.getValue();
246 if (Ext.isArray(me.originalValue) && Ext.isArray(value) &&
247 !Ext.Array.equals(value, me.originalValue)) {
bb64de6e
DM
248 me.clearValue();
249 me.setValue(me.originalValue);
250 }
50032132
DC
251 },
252
253 // we also want to open the trigger on editable comboboxes by default
254 initComponent: function() {
255 let me = this;
256 me.callParent();
257
258 if (me.editable) {
259 // The trigger.picker causes first a focus event on the field then
260 // toggles the selection picker. Thus skip expanding in this case,
261 // else our focus listener expands and the picker.trigger then
262 // collapses it directly afterwards.
263 Ext.override(me.triggers.picker, {
264 onMouseDown: function(e) {
265 // copied "should we focus" check from Ext.form.trigger.Trigger
266 if (e.pointerType !== 'touch' && !this.field.owns(Ext.Element.getActiveElement())) {
267 me.skip_expand_on_focus = true;
268 }
269 this.callParent(arguments);
01031528 270 },
50032132
DC
271 });
272
273 me.on("focus", function(combobox) {
274 if (!combobox.isExpanded && !combobox.skip_expand_on_focus) {
275 combobox.expand();
276 }
277 combobox.skip_expand_on_focus = false;
278 });
279 }
280 },
bb64de6e
DM
281});
282
47d1c80c
TL
283// when refreshing a grid/tree view, restoring the focus moves the view back to
284// the previously focused item. Save scroll position before refocusing.
285Ext.define(null, {
286 override: 'Ext.view.Table',
287
288 jumpToFocus: false,
289
290 saveFocusState: function() {
9c1296e5 291 var me = this,
05a977a2
TL
292 store = me.dataSource,
293 actionableMode = me.actionableMode,
294 navModel = me.getNavigationModel(),
295 focusPosition = actionableMode ? me.actionPosition : navModel.getPosition(true),
9c1296e5
DC
296 activeElement = Ext.fly(Ext.Element.getActiveElement()),
297 focusCell = focusPosition && focusPosition.view === me &&
298 Ext.fly(focusPosition.getCell(true)),
299 refocusRow, refocusCol, record;
300
301 // The navModel may return a position that is in a locked partner, so check that
302 // the focusPosition's cell contains the focus before going forward.
303 // The skipSaveFocusState is set by Actionables which actively control
304 // focus destination. See CellEditing#activateCell.
305 if (!me.skipSaveFocusState && focusCell && focusCell.contains(activeElement)) {
05a977a2
TL
306 // Separate this from the instance that the nav model is using.
307 focusPosition = focusPosition.clone();
308
9c1296e5
DC
309 // While we deactivate the focused element, suspend focus processing on it.
310 activeElement.suspendFocusEvents();
311
312 // Suspend actionable mode.
313 // Each Actionable must silently save its state ready to resume when focus
314 // can be restored but should only do that if the activeElement is not the cell itself,
315 // this happens when the grid is refreshed while one of the actionables is being
316 // deactivated (e.g. Calling view refresh inside CellEditor 'edit' event listener).
317 if (actionableMode && focusCell.dom !== activeElement.dom) {
318 me.suspendActionableMode();
319 } else {
320 // Clear position, otherwise the setPosition on the other side
321 // will be rejected as a no-op if the resumption position is logically
322 // equivalent.
323 actionableMode = false;
324 navModel.setPosition();
05a977a2 325 }
47d1c80c 326
9c1296e5
DC
327 // Do not leave the element in tht state in case refresh fails, and restoration
328 // closure not called.
329 activeElement.resumeFocusEvents();
05a977a2 330
9c1296e5
DC
331 // if the store is expanding or collapsing, we should never scroll the view.
332 if (store.isExpandingOrCollapsing) {
333 return Ext.emptyFn;
334 }
05a977a2
TL
335
336 // The following function will attempt to refocus back in the same mode to the same cell
9c1296e5
DC
337 // as it was at before based upon the previous record (if it's still in the store),
338 // or the row index.
05a977a2 339 return function() {
9c1296e5
DC
340 var all;
341
342 // May have changed due to reconfigure
343 store = me.dataSource;
344
05a977a2
TL
345 // If we still have data, attempt to refocus in the same mode.
346 if (store.getCount()) {
9c1296e5
DC
347 all = me.all;
348
349 // Adjust expectations of where we are able to refocus according to
350 // what kind of destruction might have been wrought on this view's DOM
351 // during focus save.
352 refocusRow =
353 Math.min(Math.max(focusPosition.rowIdx, all.startIndex), all.endIndex);
354
355 refocusCol = Math.min(
356 focusPosition.colIdx,
357 me.getVisibleColumnManager().getColumns().length - 1,
358 );
359
360 record = focusPosition.record;
361
362 focusPosition = new Ext.grid.CellContext(me).setPosition(
363 record && store.contains(record) && !record.isCollapsedPlaceholder
364 ? record
365 : refocusRow,
366 refocusCol,
367 );
368
369 // Maybe there are no cells. eg: all groups collapsed.
370 if (focusPosition.getCell(true)) {
371 if (actionableMode) {
372 me.resumeActionableMode(focusPosition);
373 } else {
374 // we sometimes want to scroll back to where we are
375
376 let x = me.getScrollX();
377 let y = me.getScrollY();
378
379 // Pass "preventNavigation" as true
380 // so that that does not cause selection.
381 navModel.setPosition(focusPosition, null, null, null, true);
382
383 if (!navModel.getPosition()) {
384 focusPosition.column.focus();
385 }
386
387 if (!me.jumpToFocus) {
388 me.scrollTo(x, y);
389 }
47d1c80c 390 }
05a977a2
TL
391 }
392 } else { // No rows - focus associated column header
393 focusPosition.column.focus();
394 }
395 };
396 }
397 return Ext.emptyFn;
01031528 398 },
47d1c80c
TL
399});
400
a55813d6
DM
401// ExtJS 6.0.1 has no setSubmitValue() (although you find it in the docs).
402// Note: this.submitValue is a boolean flag, whereas getSubmitValue() returns
403// data to be submitted.
1d9804a9
DM
404Ext.define('Proxmox.form.field.Text', {
405 override: 'Ext.form.field.Text',
406
407 setSubmitValue: function(v) {
408 this.submitValue = v;
409 },
1d9804a9
DM
410});
411
d78eb5ec
DC
412// make mousescrolling work in firefox in the containers overflowhandler,
413// by using only the 'wheel' event not 'mousewheel'(fixed in 7.3)
414// also reverse the scrolldirection (fixed in 7.3)
415// and reduce the default increment
1fb41f2e
TL
416Ext.define(null, {
417 override: 'Ext.layout.container.boxOverflow.Scroller',
418
d78eb5ec
DC
419 wheelIncrement: 1,
420
421 getWheelDelta: function(e) {
422 return -e.getWheelDelta(e);
423 },
424
425 onOwnerRender: function(owner) {
426 var me = this,
427 scrollable = {
428 isBoxOverflowScroller: true,
429 x: false,
430 y: false,
431 listeners: {
432 scrollend: this.onScrollEnd,
433 scope: this,
434 },
435 };
436
437 // If no obstrusive scrollbars, allow natural scrolling on mobile touch devices
438 if (!Ext.scrollbar.width() && !Ext.platformTags.desktop) {
439 scrollable[owner.layout.horizontal ? 'x' : 'y'] = true;
1fb41f2e 440 } else {
d78eb5ec
DC
441 me.wheelListener = me.layout.innerCt.on(
442 'wheel', me.onMouseWheel, me, { destroyable: true },
443 );
1fb41f2e 444 }
1fb41f2e 445
d78eb5ec 446 owner.setScrollable(scrollable);
01031528 447 },
d78eb5ec
DC
448});
449
450// extj 6.7 reversed mousewheel direction... (fixed in 7.3)
451// https://forum.sencha.com/forum/showthread.php?472517-Mousewheel-scroll-direction-in-numberfield-with-spinners
452// alse use the 'wheel' event instead of 'mousewheel' (fixed in 7.3)
453Ext.define('Proxmox.form.field.Spinner', {
454 override: 'Ext.form.field.Spinner',
455
456 onRender: function() {
457 var me = this,
458 spinnerTrigger = me.getTrigger('spinner');
1fb41f2e 459
d78eb5ec
DC
460 me.callParent();
461
462 // Init up/down arrow keys
463 if (me.keyNavEnabled) {
464 me.spinnerKeyNav = new Ext.util.KeyNav({
465 target: me.inputEl,
466 scope: me,
467 up: me.spinUp,
468 down: me.spinDown,
469 });
470
471 me.inputEl.on({
472 keyup: me.onInputElKeyUp,
473 scope: me,
474 });
475 }
476
477 // Init mouse wheel
478 if (me.mouseWheelEnabled) {
479 me.mon(me.bodyEl, 'wheel', me.onMouseWheel, me);
480 }
481
482 // in v4 spinUpEl/spinDownEl were childEls, now they are children of the trigger.
483 // create references for compatibility
484 me.spinUpEl = spinnerTrigger.upEl;
485 me.spinDownEl = spinnerTrigger.downEl;
486 },
487
488 onMouseWheel: function(e) {
489 var me = this,
490 delta;
491 if (me.hasFocus) {
492 delta = e.getWheelDelta();
493 if (delta > 0) {
494 me.spinDown();
495 } else if (delta < 0) {
496 me.spinUp();
497 }
498 e.stopEvent();
499 me.onSpinEnd();
500 }
501 },
1fb41f2e
TL
502});
503
312310e0
DC
504// add '@' to the valid id
505Ext.define('Proxmox.validIdReOverride', {
506 override: 'Ext.Component',
05a977a2 507 validIdRe: /^[a-z_][a-z0-9\-_@]*$/i,
312310e0
DC
508});
509
98d894d8
DC
510Ext.define('Proxmox.selection.CheckboxModel', {
511 override: 'Ext.selection.CheckboxModel',
512
1f628e9c 513 // [P] use whole checkbox cell to multiselect, not only the checkbox
98d894d8 514 checkSelector: '.x-grid-cell-row-checker',
1f628e9c 515
ea2b3fd7
TL
516 // TODO: remove all optimizations below to an override for parent 'Ext.selection.Model' ??
517
1f628e9c
TL
518 // [ P: optimized to remove all records at once as single remove is O(n^3) slow ]
519 // records can be an index, a record or an array of records
520 doDeselect: function(records, suppressEvent) {
521 var me = this,
522 selected = me.selected,
523 i = 0,
524 len, record,
525 commit;
526 if (me.locked || !me.store) {
527 return false;
528 }
529 if (typeof records === "number") {
530 // No matching record, jump out
531 record = me.store.getAt(records);
532 if (!record) {
533 return false;
534 }
535 records = [
536 record,
537 ];
538 } else if (!Ext.isArray(records)) {
539 records = [
540 records,
541 ];
542 }
543 // [P] a beforedeselection, triggered by me.onSelectChange below, can block removal by
544 // returning false, thus the original implementation removed only here in the commit fn,
545 // which has an abysmal performance O(n^3). As blocking removal is not the norm, go do the
546 // reverse, record blocked records and remove them from the to-be-removed array before
547 // applying it. A FF86 i9-9900K on 10k records goes from >40s to ~33ms for >90% deselection
548 let committed = false;
549 commit = function() {
550 committed = true;
551 if (record === me.selectionStart) {
552 me.selectionStart = null;
553 }
554 };
555 let removalBlocked = [];
556 len = records.length;
557 me.suspendChanges();
558 for (; i < len; i++) {
559 record = records[i];
560 if (me.isSelected(record)) {
561 committed = false;
562 me.onSelectChange(record, false, suppressEvent, commit);
563 if (!committed) {
564 removalBlocked.push(record);
565 }
566 if (me.destroyed) {
567 return false;
568 }
569 }
570 }
571 if (removalBlocked.length > 0) {
572 records.remove(removalBlocked);
573 }
574 selected.remove(records); // [P] FAST(er)
575 me.lastSelected = selected.last();
576 me.resumeChanges();
577 // fire selchange if there was a change and there is no suppressEvent flag
578 me.maybeFireSelectionChange(records.length > 0 && !suppressEvent);
ea2b3fd7
TL
579 return records.length;
580 },
581
582
583 doMultiSelect: function(records, keepExisting, suppressEvent) {
584 var me = this,
585 selected = me.selected,
586 change = false,
587 result, i, len, record, commit;
588
589 if (me.locked) {
590 return;
591 }
592
593 records = !Ext.isArray(records) ? [records] : records;
594 len = records.length;
595 if (!keepExisting && selected.getCount() > 0) {
596 result = me.deselectDuringSelect(records, suppressEvent);
597 if (me.destroyed) {
598 return;
599 }
600 if (result[0]) {
601 // We had a failure during selection, so jump out
602 // Fire selection change if we did deselect anything
603 me.maybeFireSelectionChange(result[1] > 0 && !suppressEvent);
604 return;
605 } else {
606 // Means something has been deselected, so we've had a change
607 change = result[1] > 0;
608 }
609 }
610
611 let gotBlocked, blockedRecords = [];
612 commit = function() {
613 if (!selected.getCount()) {
614 me.selectionStart = record;
615 }
616 gotBlocked = false;
617 change = true;
618 };
619
620 for (i = 0; i < len; i++) {
621 record = records[i];
622 if (me.isSelected(record)) {
623 continue;
624 }
625
626 gotBlocked = true;
627 me.onSelectChange(record, true, suppressEvent, commit);
628 if (me.destroyed) {
629 return;
630 }
631 if (gotBlocked) {
632 blockedRecords.push(record);
633 }
634 }
635 if (blockedRecords.length > 0) {
636 records.remove(blockedRecords);
637 }
638 selected.add(records);
639 me.lastSelected = record;
640
641 // fire selchange if there was a change and there is no suppressEvent flag
642 me.maybeFireSelectionChange(change && !suppressEvent);
643 },
644 deselectDuringSelect: function(toSelect, suppressEvent) {
645 var me = this,
646 selected = me.selected.getRange(),
647 changed = 0,
648 failed = false;
649 // Prevent selection change events from firing, will happen during select
650 me.suspendChanges();
651 me.deselectingDuringSelect = true;
652 let toDeselect = selected.filter(item => !Ext.Array.contains(toSelect, item));
653 if (toDeselect.length > 0) {
654 changed = me.doDeselect(toDeselect, suppressEvent);
655 if (!changed) {
656 failed = true;
657 }
658 if (me.destroyed) {
659 failed = true;
660 changed = 0;
661 }
662 }
663 me.deselectingDuringSelect = false;
664 me.resumeChanges();
665 return [
666 failed,
667 changed,
668 ];
1f628e9c 669 },
98d894d8
DC
670});
671
322de562
DC
672// stop nulling of properties
673Ext.define('Proxmox.Component', {
674 override: 'Ext.Component',
675 clearPropertiesOnDestroy: false,
676});
677
bb64de6e
DM
678// force alert boxes to be rendered with an Error Icon
679// since Ext.Msg is an object and not a prototype, we need to override it
680// after the framework has been initiated
681Ext.onReady(function() {
bb64de6e 682 Ext.override(Ext.Msg, {
05a977a2 683 alert: function(title, message, fn, scope) { // eslint-disable-line consistent-return
bb64de6e 684 if (Ext.isString(title)) {
05a977a2 685 let config = {
bb64de6e
DM
686 title: title,
687 message: message,
688 icon: this.ERROR,
689 buttons: this.OK,
690 fn: fn,
01031528
TL
691 scope: scope,
692 minWidth: this.minWidth,
bb64de6e
DM
693 };
694 return this.show(config);
695 }
01031528 696 },
bb64de6e 697 });
bb64de6e
DM
698});
699Ext.define('Ext.ux.IFrame', {
700 extend: 'Ext.Component',
701
702 alias: 'widget.uxiframe',
703
704 loadMask: 'Loading...',
705
706 src: 'about:blank',
707
708 renderTpl: [
01031528 709 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>',
bb64de6e
DM
710 ],
711 childEls: ['iframeEl'],
712
01031528 713 initComponent: function() {
bb64de6e
DM
714 this.callParent();
715
716 this.frameName = this.frameName || this.id + '-frame';
717 },
718
01031528 719 initEvents: function() {
05a977a2 720 let me = this;
bb64de6e
DM
721 me.callParent();
722 me.iframeEl.on('load', me.onLoad, me);
723 },
724
725 initRenderData: function() {
726 return Ext.apply(this.callParent(), {
727 src: this.src,
01031528 728 frameName: this.frameName,
bb64de6e
DM
729 });
730 },
731
732 getBody: function() {
05a977a2 733 let doc = this.getDoc();
bb64de6e
DM
734 return doc.body || doc.documentElement;
735 },
736
737 getDoc: function() {
738 try {
739 return this.getWin().document;
740 } catch (ex) {
741 return null;
742 }
743 },
744
745 getWin: function() {
05a977a2 746 let me = this,
bb64de6e
DM
747 name = me.frameName,
748 win = Ext.isIE
749 ? me.iframeEl.dom.contentWindow
750 : window.frames[name];
751 return win;
752 },
753
754 getFrame: function() {
05a977a2 755 let me = this;
bb64de6e
DM
756 return me.iframeEl.dom;
757 },
758
01031528 759 beforeDestroy: function() {
bb64de6e
DM
760 this.cleanupListeners(true);
761 this.callParent();
762 },
763
01031528 764 cleanupListeners: function(destroying) {
05a977a2 765 let doc, prop;
bb64de6e
DM
766
767 if (this.rendered) {
768 try {
769 doc = this.getDoc();
770 if (doc) {
bb64de6e 771 Ext.get(doc).un(this._docListeners);
bb64de6e
DM
772 if (destroying && doc.hasOwnProperty) {
773 for (prop in doc) {
05a977a2 774 if (Object.prototype.hasOwnProperty.call(doc, prop)) {
bb64de6e
DM
775 delete doc[prop];
776 }
777 }
778 }
779 }
05a977a2
TL
780 } catch (e) {
781 // do nothing
782 }
bb64de6e
DM
783 }
784 },
785
786 onLoad: function() {
05a977a2 787 let me = this,
bb64de6e
DM
788 doc = me.getDoc(),
789 fn = me.onRelayedEvent;
790
791 if (doc) {
792 try {
793 // These events need to be relayed from the inner document (where they stop
794 // bubbling) up to the outer document. This has to be done at the DOM level so
795 // the event reaches listeners on elements like the document body. The effected
796 // mechanisms that depend on this bubbling behavior are listed to the right
797 // of the event.
bb64de6e
DM
798 Ext.get(doc).on(
799 me._docListeners = {
800 mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
801 mousemove: fn, // window resize drag detection
01031528
TL
802 mouseup: fn, // window resize termination
803 click: fn, // not sure, but just to be safe
804 dblclick: fn, // not sure again
805 scope: me,
806 },
bb64de6e 807 );
01031528 808 } catch (e) {
bb64de6e
DM
809 // cannot do this xss
810 }
811
812 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
813 Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me);
814
815 this.el.unmask();
816 this.fireEvent('load', this);
bb64de6e 817 } else if (me.src) {
bb64de6e
DM
818 this.el.unmask();
819 this.fireEvent('error', this);
820 }
bb64de6e
DM
821 },
822
01031528 823 onRelayedEvent: function(event) {
bb64de6e
DM
824 // relay event from the iframe's document to the document that owns the iframe...
825
05a977a2 826 let iframeEl = this.iframeEl,
bb64de6e
DM
827
828 // Get the left-based iframe position
829 iframeXY = iframeEl.getTrueXY(),
830 originalEventXY = event.getXY(),
831
832 // Get the left-based XY position.
833 // This is because the consumer of the injected event will
834 // perform its own RTL normalization.
835 eventXY = event.getTrueXY();
836
837 // the event from the inner document has XY relative to that document's origin,
838 // so adjust it to use the origin of the iframe in the outer document:
839 event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]];
840
841 event.injectEvent(iframeEl); // blame the iframe for the event...
842
843 event.xy = originalEventXY; // restore the original XY (just for safety)
844 },
845
01031528 846 load: function(src) {
05a977a2 847 let me = this,
bb64de6e
DM
848 text = me.loadMask,
849 frame = me.getFrame();
850
851 if (me.fireEvent('beforeload', me, src) !== false) {
852 if (text && me.el) {
853 me.el.mask(text);
854 }
855
01031528 856 frame.src = me.src = src || me.src;
bb64de6e 857 }
01031528 858 },
bb64de6e 859});