1 // ExtJS related things
3 // do not send '_dc' parameter
4 Ext
.Ajax
.disableCaching
= false;
7 Ext
.apply(Ext
.form
.field
.VTypes
, {
8 IPAddress: function(v
) {
9 return Proxmox
.Utils
.IP4_match
.test(v
);
11 IPAddressText
: gettext('Example') + ': 192.168.1.1',
12 IPAddressMask
: /[\d.]/i,
14 IPCIDRAddress: function(v
) {
15 let result
= Proxmox
.Utils
.IP4_cidr_match
.exec(v
);
16 // limits according to JSON Schema see
17 // pve-common/src/PVE/JSONSchema.pm
18 return result
!== null && result
[1] >= 8 && result
[1] <= 32;
20 IPCIDRAddressText
: gettext('Example') + ': 192.168.1.1/24<br>' + gettext('Valid CIDR Range') + ': 8-32',
21 IPCIDRAddressMask
: /[\d./]/i
,
23 IP6Address: function(v
) {
24 return Proxmox
.Utils
.IP6_match
.test(v
);
26 IP6AddressText
: gettext('Example') + ': 2001:DB8::42',
27 IP6AddressMask
: /[A-Fa-f0-9:]/,
29 IP6CIDRAddress: function(v
) {
30 let result
= Proxmox
.Utils
.IP6_cidr_match
.exec(v
);
31 // limits according to JSON Schema see
32 // pve-common/src/PVE/JSONSchema.pm
33 return result
!== null && result
[1] >= 8 && result
[1] <= 128;
35 IP6CIDRAddressText
: gettext('Example') + ': 2001:DB8::42/64<br>' + gettext('Valid CIDR Range') + ': 8-128',
36 IP6CIDRAddressMask
: /[A-Fa-f0-9:/]/,
38 IP6PrefixLength: function(v
) {
39 return v
>= 0 && v
<= 128;
41 IP6PrefixLengthText
: gettext('Example') + ': X, where 0 <= X <= 128',
42 IP6PrefixLengthMask
: /[0-9]/,
44 IP64Address: function(v
) {
45 return Proxmox
.Utils
.IP64_match
.test(v
);
47 IP64AddressText
: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
48 IP64AddressMask
: /[A-Fa-f0-9.:]/,
50 IP64CIDRAddress: function(v
) {
51 let result
= Proxmox
.Utils
.IP64_cidr_match
.exec(v
);
52 if (result
=== null) {
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;
63 IP64CIDRAddressText
: gettext('Example') + ': 192.168.1.1/24 2001:DB8::42/64',
64 IP64CIDRAddressMask
: /[A-Fa-f0-9.:/]/,
66 MacAddress: function(v
) {
67 return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v
);
69 MacAddressMask
: /[a-fA-F0-9:]/,
70 MacAddressText
: gettext('Example') + ': 01:23:45:67:89:ab',
72 MacPrefix: function(v
) {
73 return (/^[a-f0-9][02468ace](?::[a-f0-9]{2}){0,2}:?$/i).test(v
);
75 MacPrefixMask
: /[a-fA-F0-9:]/,
76 MacPrefixText
: gettext('Example') + ': 02:8f - ' + gettext('only unicast addresses are allowed'),
78 BridgeName: function(v
) {
79 return (/^[a-zA-Z][a-zA-Z0-9_]{0,9}$/).test(v
);
81 VlanName: function(v
) {
82 if (Proxmox
.Utils
.VlanInterface_match
.test(v
)) {
84 } else if (Proxmox
.Utils
.Vlan_match
.test(v
)) {
89 BridgeNameText
: gettext('Format') + ': alphanumeric string starting with a character',
91 BondName: function(v
) {
92 return (/^bond\d{1,4}$/).test(v
);
94 BondNameText
: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
96 InterfaceName: function(v
) {
97 return (/^[a-z][a-z0-9_]{1,20}$/).test(v
);
99 InterfaceNameText
: gettext("Allowed characters") + ": 'a-z', '0-9', '_'<br />" +
100 gettext("Minimum characters") + ": 2<br />" +
101 gettext("Maximum characters") + ": 21<br />" +
102 gettext("Must start with") + ": 'a-z'",
104 StorageId: function(v
) {
105 return (/^[a-z][a-z0-9\-_.]*[a-z0-9]$/i).test(v
);
107 StorageIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'<br />" +
108 gettext("Minimum characters") + ": 2<br />" +
109 gettext("Must start with") + ": 'A-Z', 'a-z'<br />" +
110 gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />",
112 ConfigId: function(v
) {
113 return (/^[a-z][a-z0-9_-]+$/i).test(v
);
115 ConfigIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'<br />" +
116 gettext("Minimum characters") + ": 2<br />" +
117 gettext("Must start with") + ": " + gettext("letter"),
119 HttpProxy: function(v
) {
120 return (/^http:\/\/.*$/).test(v
);
122 HttpProxyText
: gettext('Example') + ": http://username:password@host:port/",
124 CpuSet: function(v
) {
125 return Proxmox
.Utils
.CpuSet_match
.test(v
);
127 CpuSetText
: gettext('This is not a valid CpuSet'),
129 DnsName: function(v
) {
130 return Proxmox
.Utils
.DnsName_match
.test(v
);
132 DnsNameText
: gettext('This is not a valid hostname'),
134 DnsNameOrWildcard: function(v
) {
135 return Proxmox
.Utils
.DnsName_or_Wildcard_match
.test(v
);
137 DnsNameOrWildcardText
: gettext('This is not a valid hostname'),
139 // email regex used by pve-common
140 proxmoxMail: function(v
) {
141 return (/^[\w+-~]+(\.[\w+-~]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/).test(v
);
143 proxmoxMailText
: gettext('Example') + ": user@example.com",
145 DnsOrIp: function(v
) {
146 if (!Proxmox
.Utils
.DnsName_match
.test(v
) &&
147 !Proxmox
.Utils
.IP64_match
.test(v
)) {
153 DnsOrIpText
: gettext('Not a valid DNS name or IP address.'),
155 HostPort: function(v
) {
156 return Proxmox
.Utils
.HostPort_match
.test(v
) ||
157 Proxmox
.Utils
.HostPortBrackets_match
.test(v
) ||
158 Proxmox
.Utils
.IP6_dotnotation_match
.test(v
);
160 HostPortText
: gettext('Host/IP address or optional port is invalid'),
162 HostList: function(v
) {
163 let list
= v
.split(/[ ,;]+/);
165 for (i
= 0; i
< list
.length
; i
++) {
166 if (list
[i
] === '') {
170 if (!Proxmox
.Utils
.HostPort_match
.test(list
[i
]) &&
171 !Proxmox
.Utils
.HostPortBrackets_match
.test(list
[i
]) &&
172 !Proxmox
.Utils
.IP6_dotnotation_match
.test(list
[i
])) {
179 HostListText
: gettext('Not a valid list of hosts'),
181 password: function(val
, field
) {
182 if (field
.initialPassField
) {
183 let pwd
= field
.up('form').down(`[name=${field.initialPassField}]`);
184 return val
=== pwd
.getValue();
189 passwordText
: gettext('Passwords do not match'),
191 email: function(value
) {
192 let emailre
= /^[\w+~-]+(\.[\w+~-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/;
193 return emailre
.test(value
);
197 // we always want the number in x.y format and never in, e.g., x,y
198 Ext
.define('PVE.form.field.Number', {
199 override
: 'Ext.form.field.Number',
200 submitLocaleSeparator
: false,
203 // avois spamming the console and if we ever use this avoid a CORS block error too
204 Ext
.define('PVE.draw.Container', {
205 override
: 'Ext.draw.Container',
206 defaultDownloadServerUrl
: document
.location
.origin
, // avoid that pointing to http://svg.sencha.io
207 applyDownloadServerUrl: function(url
) { // avoid noisy warning, we don't really use that anyway
208 url
= url
|| this.defaultDownloadServerUrl
;
213 // ExtJs 5-6 has an issue with caching
214 // see https://www.sencha.com/forum/showthread.php?308989
215 Ext
.define('Proxmox.UnderlayPool', {
216 override
: 'Ext.dom.UnderlayPool',
218 checkOut: function() {
219 let cache
= this.cache
,
223 // do cleanup because some of the objects might have been destroyed
225 if (cache
[len
].destroyed
) {
226 cache
.splice(len
, 1);
234 el
= Ext
.Element
.create(this.elementConfig
);
235 el
.setVisibilityMode(2);
237 // tell the spec runner to ignore this element when checking if the dom is clean
238 el
.dom
.setAttribute('data-sticky', true);
246 // if the order of the values are not the same in originalValue and value
247 // extjs will not overwrite value, but marks the field dirty and thus
248 // the reset button will be enabled (but clicking it changes nothing)
249 // so if the arrays are not the same after resetting, we
251 Ext
.define('Proxmox.form.ComboBox', {
252 override
: 'Ext.form.field.ComboBox',
255 // copied from combobox
259 // clear and set when not the same
260 let value
= me
.getValue();
261 if (Ext
.isArray(me
.originalValue
) && Ext
.isArray(value
) &&
262 !Ext
.Array
.equals(value
, me
.originalValue
)) {
264 me
.setValue(me
.originalValue
);
268 // we also want to open the trigger on editable comboboxes by default
269 initComponent: function() {
274 // The trigger.picker causes first a focus event on the field then
275 // toggles the selection picker. Thus skip expanding in this case,
276 // else our focus listener expands and the picker.trigger then
277 // collapses it directly afterwards.
278 Ext
.override(me
.triggers
.picker
, {
279 onMouseDown: function(e
) {
280 // copied "should we focus" check from Ext.form.trigger.Trigger
281 if (e
.pointerType
!== 'touch' && !this.field
.owns(Ext
.Element
.getActiveElement())) {
282 me
.skip_expand_on_focus
= true;
284 this.callParent(arguments
);
288 me
.on("focus", function(combobox
) {
289 if (!combobox
.isExpanded
&& !combobox
.skip_expand_on_focus
) {
292 combobox
.skip_expand_on_focus
= false;
298 // when refreshing a grid/tree view, restoring the focus moves the view back to
299 // the previously focused item. Save scroll position before refocusing.
301 override
: 'Ext.view.Table',
305 saveFocusState: function() {
307 store
= me
.dataSource
,
308 actionableMode
= me
.actionableMode
,
309 navModel
= me
.getNavigationModel(),
310 focusPosition
= actionableMode
? me
.actionPosition
: navModel
.getPosition(true),
311 activeElement
= Ext
.fly(Ext
.Element
.getActiveElement()),
312 focusCell
= focusPosition
&& focusPosition
.view
=== me
&&
313 Ext
.fly(focusPosition
.getCell(true)),
314 refocusRow
, refocusCol
, record
;
316 // The navModel may return a position that is in a locked partner, so check that
317 // the focusPosition's cell contains the focus before going forward.
318 // The skipSaveFocusState is set by Actionables which actively control
319 // focus destination. See CellEditing#activateCell.
320 if (!me
.skipSaveFocusState
&& focusCell
&& focusCell
.contains(activeElement
)) {
321 // Separate this from the instance that the nav model is using.
322 focusPosition
= focusPosition
.clone();
324 // While we deactivate the focused element, suspend focus processing on it.
325 activeElement
.suspendFocusEvents();
327 // Suspend actionable mode.
328 // Each Actionable must silently save its state ready to resume when focus
329 // can be restored but should only do that if the activeElement is not the cell itself,
330 // this happens when the grid is refreshed while one of the actionables is being
331 // deactivated (e.g. Calling view refresh inside CellEditor 'edit' event listener).
332 if (actionableMode
&& focusCell
.dom
!== activeElement
.dom
) {
333 me
.suspendActionableMode();
335 // Clear position, otherwise the setPosition on the other side
336 // will be rejected as a no-op if the resumption position is logically
338 actionableMode
= false;
339 navModel
.setPosition();
342 // Do not leave the element in that state in case refresh fails, and restoration
343 // closure not called.
344 activeElement
.resumeFocusEvents();
346 // if the store is expanding or collapsing, we should never scroll the view.
347 if (store
.isExpandingOrCollapsing
) {
351 // The following function will attempt to refocus back in the same mode to the same cell
352 // as it was at before based upon the previous record (if it's still in the store),
357 // May have changed due to reconfigure
358 store
= me
.dataSource
;
360 // If we still have data, attempt to refocus in the same mode.
361 if (store
.getCount()) {
364 // Adjust expectations of where we are able to refocus according to
365 // what kind of destruction might have been wrought on this view's DOM
366 // during focus save.
368 Math
.min(Math
.max(focusPosition
.rowIdx
, all
.startIndex
), all
.endIndex
);
370 refocusCol
= Math
.min(
371 focusPosition
.colIdx
,
372 me
.getVisibleColumnManager().getColumns().length
- 1,
375 record
= focusPosition
.record
;
377 focusPosition
= new Ext
.grid
.CellContext(me
).setPosition(
378 record
&& store
.contains(record
) && !record
.isCollapsedPlaceholder
384 // Maybe there are no cells. eg: all groups collapsed.
385 if (focusPosition
.getCell(true)) {
386 if (actionableMode
) {
387 me
.resumeActionableMode(focusPosition
);
389 // we sometimes want to scroll back to where we are
391 let x
= me
.getScrollX();
392 let y
= me
.getScrollY();
394 // Pass "preventNavigation" as true
395 // so that that does not cause selection.
396 navModel
.setPosition(focusPosition
, null, null, null, true);
398 if (!navModel
.getPosition()) {
399 focusPosition
.column
.focus();
402 if (!me
.jumpToFocus
) {
407 } else { // No rows - focus associated column header
408 focusPosition
.column
.focus();
416 // ExtJS 6.0.1 has no setSubmitValue() (although you find it in the docs).
417 // Note: this.submitValue is a boolean flag, whereas getSubmitValue() returns
418 // data to be submitted.
419 Ext
.define('Proxmox.form.field.Text', {
420 override
: 'Ext.form.field.Text',
422 setSubmitValue: function(v
) {
423 this.submitValue
= v
;
427 // make mousescrolling work in firefox in the containers overflowhandler,
428 // by using only the 'wheel' event not 'mousewheel'(fixed in 7.3)
429 // also reverse the scrolldirection (fixed in 7.3)
430 // and reduce the default increment
432 override
: 'Ext.layout.container.boxOverflow.Scroller',
436 getWheelDelta: function(e
) {
437 return -e
.getWheelDelta(e
);
440 onOwnerRender: function(owner
) {
443 isBoxOverflowScroller
: true,
447 scrollend
: this.onScrollEnd
,
452 // If no obstrusive scrollbars, allow natural scrolling on mobile touch devices
453 if (!Ext
.scrollbar
.width() && !Ext
.platformTags
.desktop
) {
454 scrollable
[owner
.layout
.horizontal
? 'x' : 'y'] = true;
456 me
.wheelListener
= me
.layout
.innerCt
.on(
457 'wheel', me
.onMouseWheel
, me
, { destroyable
: true },
461 owner
.setScrollable(scrollable
);
465 // extj 6.7 reversed mousewheel direction... (fixed in 7.3)
466 // https://forum.sencha.com/forum/showthread.php?472517-Mousewheel-scroll-direction-in-numberfield-with-spinners
467 // also use the 'wheel' event instead of 'mousewheel' (fixed in 7.3)
468 Ext
.define('Proxmox.form.field.Spinner', {
469 override
: 'Ext.form.field.Spinner',
471 onRender: function() {
477 if (me
.mouseWheelEnabled
) {
478 // Unlisten Ext generated listener ('mousewheel' is deprecated anyway)
479 me
.mun(me
.bodyEl
, 'mousewheel', me
.onMouseWheel
, me
);
481 me
.mon(me
.bodyEl
, 'wheel', me
.onMouseWheel
, me
);
485 onMouseWheel: function(e
) {
489 delta
= e
.getWheelDelta();
492 } else if (delta
< 0) {
501 // add '@' to the valid id
502 Ext
.define('Proxmox.validIdReOverride', {
503 override
: 'Ext.Component',
504 validIdRe
: /^[a-z_][a-z0-9\-_@]*$/i,
507 Ext
.define('Proxmox.selection.CheckboxModel', {
508 override
: 'Ext.selection.CheckboxModel',
510 // [P] use whole checkbox cell to multiselect, not only the checkbox
511 checkSelector
: '.x-grid-cell-row-checker',
513 // TODO: remove all optimizations below to an override for parent 'Ext.selection.Model' ??
515 // [ P: optimized to remove all records at once as single remove is O(n^3) slow ]
516 // records can be an index, a record or an array of records
517 doDeselect: function(records
, suppressEvent
) {
519 selected
= me
.selected
,
523 if (me
.locked
|| !me
.store
) {
526 if (typeof records
=== "number") {
527 // No matching record, jump out
528 record
= me
.store
.getAt(records
);
535 } else if (!Ext
.isArray(records
)) {
540 // [P] a beforedeselection, triggered by me.onSelectChange below, can block removal by
541 // returning false, thus the original implementation removed only here in the commit fn,
542 // which has an abysmal performance O(n^3). As blocking removal is not the norm, go do the
543 // reverse, record blocked records and remove them from the to-be-removed array before
544 // applying it. A FF86 i9-9900K on 10k records goes from >40s to ~33ms for >90% deselection
545 let committed
= false;
546 commit = function() {
548 if (record
=== me
.selectionStart
) {
549 me
.selectionStart
= null;
552 let removalBlocked
= [];
553 len
= records
.length
;
555 for (; i
< len
; i
++) {
557 if (me
.isSelected(record
)) {
559 me
.onSelectChange(record
, false, suppressEvent
, commit
);
561 removalBlocked
.push(record
);
568 if (removalBlocked
.length
> 0) {
569 records
.remove(removalBlocked
);
571 selected
.remove(records
); // [P] FAST(er)
572 me
.lastSelected
= selected
.last();
574 // fire selchange if there was a change and there is no suppressEvent flag
575 me
.maybeFireSelectionChange(records
.length
> 0 && !suppressEvent
);
576 return records
.length
;
580 doMultiSelect: function(records
, keepExisting
, suppressEvent
) {
582 selected
= me
.selected
,
584 result
, i
, len
, record
, commit
;
590 records
= !Ext
.isArray(records
) ? [records
] : records
;
591 len
= records
.length
;
592 if (!keepExisting
&& selected
.getCount() > 0) {
593 result
= me
.deselectDuringSelect(records
, suppressEvent
);
598 // We had a failure during selection, so jump out
599 // Fire selection change if we did deselect anything
600 me
.maybeFireSelectionChange(result
[1] > 0 && !suppressEvent
);
603 // Means something has been deselected, so we've had a change
604 change
= result
[1] > 0;
608 let gotBlocked
, blockedRecords
= [];
609 commit = function() {
610 if (!selected
.getCount()) {
611 me
.selectionStart
= record
;
617 for (i
= 0; i
< len
; i
++) {
619 if (me
.isSelected(record
)) {
624 me
.onSelectChange(record
, true, suppressEvent
, commit
);
629 blockedRecords
.push(record
);
632 if (blockedRecords
.length
> 0) {
633 records
.remove(blockedRecords
);
635 selected
.add(records
);
636 me
.lastSelected
= record
;
638 // fire selchange if there was a change and there is no suppressEvent flag
639 me
.maybeFireSelectionChange(change
&& !suppressEvent
);
641 deselectDuringSelect: function(toSelect
, suppressEvent
) {
643 selected
= me
.selected
.getRange(),
646 // Prevent selection change events from firing, will happen during select
648 me
.deselectingDuringSelect
= true;
649 let toDeselect
= selected
.filter(item
=> !Ext
.Array
.contains(toSelect
, item
));
650 if (toDeselect
.length
> 0) {
651 changed
= me
.doDeselect(toDeselect
, suppressEvent
);
660 me
.deselectingDuringSelect
= false;
669 // stop nulling of properties
670 Ext
.define('Proxmox.Component', {
671 override
: 'Ext.Component',
672 clearPropertiesOnDestroy
: false,
675 // Fix drag&drop for vms and desktops that detect 'pen' pointerType
676 // NOTE: this part has been rewritten in ExtJS 7.4, so re-check once we can upgrade
677 Ext
.define('Proxmox.view.DragZone', {
678 override
: 'Ext.view.DragZone',
680 onItemMouseDown: function(view
, record
, item
, index
, e
) {
681 // Ignore touchstart.
682 // For touch events, we use longpress.
683 if (e
.pointerType
!== 'touch') {
684 this.onTriggerGesture(view
, record
, item
, index
, e
);
689 // Fix text selection on drag when using DragZone,
690 // see https://forum.sencha.com/forum/showthread.php?335100
691 Ext
.define('Proxmox.dd.DragDropManager', {
692 override
: 'Ext.dd.DragDropManager',
694 stopEvent: function(e
) {
695 if (this.stopPropagation
) {
699 if (this.preventDefault
) {
705 // make it possible to set the SameSite attribute on cookies
706 Ext
.define('Proxmox.Cookies', {
707 override
: 'Ext.util.Cookies',
709 set: function(name
, value
, expires
, path
, domain
, secure
, samesite
) {
713 attrs
.push("expires=" + expires
.toUTCString());
716 if (path
=== undefined) { // mimic original function's behaviour
717 attrs
.push("path=/");
719 attrs
.push("path=" + path
);
723 attrs
.push("domain=" + domain
);
726 if (secure
=== true) {
727 attrs
.push("secure");
730 if (samesite
&& ["lax", "none", "strict"].includes(samesite
.toLowerCase())) {
731 attrs
.push("samesite=" + samesite
);
734 document
.cookie
= name
+ "=" + escape(value
) + "; " + attrs
.join("; ");
738 // force alert boxes to be rendered with an Error Icon
739 // since Ext.Msg is an object and not a prototype, we need to override it
740 // after the framework has been initiated
741 Ext
.onReady(function() {
742 Ext
.override(Ext
.Msg
, {
743 alert: function(title
, message
, fn
, scope
) { // eslint-disable-line consistent-return
744 if (Ext
.isString(title
)) {
752 minWidth
: this.minWidth
,
754 return this.show(config
);
760 // add allowfullscreen to render template to allow the noVNC/xterm.js embedded UIs to go fullscreen
762 // The rest is the same as in the separate ux package (extjs/build/packages/ux/classic/ux-debug.js),
763 // which we do not load as it's rather big and most of the widgets there are not useful for our UIs
764 Ext
.define('Ext.ux.IFrame', {
765 extend
: 'Ext.Component',
767 alias
: 'widget.uxiframe',
769 loadMask
: 'Loading...',
774 // eslint-disable-next-line max-len
775 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>',
778 childEls
: ['iframeEl'],
780 initComponent: function() {
783 this.frameName
= this.frameName
|| this.id
+ '-frame';
786 initEvents: function() {
790 me
.iframeEl
.on('load', me
.onLoad
, me
);
793 initRenderData: function() {
794 return Ext
.apply(this.callParent(), {
796 frameName
: this.frameName
,
800 getBody: function() {
801 let doc
= this.getDoc();
803 return doc
.body
|| doc
.documentElement
;
808 return this.getWin().document
;
817 win
= Ext
.isIE
? me
.iframeEl
.dom
.contentWindow
: window
.frames
[name
];
822 getFrame: function() {
825 return me
.iframeEl
.dom
;
834 this.fireEvent('load', this);
837 this.fireEvent('error', this);
841 load: function(src
) {
844 frame
= me
.getFrame();
846 if (me
.fireEvent('beforeload', me
, src
) !== false) {
851 frame
.src
= me
.src
= src
|| me
.src
;