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