]>
Commit | Line | Data |
---|---|---|
1 | // ExtJS related things | |
2 | ||
3 | // do not send '_dc' parameter | |
4 | Ext.Ajax.disableCaching = false; | |
5 | ||
6 | // custom Vtypes | |
7 | Ext.apply(Ext.form.field.VTypes, { | |
8 | IPAddress: function(v) { | |
9 | return Proxmox.Utils.IP4_match.test(v); | |
10 | }, | |
11 | IPAddressText: gettext('Example') + ': 192.168.1.1', | |
12 | IPAddressMask: /[\d\.]/i, | |
13 | ||
14 | IPCIDRAddress: function(v) { | |
15 | var 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); | |
19 | }, | |
20 | IPCIDRAddressText: gettext('Example') + ': 192.168.1.1/24' + "<br>" + gettext('Valid CIDR Range') + ': 8-32', | |
21 | IPCIDRAddressMask: /[\d\.\/]/i, | |
22 | ||
23 | IP6Address: function(v) { | |
24 | return Proxmox.Utils.IP6_match.test(v); | |
25 | }, | |
26 | IP6AddressText: gettext('Example') + ': 2001:DB8::42', | |
27 | IP6AddressMask: /[A-Fa-f0-9:]/, | |
28 | ||
29 | IP6CIDRAddress: function(v) { | |
30 | var 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] <= 120); | |
34 | }, | |
35 | IP6CIDRAddressText: gettext('Example') + ': 2001:DB8::42/64' + "<br>" + gettext('Valid CIDR Range') + ': 8-120', | |
36 | IP6CIDRAddressMask: /[A-Fa-f0-9:\/]/, | |
37 | ||
38 | IP6PrefixLength: function(v) { | |
39 | return v >= 0 && v <= 128; | |
40 | }, | |
41 | IP6PrefixLengthText: gettext('Example') + ': X, where 0 <= X <= 128', | |
42 | IP6PrefixLengthMask: /[0-9]/, | |
43 | ||
44 | IP64Address: function(v) { | |
45 | return Proxmox.Utils.IP64_match.test(v); | |
46 | }, | |
47 | IP64AddressText: gettext('Example') + ': 192.168.1.1 2001:DB8::42', | |
48 | IP64AddressMask: /[A-Fa-f0-9\.:]/, | |
49 | ||
50 | MacAddress: function(v) { | |
51 | return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v); | |
52 | }, | |
53 | MacAddressMask: /[a-fA-F0-9:]/, | |
54 | MacAddressText: gettext('Example') + ': 01:23:45:67:89:ab', | |
55 | ||
56 | MacPrefix: function(v) { | |
57 | return (/^[a-f0-9]{2}(?::[a-f0-9]{2}){0,2}:?$/i).test(v); | |
58 | }, | |
59 | MacPrefixMask: /[a-fA-F0-9:]/, | |
60 | MacPrefixText: gettext('Example') + ': 02:8f', | |
61 | ||
62 | BridgeName: function(v) { | |
63 | return (/^vmbr\d{1,4}$/).test(v); | |
64 | }, | |
65 | BridgeNameText: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999', | |
66 | ||
67 | BondName: function(v) { | |
68 | return (/^bond\d{1,4}$/).test(v); | |
69 | }, | |
70 | BondNameText: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999', | |
71 | ||
72 | InterfaceName: function(v) { | |
73 | return (/^[a-z][a-z0-9_]{1,20}$/).test(v); | |
74 | }, | |
75 | InterfaceNameText: gettext("Allowed characters") + ": 'a-z', '0-9', '_'" + "<br />" + | |
76 | gettext("Minimum characters") + ": 2" + "<br />" + | |
77 | gettext("Maximum characters") + ": 21" + "<br />" + | |
78 | gettext("Must start with") + ": 'a-z'", | |
79 | ||
80 | StorageId: function(v) { | |
81 | return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v); | |
82 | }, | |
83 | StorageIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'" + "<br />" + | |
84 | gettext("Minimum characters") + ": 2" + "<br />" + | |
85 | gettext("Must start with") + ": 'A-Z', 'a-z'<br />" + | |
86 | gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />", | |
87 | ||
88 | ConfigId: function(v) { | |
89 | return (/^[a-z][a-z0-9\_]+$/i).test(v); | |
90 | }, | |
91 | ConfigIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'" + "<br />" + | |
92 | gettext("Minimum characters") + ": 2" + "<br />" + | |
93 | gettext("Must start with") + ": " + gettext("letter"), | |
94 | ||
95 | HttpProxy: function(v) { | |
96 | return (/^http:\/\/.*$/).test(v); | |
97 | }, | |
98 | HttpProxyText: gettext('Example') + ": http://username:password@host:port/", | |
99 | ||
100 | DnsName: function(v) { | |
101 | return Proxmox.Utils.DnsName_match.test(v); | |
102 | }, | |
103 | DnsNameText: gettext('This is not a valid DNS name'), | |
104 | ||
105 | // workaround for https://www.sencha.com/forum/showthread.php?302150 | |
106 | proxmoxMail: function(v) { | |
107 | return (/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v); | |
108 | }, | |
109 | proxmoxMailText: gettext('Example') + ": user@example.com", | |
110 | ||
111 | DnsOrIp: function(v) { | |
112 | if (!Proxmox.Utils.DnsName_match.test(v) && | |
113 | !Proxmox.Utils.IP64_match.test(v)) { | |
114 | return false; | |
115 | } | |
116 | ||
117 | return true; | |
118 | }, | |
119 | DnsOrIpText: gettext('Not a valid DNS name or IP address.'), | |
120 | ||
121 | HostList: function(v) { | |
122 | var list = v.split(/[\ \,\;]+/); | |
123 | var i; | |
124 | for (i = 0; i < list.length; i++) { | |
125 | if (list[i] == "") { | |
126 | continue; | |
127 | } | |
128 | ||
129 | if (!Proxmox.Utils.HostPort_match.test(list[i]) && | |
130 | !Proxmox.Utils.HostPortBrackets_match.test(list[i]) && | |
131 | !Proxmox.Utils.IP6_dotnotation_match.test(list[i])) { | |
132 | return false; | |
133 | } | |
134 | } | |
135 | ||
136 | return true; | |
137 | }, | |
138 | HostListText: gettext('Not a valid list of hosts'), | |
139 | ||
140 | password: function(val, field) { | |
141 | if (field.initialPassField) { | |
142 | var pwd = field.up('form').down( | |
143 | '[name=' + field.initialPassField + ']'); | |
144 | return (val == pwd.getValue()); | |
145 | } | |
146 | return true; | |
147 | }, | |
148 | ||
149 | passwordText: gettext('Passwords do not match') | |
150 | }); | |
151 | ||
152 | // Firefox 52+ Touchscreen bug | |
153 | // see https://www.sencha.com/forum/showthread.php?336762-Examples-don-t-work-in-Firefox-52-touchscreen/page2 | |
154 | // and https://bugzilla.proxmox.com/show_bug.cgi?id=1223 | |
155 | Ext.define('EXTJS_23846.Element', { | |
156 | override: 'Ext.dom.Element' | |
157 | }, function(Element) { | |
158 | var supports = Ext.supports, | |
159 | proto = Element.prototype, | |
160 | eventMap = proto.eventMap, | |
161 | additiveEvents = proto.additiveEvents; | |
162 | ||
163 | if (Ext.os.is.Desktop && supports.TouchEvents && !supports.PointerEvents) { | |
164 | eventMap.touchstart = 'mousedown'; | |
165 | eventMap.touchmove = 'mousemove'; | |
166 | eventMap.touchend = 'mouseup'; | |
167 | eventMap.touchcancel = 'mouseup'; | |
168 | ||
169 | additiveEvents.mousedown = 'mousedown'; | |
170 | additiveEvents.mousemove = 'mousemove'; | |
171 | additiveEvents.mouseup = 'mouseup'; | |
172 | additiveEvents.touchstart = 'touchstart'; | |
173 | additiveEvents.touchmove = 'touchmove'; | |
174 | additiveEvents.touchend = 'touchend'; | |
175 | additiveEvents.touchcancel = 'touchcancel'; | |
176 | ||
177 | additiveEvents.pointerdown = 'mousedown'; | |
178 | additiveEvents.pointermove = 'mousemove'; | |
179 | additiveEvents.pointerup = 'mouseup'; | |
180 | additiveEvents.pointercancel = 'mouseup'; | |
181 | } | |
182 | }); | |
183 | ||
184 | Ext.define('EXTJS_23846.Gesture', { | |
185 | override: 'Ext.event.publisher.Gesture' | |
186 | }, function(Gesture) { | |
187 | var me = Gesture.instance; | |
188 | ||
189 | if (Ext.supports.TouchEvents && !Ext.isWebKit && Ext.os.is.Desktop) { | |
190 | me.handledDomEvents.push('mousedown', 'mousemove', 'mouseup'); | |
191 | me.registerEvents(); | |
192 | } | |
193 | }); | |
194 | ||
195 | // we always want the number in x.y format and never in, e.g., x,y | |
196 | Ext.define('PVE.form.field.Number', { | |
197 | override: 'Ext.form.field.Number', | |
198 | submitLocaleSeparator: false | |
199 | }); | |
200 | ||
201 | // ExtJs 5-6 has an issue with caching | |
202 | // see https://www.sencha.com/forum/showthread.php?308989 | |
203 | Ext.define('Proxmox.UnderlayPool', { | |
204 | override: 'Ext.dom.UnderlayPool', | |
205 | ||
206 | checkOut: function () { | |
207 | var cache = this.cache, | |
208 | len = cache.length, | |
209 | el; | |
210 | ||
211 | // do cleanup because some of the objects might have been destroyed | |
212 | while (len--) { | |
213 | if (cache[len].destroyed) { | |
214 | cache.splice(len, 1); | |
215 | } | |
216 | } | |
217 | // end do cleanup | |
218 | ||
219 | el = cache.shift(); | |
220 | ||
221 | if (!el) { | |
222 | el = Ext.Element.create(this.elementConfig); | |
223 | el.setVisibilityMode(2); | |
224 | //<debug> | |
225 | // tell the spec runner to ignore this element when checking if the dom is clean | |
226 | el.dom.setAttribute('data-sticky', true); | |
227 | //</debug> | |
228 | } | |
229 | ||
230 | return el; | |
231 | } | |
232 | }); | |
233 | ||
234 | // 'Enter' in Textareas and aria multiline fields should not activate the | |
235 | // defaultbutton, fixed in extjs 6.0.2 | |
236 | Ext.define('PVE.panel.Panel', { | |
237 | override: 'Ext.panel.Panel', | |
238 | ||
239 | fireDefaultButton: function(e) { | |
240 | if (e.target.getAttribute('aria-multiline') === 'true' || | |
241 | e.target.tagName === "TEXTAREA") { | |
242 | return true; | |
243 | } | |
244 | return this.callParent(arguments); | |
245 | } | |
246 | }); | |
247 | ||
248 | // if the order of the values are not the same in originalValue and value | |
249 | // extjs will not overwrite value, but marks the field dirty and thus | |
250 | // the reset button will be enabled (but clicking it changes nothing) | |
251 | // so if the arrays are not the same after resetting, we | |
252 | // clear and set it | |
253 | Ext.define('Proxmox.form.ComboBox', { | |
254 | override: 'Ext.form.field.ComboBox', | |
255 | ||
256 | reset: function() { | |
257 | // copied from combobox | |
258 | var me = this; | |
259 | me.callParent(); | |
260 | ||
261 | // clear and set when not the same | |
262 | var value = me.getValue(); | |
263 | if (Ext.isArray(me.originalValue) && Ext.isArray(value) && !Ext.Array.equals(value, me.originalValue)) { | |
264 | me.clearValue(); | |
265 | me.setValue(me.originalValue); | |
266 | } | |
267 | } | |
268 | }); | |
269 | ||
270 | // when refreshing a grid/tree view, restoring the focus moves the view back to | |
271 | // the previously focused item. Save scroll position before refocusing. | |
272 | Ext.define(null, { | |
273 | override: 'Ext.view.Table', | |
274 | ||
275 | jumpToFocus: false, | |
276 | ||
277 | saveFocusState: function() { | |
278 | var me = this, | |
279 | store = me.dataSource, | |
280 | actionableMode = me.actionableMode, | |
281 | navModel = me.getNavigationModel(), | |
282 | focusPosition = actionableMode ? me.actionPosition : navModel.getPosition(true), | |
283 | refocusRow, refocusCol; | |
284 | ||
285 | if (focusPosition) { | |
286 | // Separate this from the instance that the nav model is using. | |
287 | focusPosition = focusPosition.clone(); | |
288 | ||
289 | // Exit actionable mode. | |
290 | // We must inform any Actionables that they must relinquish control. | |
291 | // Tabbability must be reset. | |
292 | if (actionableMode) { | |
293 | me.ownerGrid.setActionableMode(false); | |
294 | } | |
295 | ||
296 | // Blur the focused descendant, but do not trigger focusLeave. | |
297 | me.el.dom.focus(); | |
298 | ||
299 | // Exiting actionable mode navigates to the owning cell, so in either focus mode we must | |
300 | // clear the navigation position | |
301 | navModel.setPosition(); | |
302 | ||
303 | // The following function will attempt to refocus back in the same mode to the same cell | |
304 | // as it was at before based upon the previous record (if it's still inthe store), or the row index. | |
305 | return function() { | |
306 | // If we still have data, attempt to refocus in the same mode. | |
307 | if (store.getCount()) { | |
308 | ||
309 | // Adjust expectations of where we are able to refocus according to what kind of destruction | |
310 | // might have been wrought on this view's DOM during focus save. | |
311 | refocusRow = Math.min(focusPosition.rowIdx, me.all.getCount() - 1); | |
312 | refocusCol = Math.min(focusPosition.colIdx, me.getVisibleColumnManager().getColumns().length - 1); | |
313 | focusPosition = new Ext.grid.CellContext(me).setPosition( | |
314 | store.contains(focusPosition.record) ? focusPosition.record : refocusRow, refocusCol); | |
315 | ||
316 | if (actionableMode) { | |
317 | me.ownerGrid.setActionableMode(true, focusPosition); | |
318 | } else { | |
319 | me.cellFocused = true; | |
320 | ||
321 | // we sometimes want to scroll back to where we were | |
322 | var x = me.getScrollX(); | |
323 | var y = me.getScrollY(); | |
324 | ||
325 | // Pass "preventNavigation" as true so that that does not cause selection. | |
326 | navModel.setPosition(focusPosition, null, null, null, true); | |
327 | ||
328 | if (!me.jumpToFocus) { | |
329 | me.scrollTo(x,y); | |
330 | } | |
331 | } | |
332 | } | |
333 | // No rows - focus associated column header | |
334 | else { | |
335 | focusPosition.column.focus(); | |
336 | } | |
337 | }; | |
338 | } | |
339 | return Ext.emptyFn; | |
340 | } | |
341 | }); | |
342 | ||
343 | // should be fixed with ExtJS 6.0.2, see: | |
344 | // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll | |
345 | Ext.define('Proxmox.Datepicker', { | |
346 | override: 'Ext.picker.Date', | |
347 | hideMode: 'visibility' | |
348 | }); | |
349 | ||
350 | // ExtJS 6.0.1 has no setSubmitValue() (although you find it in the docs). | |
351 | // Note: this.submitValue is a boolean flag, whereas getSubmitValue() returns | |
352 | // data to be submitted. | |
353 | Ext.define('Proxmox.form.field.Text', { | |
354 | override: 'Ext.form.field.Text', | |
355 | ||
356 | setSubmitValue: function(v) { | |
357 | this.submitValue = v; | |
358 | }, | |
359 | }); | |
360 | ||
361 | // this should be fixed with ExtJS 6.0.2 | |
362 | // make mousescrolling work in firefox in the containers overflowhandler | |
363 | Ext.define(null, { | |
364 | override: 'Ext.layout.container.boxOverflow.Scroller', | |
365 | ||
366 | createWheelListener: function() { | |
367 | var me = this; | |
368 | if (Ext.isFirefox) { | |
369 | me.wheelListener = me.layout.innerCt.on('wheel', me.onMouseWheelFirefox, me, {destroyable: true}); | |
370 | } else { | |
371 | me.wheelListener = me.layout.innerCt.on('mousewheel', me.onMouseWheel, me, {destroyable: true}); | |
372 | } | |
373 | }, | |
374 | ||
375 | // special wheel handler for firefox. differs from the default onMouseWheel | |
376 | // handler by using deltaY instead of wheelDeltaY and no normalizing, | |
377 | // because it is already | |
378 | onMouseWheelFirefox: function(e) { | |
379 | e.stopEvent(); | |
380 | var delta = e.browserEvent.deltaY || 0; | |
381 | this.scrollBy(delta * this.wheelIncrement, false); | |
382 | } | |
383 | ||
384 | }); | |
385 | ||
386 | // force alert boxes to be rendered with an Error Icon | |
387 | // since Ext.Msg is an object and not a prototype, we need to override it | |
388 | // after the framework has been initiated | |
389 | Ext.onReady(function() { | |
390 | /*jslint confusion: true */ | |
391 | Ext.override(Ext.Msg, { | |
392 | alert: function(title, message, fn, scope) { | |
393 | if (Ext.isString(title)) { | |
394 | var config = { | |
395 | title: title, | |
396 | message: message, | |
397 | icon: this.ERROR, | |
398 | buttons: this.OK, | |
399 | fn: fn, | |
400 | scope : scope, | |
401 | minWidth: this.minWidth | |
402 | }; | |
403 | return this.show(config); | |
404 | } | |
405 | } | |
406 | }); | |
407 | /*jslint confusion: false */ | |
408 | }); | |
409 | Ext.define('Ext.ux.IFrame', { | |
410 | extend: 'Ext.Component', | |
411 | ||
412 | alias: 'widget.uxiframe', | |
413 | ||
414 | loadMask: 'Loading...', | |
415 | ||
416 | src: 'about:blank', | |
417 | ||
418 | renderTpl: [ | |
419 | '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>' | |
420 | ], | |
421 | childEls: ['iframeEl'], | |
422 | ||
423 | initComponent: function () { | |
424 | this.callParent(); | |
425 | ||
426 | this.frameName = this.frameName || this.id + '-frame'; | |
427 | }, | |
428 | ||
429 | initEvents : function() { | |
430 | var me = this; | |
431 | me.callParent(); | |
432 | me.iframeEl.on('load', me.onLoad, me); | |
433 | }, | |
434 | ||
435 | initRenderData: function() { | |
436 | return Ext.apply(this.callParent(), { | |
437 | src: this.src, | |
438 | frameName: this.frameName | |
439 | }); | |
440 | }, | |
441 | ||
442 | getBody: function() { | |
443 | var doc = this.getDoc(); | |
444 | return doc.body || doc.documentElement; | |
445 | }, | |
446 | ||
447 | getDoc: function() { | |
448 | try { | |
449 | return this.getWin().document; | |
450 | } catch (ex) { | |
451 | return null; | |
452 | } | |
453 | }, | |
454 | ||
455 | getWin: function() { | |
456 | var me = this, | |
457 | name = me.frameName, | |
458 | win = Ext.isIE | |
459 | ? me.iframeEl.dom.contentWindow | |
460 | : window.frames[name]; | |
461 | return win; | |
462 | }, | |
463 | ||
464 | getFrame: function() { | |
465 | var me = this; | |
466 | return me.iframeEl.dom; | |
467 | }, | |
468 | ||
469 | beforeDestroy: function () { | |
470 | this.cleanupListeners(true); | |
471 | this.callParent(); | |
472 | }, | |
473 | ||
474 | cleanupListeners: function(destroying){ | |
475 | var doc, prop; | |
476 | ||
477 | if (this.rendered) { | |
478 | try { | |
479 | doc = this.getDoc(); | |
480 | if (doc) { | |
481 | /*jslint nomen: true*/ | |
482 | Ext.get(doc).un(this._docListeners); | |
483 | /*jslint nomen: false*/ | |
484 | if (destroying && doc.hasOwnProperty) { | |
485 | for (prop in doc) { | |
486 | if (doc.hasOwnProperty(prop)) { | |
487 | delete doc[prop]; | |
488 | } | |
489 | } | |
490 | } | |
491 | } | |
492 | } catch(e) { } | |
493 | } | |
494 | }, | |
495 | ||
496 | onLoad: function() { | |
497 | var me = this, | |
498 | doc = me.getDoc(), | |
499 | fn = me.onRelayedEvent; | |
500 | ||
501 | if (doc) { | |
502 | try { | |
503 | // These events need to be relayed from the inner document (where they stop | |
504 | // bubbling) up to the outer document. This has to be done at the DOM level so | |
505 | // the event reaches listeners on elements like the document body. The effected | |
506 | // mechanisms that depend on this bubbling behavior are listed to the right | |
507 | // of the event. | |
508 | /*jslint nomen: true*/ | |
509 | Ext.get(doc).on( | |
510 | me._docListeners = { | |
511 | mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront) | |
512 | mousemove: fn, // window resize drag detection | |
513 | mouseup: fn, // window resize termination | |
514 | click: fn, // not sure, but just to be safe | |
515 | dblclick: fn, // not sure again | |
516 | scope: me | |
517 | } | |
518 | ); | |
519 | /*jslint nomen: false*/ | |
520 | } catch(e) { | |
521 | // cannot do this xss | |
522 | } | |
523 | ||
524 | // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK! | |
525 | Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me); | |
526 | ||
527 | this.el.unmask(); | |
528 | this.fireEvent('load', this); | |
529 | ||
530 | } else if (me.src) { | |
531 | ||
532 | this.el.unmask(); | |
533 | this.fireEvent('error', this); | |
534 | } | |
535 | ||
536 | ||
537 | }, | |
538 | ||
539 | onRelayedEvent: function (event) { | |
540 | // relay event from the iframe's document to the document that owns the iframe... | |
541 | ||
542 | var iframeEl = this.iframeEl, | |
543 | ||
544 | // Get the left-based iframe position | |
545 | iframeXY = iframeEl.getTrueXY(), | |
546 | originalEventXY = event.getXY(), | |
547 | ||
548 | // Get the left-based XY position. | |
549 | // This is because the consumer of the injected event will | |
550 | // perform its own RTL normalization. | |
551 | eventXY = event.getTrueXY(); | |
552 | ||
553 | // the event from the inner document has XY relative to that document's origin, | |
554 | // so adjust it to use the origin of the iframe in the outer document: | |
555 | event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]]; | |
556 | ||
557 | event.injectEvent(iframeEl); // blame the iframe for the event... | |
558 | ||
559 | event.xy = originalEventXY; // restore the original XY (just for safety) | |
560 | }, | |
561 | ||
562 | load: function (src) { | |
563 | var me = this, | |
564 | text = me.loadMask, | |
565 | frame = me.getFrame(); | |
566 | ||
567 | if (me.fireEvent('beforeload', me, src) !== false) { | |
568 | if (text && me.el) { | |
569 | me.el.mask(text); | |
570 | } | |
571 | ||
572 | frame.src = me.src = (src || me.src); | |
573 | } | |
574 | } | |
575 | }); |