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