]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/Toolkit.js
1 // ExtJS related things
3 Proxmox
.Utils
.toolkit
= 'extjs';
5 // do not send '_dc' parameter
6 Ext
.Ajax
.disableCaching
= false;
9 Ext
.apply(Ext
.form
.field
.VTypes
, {
10 IPAddress: function(v
) {
11 return Proxmox
.Utils
.IP4_match
.test(v
);
13 IPAddressText
: gettext('Example') + ': 192.168.1.1',
14 IPAddressMask
: /[\d\.]/i,
16 IPCIDRAddress: function(v
) {
17 var result
= Proxmox
.Utils
.IP4_cidr_match
.exec(v
);
18 // limits according to JSON Schema see
19 // pve-common/src/PVE/JSONSchema.pm
20 return (result
!== null && result
[1] >= 8 && result
[1] <= 32);
22 IPCIDRAddressText
: gettext('Example') + ': 192.168.1.1/24' + "<br>" + gettext('Valid CIDR Range') + ': 8-32',
23 IPCIDRAddressMask
: /[\d\.\/]/i,
25 IP6Address: function(v
) {
26 return Proxmox
.Utils
.IP6_match
.test(v
);
28 IP6AddressText
: gettext('Example') + ': 2001:DB8::42',
29 IP6AddressMask
: /[A-Fa-f0-9:]/,
31 IP6CIDRAddress: function(v
) {
32 var result
= Proxmox
.Utils
.IP6_cidr_match
.exec(v
);
33 // limits according to JSON Schema see
34 // pve-common/src/PVE/JSONSchema.pm
35 return (result
!== null && result
[1] >= 8 && result
[1] <= 120);
37 IP6CIDRAddressText
: gettext('Example') + ': 2001:DB8::42/64' + "<br>" + gettext('Valid CIDR Range') + ': 8-120',
38 IP6CIDRAddressMask
: /[A-Fa-f0-9:\/]/,
40 IP6PrefixLength: function(v
) {
41 return v
>= 0 && v
<= 128;
43 IP6PrefixLengthText
: gettext('Example') + ': X, where 0 <= X <= 128',
44 IP6PrefixLengthMask
: /[0-9]/,
46 IP64Address: function(v
) {
47 return Proxmox
.Utils
.IP64_match
.test(v
);
49 IP64AddressText
: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
50 IP64AddressMask
: /[A-Fa-f0-9\.:]/,
52 MacAddress: function(v
) {
53 return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v
);
55 MacAddressMask
: /[a-fA-F0-9:]/,
56 MacAddressText
: gettext('Example') + ': 01:23:45:67:89:ab',
58 MacPrefix: function(v
) {
59 return (/^[a-f0-9]{2}(?::[a-f0-9]{2}){0,2}:?$/i).test(v
);
61 MacPrefixMask
: /[a-fA-F0-9:]/,
62 MacPrefixText
: gettext('Example') + ': 02:8f',
64 BridgeName: function(v
) {
65 return (/^vmbr\d{1,4}$/).test(v
);
67 BridgeNameText
: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
69 BondName: function(v
) {
70 return (/^bond\d{1,4}$/).test(v
);
72 BondNameText
: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
74 InterfaceName: function(v
) {
75 return (/^[a-z][a-z0-9_]{1,20}$/).test(v
);
77 InterfaceNameText
: gettext("Allowed characters") + ": 'a-z', '0-9', '_'" + "<br />" +
78 gettext("Minimum characters") + ": 2" + "<br />" +
79 gettext("Maximum characters") + ": 21" + "<br />" +
80 gettext("Must start with") + ": 'a-z'",
82 QemuStartDate: function(v
) {
83 return (/^(now|\d{4}-\d{1,2}-\d{1,2}(T\d{1,2}:\d{1,2}:\d{1,2})?)$/).test(v
);
85 QemuStartDateText
: gettext('Format') + ': "now" or "2006-06-17T16:01:21" or "2006-06-17"',
87 StorageId: function(v
) {
88 return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v
);
90 StorageIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'" + "<br />" +
91 gettext("Minimum characters") + ": 2" + "<br />" +
92 gettext("Must start with") + ": 'A-Z', 'a-z'<br />" +
93 gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />",
95 ConfigId: function(v
) {
96 return (/^[a-z][a-z0-9\_]+$/i).test(v
);
98 ConfigIdText
: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'" + "<br />" +
99 gettext("Minimum characters") + ": 2" + "<br />" +
100 gettext("Must start with") + ": " + gettext("letter"),
102 HttpProxy: function(v
) {
103 return (/^http:\/\/.*$/).test(v
);
105 HttpProxyText
: gettext('Example') + ": http://username:password@host:port/",
107 DnsName: function(v
) {
108 return Proxmox
.Utils
.DnsName_match
.test(v
);
110 DnsNameText
: gettext('This is not a valid DNS name'),
112 // workaround for https://www.sencha.com/forum/showthread.php?302150
113 pveMail: function(v
) {
114 return (/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v
);
116 pveMailText
: gettext('Example') + ": user@example.com",
118 HostList: function(v
) {
119 var list
= v
.split(/[\ \,\;]+/);
121 for (i
= 0; i
< list
.length
; i
++) {
126 if (!Proxmox
.Utils
.HostPort_match
.test(list
[i
]) &&
127 !Proxmox
.Utils
.HostPortBrackets_match
.test(list
[i
]) &&
128 !Proxmox
.Utils
.IP6_dotnotation_match
.test(list
[i
])) {
135 HostListText
: gettext('Not a valid list of hosts')
138 // since we always want the number in
139 // x.y format and never in e.g. x,y
140 Ext
.define('PVE.form.field.Number', {
141 override
: 'Ext.form.field.Number',
142 submitLocaleSeparator
: false
145 // ExtJs 5-6 has an issue with caching
146 // see https://www.sencha.com/forum/showthread.php?308989
147 Ext
.define('PVE.UnderlayPool', {
148 override
: 'Ext.dom.UnderlayPool',
150 checkOut: function () {
151 var cache
= this.cache
,
155 // do cleanup because some of the objects might have been destroyed
157 if (cache
[len
].destroyed
) {
158 cache
.splice(len
, 1);
166 el
= Ext
.Element
.create(this.elementConfig
);
167 el
.setVisibilityMode(2);
169 // tell the spec runner to ignore this element when checking if the dom is clean
170 el
.dom
.setAttribute('data-sticky', true);
178 // 'Enter' in Textareas and aria multiline fields should not activate the
179 // defaultbutton, fixed in extjs 6.0.2
180 Ext
.define('PVE.panel.Panel', {
181 override
: 'Ext.panel.Panel',
183 fireDefaultButton: function(e
) {
184 if (e
.target
.getAttribute('aria-multiline') === 'true' ||
185 e
.target
.tagName
=== "TEXTAREA") {
188 return this.callParent(arguments
);
192 // if the order of the values are not the same in originalValue and value
193 // extjs will not overwrite value, but marks the field dirty and thus
194 // the reset button will be enabled (but clicking it changes nothing)
195 // so if the arrays are not the same after resetting, we
197 Ext
.define('PVE.form.ComboBox', {
198 override
: 'Ext.form.field.ComboBox',
201 // copied from combobox
205 // clear and set when not the same
206 var value
= me
.getValue();
207 if (Ext
.isArray(me
.originalValue
) && Ext
.isArray(value
) && !Ext
.Array
.equals(value
, me
.originalValue
)) {
209 me
.setValue(me
.originalValue
);
214 // when refreshing the view of a grid/tree
215 // the restoring of the focus brings the
216 // focused item back in the view, even when we scrolled away
218 override
: 'Ext.view.Table',
222 saveFocusState: function() {
224 store
= me
.dataSource
,
225 actionableMode
= me
.actionableMode
,
226 navModel
= me
.getNavigationModel(),
227 focusPosition
= actionableMode
? me
.actionPosition
: navModel
.getPosition(true),
228 refocusRow
, refocusCol
;
231 // Separate this from the instance that the nav model is using.
232 focusPosition
= focusPosition
.clone();
234 // Exit actionable mode.
235 // We must inform any Actionables that they must relinquish control.
236 // Tabbability must be reset.
237 if (actionableMode
) {
238 me
.ownerGrid
.setActionableMode(false);
241 // Blur the focused descendant, but do not trigger focusLeave.
244 // Exiting actionable mode navigates to the owning cell, so in either focus mode we must
245 // clear the navigation position
246 navModel
.setPosition();
248 // The following function will attempt to refocus back in the same mode to the same cell
249 // as it was at before based upon the previous record (if it's still inthe store), or the row index.
251 // If we still have data, attempt to refocus in the same mode.
252 if (store
.getCount()) {
254 // Adjust expectations of where we are able to refocus according to what kind of destruction
255 // might have been wrought on this view's DOM during focus save.
256 refocusRow
= Math
.min(focusPosition
.rowIdx
, me
.all
.getCount() - 1);
257 refocusCol
= Math
.min(focusPosition
.colIdx
, me
.getVisibleColumnManager().getColumns().length
- 1);
258 focusPosition
= new Ext
.grid
.CellContext(me
).setPosition(
259 store
.contains(focusPosition
.record
) ? focusPosition
.record
: refocusRow
, refocusCol
);
261 if (actionableMode
) {
262 me
.ownerGrid
.setActionableMode(true, focusPosition
);
264 me
.cellFocused
= true;
266 // we sometimes want to scroll back to where we were
267 var x
= me
.getScrollX();
268 var y
= me
.getScrollY();
270 // Pass "preventNavigation" as true so that that does not cause selection.
271 navModel
.setPosition(focusPosition
, null, null, null, true);
273 if (!me
.jumpToFocus
) {
278 // No rows - focus associated column header
280 focusPosition
.column
.focus();
288 // should be fixed with ExtJS 6.0.2, see:
289 // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll
290 Ext
.define('PVE.Datepicker', {
291 override
: 'Ext.picker.Date',
292 hideMode
: 'visibility'
295 // this should be fixed with ExtJS 6.0.2
296 // this makes mousescrolling work in firefox in the overflowhandler
297 // and does not change behaviour in any other browser
299 override
: 'Ext.layout.container.boxOverflow.Scroller',
301 createWheelListener: function() {
304 me
.wheelListener
= me
.layout
.innerCt
.on('wheel', me
.onMouseWheelFirefox
, me
, {destroyable
: true});
306 me
.wheelListener
= me
.layout
.innerCt
.on('mousewheel', me
.onMouseWheel
, me
, {destroyable
: true});
310 // special wheel handler for firefox
311 // nearly the same as the default onMouseWheel handler,
312 // but using deltaY instead of wheelDeltaY
313 // and no normalizing, because it is already normalized
314 onMouseWheelFirefox: function(e
) {
316 var delta
= e
.browserEvent
.deltaY
|| 0;
317 this.scrollBy(delta
* this.wheelIncrement
, false);
322 // force alert boxes to be rendered with an Error Icon
323 // since Ext.Msg is an object and not a prototype, we need to override it
324 // after the framework has been initiated
325 Ext
.onReady(function() {
326 /*jslint confusion: true */
327 Ext
.override(Ext
.Msg
, {
328 alert: function(title
, message
, fn
, scope
) {
329 if (Ext
.isString(title
)) {
337 minWidth
: this.minWidth
339 return this.show(config
);
343 /*jslint confusion: false */
345 Ext
.define('Ext.ux.IFrame', {
346 extend
: 'Ext.Component',
348 alias
: 'widget.uxiframe',
350 loadMask
: 'Loading...',
355 '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>'
357 childEls
: ['iframeEl'],
359 initComponent: function () {
362 this.frameName
= this.frameName
|| this.id
+ '-frame';
365 initEvents : function() {
368 me
.iframeEl
.on('load', me
.onLoad
, me
);
371 initRenderData: function() {
372 return Ext
.apply(this.callParent(), {
374 frameName
: this.frameName
378 getBody: function() {
379 var doc
= this.getDoc();
380 return doc
.body
|| doc
.documentElement
;
385 return this.getWin().document
;
395 ? me
.iframeEl
.dom
.contentWindow
396 : window
.frames
[name
];
400 getFrame: function() {
402 return me
.iframeEl
.dom
;
405 beforeDestroy: function () {
406 this.cleanupListeners(true);
410 cleanupListeners: function(destroying
){
417 /*jslint nomen: true*/
418 Ext
.get(doc
).un(this._docListeners
);
419 /*jslint nomen: false*/
420 if (destroying
&& doc
.hasOwnProperty
) {
422 if (doc
.hasOwnProperty(prop
)) {
435 fn
= me
.onRelayedEvent
;
439 // These events need to be relayed from the inner document (where they stop
440 // bubbling) up to the outer document. This has to be done at the DOM level so
441 // the event reaches listeners on elements like the document body. The effected
442 // mechanisms that depend on this bubbling behavior are listed to the right
444 /*jslint nomen: true*/
447 mousedown
: fn
, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
448 mousemove
: fn
, // window resize drag detection
449 mouseup
: fn
, // window resize termination
450 click
: fn
, // not sure, but just to be safe
451 dblclick
: fn
, // not sure again
455 /*jslint nomen: false*/
457 // cannot do this xss
460 // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
461 Ext
.get(this.getWin()).on('beforeunload', me
.cleanupListeners
, me
);
464 this.fireEvent('load', this);
469 this.fireEvent('error', this);
475 onRelayedEvent: function (event
) {
476 // relay event from the iframe's document to the document that owns the iframe...
478 var iframeEl
= this.iframeEl
,
480 // Get the left-based iframe position
481 iframeXY
= iframeEl
.getTrueXY(),
482 originalEventXY
= event
.getXY(),
484 // Get the left-based XY position.
485 // This is because the consumer of the injected event will
486 // perform its own RTL normalization.
487 eventXY
= event
.getTrueXY();
489 // the event from the inner document has XY relative to that document's origin,
490 // so adjust it to use the origin of the iframe in the outer document:
491 event
.xy
= [iframeXY
[0] + eventXY
[0], iframeXY
[1] + eventXY
[1]];
493 event
.injectEvent(iframeEl
); // blame the iframe for the event...
495 event
.xy
= originalEventXY
; // restore the original XY (just for safety)
498 load: function (src
) {
501 frame
= me
.getFrame();
503 if (me
.fireEvent('beforeload', me
, src
) !== false) {
508 frame
.src
= me
.src
= (src
|| me
.src
);