]>
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 VlanName: function(v
) {
87 if (Proxmox
.Utils
.VlanInterface_match
.test(v
)) {
89 } else if (Proxmox
.Utils
.Vlan_match
.test(v
)) {
94 BridgeNameText
: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
96 BondName: function(v
) {
97 return (/^bond\d{1,4}$/).test(v
);
99 BondNameText
: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
101 InterfaceName: function(v
) {
102 return (/^[a-z][a-z0-9_]{1,20}$/).test(v
);
104 InterfaceNameText
: gettext("Allowed characters") + ": 'a-z', '0-9', '_'" + "<br />" +
105 gettext("Minimum characters") + ": 2" + "<br />" +
106 gettext("Maximum characters") + ": 21" + "<br />" +
107 gettext("Must start with") + ": 'a-z'",
109 StorageId: function(v
) {
110 return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v
);
112 StorageIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'" + "<br />" +
113 gettext("Minimum characters") + ": 2" + "<br />" +
114 gettext("Must start with") + ": 'A-Z', 'a-z'<br />" +
115 gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />",
117 ConfigId: function(v
) {
118 return (/^[a-z][a-z0-9\_]+$/i).test(v
);
120 ConfigIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'" + "<br />" +
121 gettext("Minimum characters") + ": 2" + "<br />" +
122 gettext("Must start with") + ": " + gettext("letter"),
124 HttpProxy: function(v
) {
125 return (/^http:\/\/.*$/).test(v
);
127 HttpProxyText
: gettext('Example') + ": http://username:password@host:port/",
129 DnsName: function(v
) {
130 return Proxmox
.Utils
.DnsName_match
.test(v
);
132 DnsNameText
: gettext('This is not a valid DNS name'),
134 // workaround for https://www.sencha.com/forum/showthread.php?302150
135 proxmoxMail: function(v
) {
136 return (/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v
);
138 proxmoxMailText
: gettext('Example') + ": user@example.com",
140 DnsOrIp: function(v
) {
141 if (!Proxmox
.Utils
.DnsName_match
.test(v
) &&
142 !Proxmox
.Utils
.IP64_match
.test(v
)) {
148 DnsOrIpText
: gettext('Not a valid DNS name or IP address.'),
150 HostList: function(v
) {
151 var list
= v
.split(/[\ \,\;]+/);
153 for (i
= 0; i
< list
.length
; i
++) {
158 if (!Proxmox
.Utils
.HostPort_match
.test(list
[i
]) &&
159 !Proxmox
.Utils
.HostPortBrackets_match
.test(list
[i
]) &&
160 !Proxmox
.Utils
.IP6_dotnotation_match
.test(list
[i
])) {
167 HostListText
: gettext('Not a valid list of hosts'),
169 password: function(val
, field
) {
170 if (field
.initialPassField
) {
171 var pwd
= field
.up('form').down(
172 '[name=' + field
.initialPassField
+ ']');
173 return (val
== pwd
.getValue());
178 passwordText
: gettext('Passwords do not match')
181 // Firefox 52+ Touchscreen bug
182 // see https://www.sencha.com/forum/showthread.php?336762-Examples-don-t-work-in-Firefox-52-touchscreen/page2
183 // and https://bugzilla.proxmox.com/show_bug.cgi?id=1223
184 Ext
.define('EXTJS_23846.Element', {
185 override
: 'Ext.dom.Element'
186 }, function(Element
) {
187 var supports
= Ext
.supports
,
188 proto
= Element
.prototype,
189 eventMap
= proto
.eventMap
,
190 additiveEvents
= proto
.additiveEvents
;
192 if (Ext
.os
.is
.Desktop
&& supports
.TouchEvents
&& !supports
.PointerEvents
) {
193 eventMap
.touchstart
= 'mousedown';
194 eventMap
.touchmove
= 'mousemove';
195 eventMap
.touchend
= 'mouseup';
196 eventMap
.touchcancel
= 'mouseup';
198 additiveEvents
.mousedown
= 'mousedown';
199 additiveEvents
.mousemove
= 'mousemove';
200 additiveEvents
.mouseup
= 'mouseup';
201 additiveEvents
.touchstart
= 'touchstart';
202 additiveEvents
.touchmove
= 'touchmove';
203 additiveEvents
.touchend
= 'touchend';
204 additiveEvents
.touchcancel
= 'touchcancel';
206 additiveEvents
.pointerdown
= 'mousedown';
207 additiveEvents
.pointermove
= 'mousemove';
208 additiveEvents
.pointerup
= 'mouseup';
209 additiveEvents
.pointercancel
= 'mouseup';
213 Ext
.define('EXTJS_23846.Gesture', {
214 override
: 'Ext.event.publisher.Gesture'
215 }, function(Gesture
) {
216 var me
= Gesture
.instance
;
218 if (Ext
.supports
.TouchEvents
&& !Ext
.isWebKit
&& Ext
.os
.is
.Desktop
) {
219 me
.handledDomEvents
.push('mousedown', 'mousemove', 'mouseup');
224 Ext
.define('EXTJS_18900.Pie', {
225 override
: 'Ext.chart.series.Pie',
228 betweenAngle: function (x
, a
, b
) {
229 var pp
= Math
.PI
* 2,
230 offset
= this.rotationOffset
;
236 if (!this.getClockwise()) {
250 // Normalize, so that both x and b are in the [0,360) interval.
258 // Because 360 * n angles will be normalized to 0,
259 // we need to treat b === 0 as a special case.
260 return x
< b
|| b
=== 0;
264 // we always want the number in x.y format and never in, e.g., x,y
265 Ext
.define('PVE.form.field.Number', {
266 override
: 'Ext.form.field.Number',
267 submitLocaleSeparator
: false
270 // ExtJs 5-6 has an issue with caching
271 // see https://www.sencha.com/forum/showthread.php?308989
272 Ext
.define('Proxmox.UnderlayPool', {
273 override
: 'Ext.dom.UnderlayPool',
275 checkOut: function () {
276 var cache
= this.cache
,
280 // do cleanup because some of the objects might have been destroyed
282 if (cache
[len
].destroyed
) {
283 cache
.splice(len
, 1);
291 el
= Ext
.Element
.create(this.elementConfig
);
292 el
.setVisibilityMode(2);
294 // tell the spec runner to ignore this element when checking if the dom is clean
295 el
.dom
.setAttribute('data-sticky', true);
303 // 'Enter' in Textareas and aria multiline fields should not activate the
304 // defaultbutton, fixed in extjs 6.0.2
305 Ext
.define('PVE.panel.Panel', {
306 override
: 'Ext.panel.Panel',
308 fireDefaultButton: function(e
) {
309 if (e
.target
.getAttribute('aria-multiline') === 'true' ||
310 e
.target
.tagName
=== "TEXTAREA") {
313 return this.callParent(arguments
);
317 // if the order of the values are not the same in originalValue and value
318 // extjs will not overwrite value, but marks the field dirty and thus
319 // the reset button will be enabled (but clicking it changes nothing)
320 // so if the arrays are not the same after resetting, we
322 Ext
.define('Proxmox.form.ComboBox', {
323 override
: 'Ext.form.field.ComboBox',
326 // copied from combobox
330 // clear and set when not the same
331 var value
= me
.getValue();
332 if (Ext
.isArray(me
.originalValue
) && Ext
.isArray(value
) && !Ext
.Array
.equals(value
, me
.originalValue
)) {
334 me
.setValue(me
.originalValue
);
338 // we also want to open the trigger on editable comboboxes by default
339 initComponent: function() {
344 // The trigger.picker causes first a focus event on the field then
345 // toggles the selection picker. Thus skip expanding in this case,
346 // else our focus listener expands and the picker.trigger then
347 // collapses it directly afterwards.
348 Ext
.override(me
.triggers
.picker
, {
349 onMouseDown: function(e
) {
350 // copied "should we focus" check from Ext.form.trigger.Trigger
351 if (e
.pointerType
!== 'touch' && !this.field
.owns(Ext
.Element
.getActiveElement())) {
352 me
.skip_expand_on_focus
= true;
354 this.callParent(arguments
);
358 me
.on("focus", function(combobox
) {
359 if (!combobox
.isExpanded
&& !combobox
.skip_expand_on_focus
) {
362 combobox
.skip_expand_on_focus
= false;
368 // when refreshing a grid/tree view, restoring the focus moves the view back to
369 // the previously focused item. Save scroll position before refocusing.
371 override
: 'Ext.view.Table',
375 saveFocusState: function() {
377 store
= me
.dataSource
,
378 actionableMode
= me
.actionableMode
,
379 navModel
= me
.getNavigationModel(),
380 focusPosition
= actionableMode
? me
.actionPosition
: navModel
.getPosition(true),
381 refocusRow
, refocusCol
;
384 // Separate this from the instance that the nav model is using.
385 focusPosition
= focusPosition
.clone();
387 // Exit actionable mode.
388 // We must inform any Actionables that they must relinquish control.
389 // Tabbability must be reset.
390 if (actionableMode
) {
391 me
.ownerGrid
.setActionableMode(false);
394 // Blur the focused descendant, but do not trigger focusLeave.
397 // Exiting actionable mode navigates to the owning cell, so in either focus mode we must
398 // clear the navigation position
399 navModel
.setPosition();
401 // The following function will attempt to refocus back in the same mode to the same cell
402 // as it was at before based upon the previous record (if it's still inthe store), or the row index.
404 // If we still have data, attempt to refocus in the same mode.
405 if (store
.getCount()) {
407 // Adjust expectations of where we are able to refocus according to what kind of destruction
408 // might have been wrought on this view's DOM during focus save.
409 refocusRow
= Math
.min(focusPosition
.rowIdx
, me
.all
.getCount() - 1);
410 refocusCol
= Math
.min(focusPosition
.colIdx
, me
.getVisibleColumnManager().getColumns().length
- 1);
411 focusPosition
= new Ext
.grid
.CellContext(me
).setPosition(
412 store
.contains(focusPosition
.record
) ? focusPosition
.record
: refocusRow
, refocusCol
);
414 if (actionableMode
) {
415 me
.ownerGrid
.setActionableMode(true, focusPosition
);
417 me
.cellFocused
= true;
419 // we sometimes want to scroll back to where we were
420 var x
= me
.getScrollX();
421 var y
= me
.getScrollY();
423 // Pass "preventNavigation" as true so that that does not cause selection.
424 navModel
.setPosition(focusPosition
, null, null, null, true);
426 if (!me
.jumpToFocus
) {
431 // No rows - focus associated column header
433 focusPosition
.column
.focus();
441 // should be fixed with ExtJS 6.0.2, see:
442 // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll
443 Ext
.define('Proxmox.Datepicker', {
444 override
: 'Ext.picker.Date',
445 hideMode
: 'visibility'
448 // ExtJS 6.0.1 has no setSubmitValue() (although you find it in the docs).
449 // Note: this.submitValue is a boolean flag, whereas getSubmitValue() returns
450 // data to be submitted.
451 Ext
.define('Proxmox.form.field.Text', {
452 override
: 'Ext.form.field.Text',
454 setSubmitValue: function(v
) {
455 this.submitValue
= v
;
459 // this should be fixed with ExtJS 6.0.2
460 // make mousescrolling work in firefox in the containers overflowhandler
462 override
: 'Ext.layout.container.boxOverflow.Scroller',
464 createWheelListener: function() {
467 me
.wheelListener
= me
.layout
.innerCt
.on('wheel', me
.onMouseWheelFirefox
, me
, {destroyable
: true});
469 me
.wheelListener
= me
.layout
.innerCt
.on('mousewheel', me
.onMouseWheel
, me
, {destroyable
: true});
473 // special wheel handler for firefox. differs from the default onMouseWheel
474 // handler by using deltaY instead of wheelDeltaY and no normalizing,
475 // because it is already
476 onMouseWheelFirefox: function(e
) {
478 var delta
= e
.browserEvent
.deltaY
|| 0;
479 this.scrollBy(delta
* this.wheelIncrement
, false);
484 // add '@' to the valid id
485 Ext
.define('Proxmox.validIdReOverride', {
486 override
: 'Ext.Component',
487 validIdRe
: /^[a-z_][a-z0-9\-_\@]*$/i,
490 // force alert boxes to be rendered with an Error Icon
491 // since Ext.Msg is an object and not a prototype, we need to override it
492 // after the framework has been initiated
493 Ext
.onReady(function() {
494 /*jslint confusion: true */
495 Ext
.override(Ext
.Msg
, {
496 alert: function(title
, message
, fn
, scope
) {
497 if (Ext
.isString(title
)) {
505 minWidth
: this.minWidth
507 return this.show(config
);
511 /*jslint confusion: false */
513 Ext
.define('Ext.ux.IFrame', {
514 extend
: 'Ext.Component',
516 alias
: 'widget.uxiframe',
518 loadMask
: 'Loading...',
523 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>'
525 childEls
: ['iframeEl'],
527 initComponent: function () {
530 this.frameName
= this.frameName
|| this.id
+ '-frame';
533 initEvents : function() {
536 me
.iframeEl
.on('load', me
.onLoad
, me
);
539 initRenderData: function() {
540 return Ext
.apply(this.callParent(), {
542 frameName
: this.frameName
546 getBody: function() {
547 var doc
= this.getDoc();
548 return doc
.body
|| doc
.documentElement
;
553 return this.getWin().document
;
563 ? me
.iframeEl
.dom
.contentWindow
564 : window
.frames
[name
];
568 getFrame: function() {
570 return me
.iframeEl
.dom
;
573 beforeDestroy: function () {
574 this.cleanupListeners(true);
578 cleanupListeners: function(destroying
){
585 /*jslint nomen: true*/
586 Ext
.get(doc
).un(this._docListeners
);
587 /*jslint nomen: false*/
588 if (destroying
&& doc
.hasOwnProperty
) {
590 if (doc
.hasOwnProperty(prop
)) {
603 fn
= me
.onRelayedEvent
;
607 // These events need to be relayed from the inner document (where they stop
608 // bubbling) up to the outer document. This has to be done at the DOM level so
609 // the event reaches listeners on elements like the document body. The effected
610 // mechanisms that depend on this bubbling behavior are listed to the right
612 /*jslint nomen: true*/
615 mousedown
: fn
, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
616 mousemove
: fn
, // window resize drag detection
617 mouseup
: fn
, // window resize termination
618 click
: fn
, // not sure, but just to be safe
619 dblclick
: fn
, // not sure again
623 /*jslint nomen: false*/
625 // cannot do this xss
628 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
629 Ext
.get(this.getWin()).on('beforeunload', me
.cleanupListeners
, me
);
632 this.fireEvent('load', this);
637 this.fireEvent('error', this);
643 onRelayedEvent: function (event
) {
644 // relay event from the iframe's document to the document that owns the iframe...
646 var iframeEl
= this.iframeEl
,
648 // Get the left-based iframe position
649 iframeXY
= iframeEl
.getTrueXY(),
650 originalEventXY
= event
.getXY(),
652 // Get the left-based XY position.
653 // This is because the consumer of the injected event will
654 // perform its own RTL normalization.
655 eventXY
= event
.getTrueXY();
657 // the event from the inner document has XY relative to that document's origin,
658 // so adjust it to use the origin of the iframe in the outer document:
659 event
.xy
= [iframeXY
[0] + eventXY
[0], iframeXY
[1] + eventXY
[1]];
661 event
.injectEvent(iframeEl
); // blame the iframe for the event...
663 event
.xy
= originalEventXY
; // restore the original XY (just for safety)
666 load: function (src
) {
669 frame
= me
.getFrame();
671 if (me
.fireEvent('beforeload', me
, src
) !== false) {
676 frame
.src
= me
.src
= (src
|| me
.src
);