]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - Toolkit.js
1 // ExtJS related things
3 // do not send '_dc' parameter
4 Ext
.Ajax
.disableCaching
= false;
6 // FIXME: HACK! Makes scrolling in number spinner work again. fixed in ExtJS >= 6.1
8 Ext
.$eventNameMap
.DOMMouseScroll
= 'DOMMouseScroll';
12 Ext
.apply(Ext
.form
.field
.VTypes
, {
13 IPAddress: function(v
) {
14 return Proxmox
.Utils
.IP4_match
.test(v
);
16 IPAddressText
: gettext('Example') + ': 192.168.1.1',
17 IPAddressMask
: /[\d\.]/i,
19 IPCIDRAddress: function(v
) {
20 var result
= Proxmox
.Utils
.IP4_cidr_match
.exec(v
);
21 // limits according to JSON Schema see
22 // pve-common/src/PVE/JSONSchema.pm
23 return (result
!== null && result
[1] >= 8 && result
[1] <= 32);
25 IPCIDRAddressText
: gettext('Example') + ': 192.168.1.1/24' + "<br>" + gettext('Valid CIDR Range') + ': 8-32',
26 IPCIDRAddressMask
: /[\d\.\/]/i,
28 IP6Address: function(v
) {
29 return Proxmox
.Utils
.IP6_match
.test(v
);
31 IP6AddressText
: gettext('Example') + ': 2001:DB8::42',
32 IP6AddressMask
: /[A-Fa-f0-9:]/,
34 IP6CIDRAddress: function(v
) {
35 var result
= Proxmox
.Utils
.IP6_cidr_match
.exec(v
);
36 // limits according to JSON Schema see
37 // pve-common/src/PVE/JSONSchema.pm
38 return (result
!== null && result
[1] >= 8 && result
[1] <= 128);
40 IP6CIDRAddressText
: gettext('Example') + ': 2001:DB8::42/64' + "<br>" + gettext('Valid CIDR Range') + ': 8-128',
41 IP6CIDRAddressMask
: /[A-Fa-f0-9:\/]/,
43 IP6PrefixLength: function(v
) {
44 return v
>= 0 && v
<= 128;
46 IP6PrefixLengthText
: gettext('Example') + ': X, where 0 <= X <= 128',
47 IP6PrefixLengthMask
: /[0-9]/,
49 IP64Address: function(v
) {
50 return Proxmox
.Utils
.IP64_match
.test(v
);
52 IP64AddressText
: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
53 IP64AddressMask
: /[A-Fa-f0-9\.:]/,
55 IP64CIDRAddress: function(v
) {
56 var result
= Proxmox
.Utils
.IP64_cidr_match
.exec(v
);
57 if (result
=== null) {
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;
68 IP64CIDRAddressText
: gettext('Example') + ': 192.168.1.1/24 2001:DB8::42/64',
69 IP64CIDRAddressMask
: /[A-Fa-f0-9\.:\/]/,
71 MacAddress: function(v
) {
72 return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v
);
74 MacAddressMask
: /[a-fA-F0-9:]/,
75 MacAddressText
: gettext('Example') + ': 01:23:45:67:89:ab',
77 MacPrefix: function(v
) {
78 return (/^[a-f0-9][02468ace](?::[a-f0-9]{2}){0,2}:?$/i).test(v
);
80 MacPrefixMask
: /[a-fA-F0-9:]/,
81 MacPrefixText
: gettext('Example') + ': 02:8f - ' + gettext('only unicast addresses are allowed'),
83 BridgeName: function(v
) {
84 return (/^vmbr\d{1,4}$/).test(v
);
86 BridgeNameText
: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
88 BondName: function(v
) {
89 return (/^bond\d{1,4}$/).test(v
);
91 BondNameText
: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
93 InterfaceName: function(v
) {
94 return (/^[a-z][a-z0-9_]{1,20}$/).test(v
);
96 InterfaceNameText
: gettext("Allowed characters") + ": 'a-z', '0-9', '_'" + "<br />" +
97 gettext("Minimum characters") + ": 2" + "<br />" +
98 gettext("Maximum characters") + ": 21" + "<br />" +
99 gettext("Must start with") + ": 'a-z'",
101 StorageId: function(v
) {
102 return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v
);
104 StorageIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'" + "<br />" +
105 gettext("Minimum characters") + ": 2" + "<br />" +
106 gettext("Must start with") + ": 'A-Z', 'a-z'<br />" +
107 gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />",
109 ConfigId: function(v
) {
110 return (/^[a-z][a-z0-9\_]+$/i).test(v
);
112 ConfigIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'" + "<br />" +
113 gettext("Minimum characters") + ": 2" + "<br />" +
114 gettext("Must start with") + ": " + gettext("letter"),
116 HttpProxy: function(v
) {
117 return (/^http:\/\/.*$/).test(v
);
119 HttpProxyText
: gettext('Example') + ": http://username:password@host:port/",
121 DnsName: function(v
) {
122 return Proxmox
.Utils
.DnsName_match
.test(v
);
124 DnsNameText
: gettext('This is not a valid DNS name'),
126 // workaround for https://www.sencha.com/forum/showthread.php?302150
127 proxmoxMail: function(v
) {
128 return (/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v
);
130 proxmoxMailText
: gettext('Example') + ": user@example.com",
132 DnsOrIp: function(v
) {
133 if (!Proxmox
.Utils
.DnsName_match
.test(v
) &&
134 !Proxmox
.Utils
.IP64_match
.test(v
)) {
140 DnsOrIpText
: gettext('Not a valid DNS name or IP address.'),
142 HostList: function(v
) {
143 var list
= v
.split(/[\ \,\;]+/);
145 for (i
= 0; i
< list
.length
; i
++) {
150 if (!Proxmox
.Utils
.HostPort_match
.test(list
[i
]) &&
151 !Proxmox
.Utils
.HostPortBrackets_match
.test(list
[i
]) &&
152 !Proxmox
.Utils
.IP6_dotnotation_match
.test(list
[i
])) {
159 HostListText
: gettext('Not a valid list of hosts'),
161 password: function(val
, field
) {
162 if (field
.initialPassField
) {
163 var pwd
= field
.up('form').down(
164 '[name=' + field
.initialPassField
+ ']');
165 return (val
== pwd
.getValue());
170 passwordText
: gettext('Passwords do not match')
173 // Firefox 52+ Touchscreen bug
174 // see https://www.sencha.com/forum/showthread.php?336762-Examples-don-t-work-in-Firefox-52-touchscreen/page2
175 // and https://bugzilla.proxmox.com/show_bug.cgi?id=1223
176 Ext
.define('EXTJS_23846.Element', {
177 override
: 'Ext.dom.Element'
178 }, function(Element
) {
179 var supports
= Ext
.supports
,
180 proto
= Element
.prototype,
181 eventMap
= proto
.eventMap
,
182 additiveEvents
= proto
.additiveEvents
;
184 if (Ext
.os
.is
.Desktop
&& supports
.TouchEvents
&& !supports
.PointerEvents
) {
185 eventMap
.touchstart
= 'mousedown';
186 eventMap
.touchmove
= 'mousemove';
187 eventMap
.touchend
= 'mouseup';
188 eventMap
.touchcancel
= 'mouseup';
190 additiveEvents
.mousedown
= 'mousedown';
191 additiveEvents
.mousemove
= 'mousemove';
192 additiveEvents
.mouseup
= 'mouseup';
193 additiveEvents
.touchstart
= 'touchstart';
194 additiveEvents
.touchmove
= 'touchmove';
195 additiveEvents
.touchend
= 'touchend';
196 additiveEvents
.touchcancel
= 'touchcancel';
198 additiveEvents
.pointerdown
= 'mousedown';
199 additiveEvents
.pointermove
= 'mousemove';
200 additiveEvents
.pointerup
= 'mouseup';
201 additiveEvents
.pointercancel
= 'mouseup';
205 Ext
.define('EXTJS_23846.Gesture', {
206 override
: 'Ext.event.publisher.Gesture'
207 }, function(Gesture
) {
208 var me
= Gesture
.instance
;
210 if (Ext
.supports
.TouchEvents
&& !Ext
.isWebKit
&& Ext
.os
.is
.Desktop
) {
211 me
.handledDomEvents
.push('mousedown', 'mousemove', 'mouseup');
216 Ext
.define('EXTJS_18900.Pie', {
217 override
: 'Ext.chart.series.Pie',
220 betweenAngle: function (x
, a
, b
) {
221 var pp
= Math
.PI
* 2,
222 offset
= this.rotationOffset
;
228 if (!this.getClockwise()) {
242 // Normalize, so that both x and b are in the [0,360) interval.
250 // Because 360 * n angles will be normalized to 0,
251 // we need to treat b === 0 as a special case.
252 return x
< b
|| b
=== 0;
256 // we always want the number in x.y format and never in, e.g., x,y
257 Ext
.define('PVE.form.field.Number', {
258 override
: 'Ext.form.field.Number',
259 submitLocaleSeparator
: false
262 // ExtJs 5-6 has an issue with caching
263 // see https://www.sencha.com/forum/showthread.php?308989
264 Ext
.define('Proxmox.UnderlayPool', {
265 override
: 'Ext.dom.UnderlayPool',
267 checkOut: function () {
268 var cache
= this.cache
,
272 // do cleanup because some of the objects might have been destroyed
274 if (cache
[len
].destroyed
) {
275 cache
.splice(len
, 1);
283 el
= Ext
.Element
.create(this.elementConfig
);
284 el
.setVisibilityMode(2);
286 // tell the spec runner to ignore this element when checking if the dom is clean
287 el
.dom
.setAttribute('data-sticky', true);
295 // 'Enter' in Textareas and aria multiline fields should not activate the
296 // defaultbutton, fixed in extjs 6.0.2
297 Ext
.define('PVE.panel.Panel', {
298 override
: 'Ext.panel.Panel',
300 fireDefaultButton: function(e
) {
301 if (e
.target
.getAttribute('aria-multiline') === 'true' ||
302 e
.target
.tagName
=== "TEXTAREA") {
305 return this.callParent(arguments
);
309 // if the order of the values are not the same in originalValue and value
310 // extjs will not overwrite value, but marks the field dirty and thus
311 // the reset button will be enabled (but clicking it changes nothing)
312 // so if the arrays are not the same after resetting, we
314 Ext
.define('Proxmox.form.ComboBox', {
315 override
: 'Ext.form.field.ComboBox',
318 // copied from combobox
322 // clear and set when not the same
323 var value
= me
.getValue();
324 if (Ext
.isArray(me
.originalValue
) && Ext
.isArray(value
) && !Ext
.Array
.equals(value
, me
.originalValue
)) {
326 me
.setValue(me
.originalValue
);
331 // when refreshing a grid/tree view, restoring the focus moves the view back to
332 // the previously focused item. Save scroll position before refocusing.
334 override
: 'Ext.view.Table',
338 saveFocusState: function() {
340 store
= me
.dataSource
,
341 actionableMode
= me
.actionableMode
,
342 navModel
= me
.getNavigationModel(),
343 focusPosition
= actionableMode
? me
.actionPosition
: navModel
.getPosition(true),
344 refocusRow
, refocusCol
;
347 // Separate this from the instance that the nav model is using.
348 focusPosition
= focusPosition
.clone();
350 // Exit actionable mode.
351 // We must inform any Actionables that they must relinquish control.
352 // Tabbability must be reset.
353 if (actionableMode
) {
354 me
.ownerGrid
.setActionableMode(false);
357 // Blur the focused descendant, but do not trigger focusLeave.
360 // Exiting actionable mode navigates to the owning cell, so in either focus mode we must
361 // clear the navigation position
362 navModel
.setPosition();
364 // The following function will attempt to refocus back in the same mode to the same cell
365 // as it was at before based upon the previous record (if it's still inthe store), or the row index.
367 // If we still have data, attempt to refocus in the same mode.
368 if (store
.getCount()) {
370 // Adjust expectations of where we are able to refocus according to what kind of destruction
371 // might have been wrought on this view's DOM during focus save.
372 refocusRow
= Math
.min(focusPosition
.rowIdx
, me
.all
.getCount() - 1);
373 refocusCol
= Math
.min(focusPosition
.colIdx
, me
.getVisibleColumnManager().getColumns().length
- 1);
374 focusPosition
= new Ext
.grid
.CellContext(me
).setPosition(
375 store
.contains(focusPosition
.record
) ? focusPosition
.record
: refocusRow
, refocusCol
);
377 if (actionableMode
) {
378 me
.ownerGrid
.setActionableMode(true, focusPosition
);
380 me
.cellFocused
= true;
382 // we sometimes want to scroll back to where we were
383 var x
= me
.getScrollX();
384 var y
= me
.getScrollY();
386 // Pass "preventNavigation" as true so that that does not cause selection.
387 navModel
.setPosition(focusPosition
, null, null, null, true);
389 if (!me
.jumpToFocus
) {
394 // No rows - focus associated column header
396 focusPosition
.column
.focus();
404 // should be fixed with ExtJS 6.0.2, see:
405 // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll
406 Ext
.define('Proxmox.Datepicker', {
407 override
: 'Ext.picker.Date',
408 hideMode
: 'visibility'
411 // ExtJS 6.0.1 has no setSubmitValue() (although you find it in the docs).
412 // Note: this.submitValue is a boolean flag, whereas getSubmitValue() returns
413 // data to be submitted.
414 Ext
.define('Proxmox.form.field.Text', {
415 override
: 'Ext.form.field.Text',
417 setSubmitValue: function(v
) {
418 this.submitValue
= v
;
422 // this should be fixed with ExtJS 6.0.2
423 // make mousescrolling work in firefox in the containers overflowhandler
425 override
: 'Ext.layout.container.boxOverflow.Scroller',
427 createWheelListener: function() {
430 me
.wheelListener
= me
.layout
.innerCt
.on('wheel', me
.onMouseWheelFirefox
, me
, {destroyable
: true});
432 me
.wheelListener
= me
.layout
.innerCt
.on('mousewheel', me
.onMouseWheel
, me
, {destroyable
: true});
436 // special wheel handler for firefox. differs from the default onMouseWheel
437 // handler by using deltaY instead of wheelDeltaY and no normalizing,
438 // because it is already
439 onMouseWheelFirefox: function(e
) {
441 var delta
= e
.browserEvent
.deltaY
|| 0;
442 this.scrollBy(delta
* this.wheelIncrement
, false);
447 // add '@' to the valid id
448 Ext
.define('Proxmox.validIdReOverride', {
449 override
: 'Ext.Component',
450 validIdRe
: /^[a-z_][a-z0-9\-_\@]*$/i,
453 // force alert boxes to be rendered with an Error Icon
454 // since Ext.Msg is an object and not a prototype, we need to override it
455 // after the framework has been initiated
456 Ext
.onReady(function() {
457 /*jslint confusion: true */
458 Ext
.override(Ext
.Msg
, {
459 alert: function(title
, message
, fn
, scope
) {
460 if (Ext
.isString(title
)) {
468 minWidth
: this.minWidth
470 return this.show(config
);
474 /*jslint confusion: false */
476 Ext
.define('Ext.ux.IFrame', {
477 extend
: 'Ext.Component',
479 alias
: 'widget.uxiframe',
481 loadMask
: 'Loading...',
486 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>'
488 childEls
: ['iframeEl'],
490 initComponent: function () {
493 this.frameName
= this.frameName
|| this.id
+ '-frame';
496 initEvents : function() {
499 me
.iframeEl
.on('load', me
.onLoad
, me
);
502 initRenderData: function() {
503 return Ext
.apply(this.callParent(), {
505 frameName
: this.frameName
509 getBody: function() {
510 var doc
= this.getDoc();
511 return doc
.body
|| doc
.documentElement
;
516 return this.getWin().document
;
526 ? me
.iframeEl
.dom
.contentWindow
527 : window
.frames
[name
];
531 getFrame: function() {
533 return me
.iframeEl
.dom
;
536 beforeDestroy: function () {
537 this.cleanupListeners(true);
541 cleanupListeners: function(destroying
){
548 /*jslint nomen: true*/
549 Ext
.get(doc
).un(this._docListeners
);
550 /*jslint nomen: false*/
551 if (destroying
&& doc
.hasOwnProperty
) {
553 if (doc
.hasOwnProperty(prop
)) {
566 fn
= me
.onRelayedEvent
;
570 // These events need to be relayed from the inner document (where they stop
571 // bubbling) up to the outer document. This has to be done at the DOM level so
572 // the event reaches listeners on elements like the document body. The effected
573 // mechanisms that depend on this bubbling behavior are listed to the right
575 /*jslint nomen: true*/
578 mousedown
: fn
, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
579 mousemove
: fn
, // window resize drag detection
580 mouseup
: fn
, // window resize termination
581 click
: fn
, // not sure, but just to be safe
582 dblclick
: fn
, // not sure again
586 /*jslint nomen: false*/
588 // cannot do this xss
591 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
592 Ext
.get(this.getWin()).on('beforeunload', me
.cleanupListeners
, me
);
595 this.fireEvent('load', this);
600 this.fireEvent('error', this);
606 onRelayedEvent: function (event
) {
607 // relay event from the iframe's document to the document that owns the iframe...
609 var iframeEl
= this.iframeEl
,
611 // Get the left-based iframe position
612 iframeXY
= iframeEl
.getTrueXY(),
613 originalEventXY
= event
.getXY(),
615 // Get the left-based XY position.
616 // This is because the consumer of the injected event will
617 // perform its own RTL normalization.
618 eventXY
= event
.getTrueXY();
620 // the event from the inner document has XY relative to that document's origin,
621 // so adjust it to use the origin of the iframe in the outer document:
622 event
.xy
= [iframeXY
[0] + eventXY
[0], iframeXY
[1] + eventXY
[1]];
624 event
.injectEvent(iframeEl
); // blame the iframe for the event...
626 event
.xy
= originalEventXY
; // restore the original XY (just for safety)
629 load: function (src
) {
632 frame
= me
.getFrame();
634 if (me
.fireEvent('beforeload', me
, src
) !== false) {
639 frame
.src
= me
.src
= (src
|| me
.src
);