]>
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 | ||
141 | // ExtJs 5-6 has an issue with caching | |
142 | // see https://www.sencha.com/forum/showthread.php?308989 | |
143 | Ext.define('Proxmox.UnderlayPool', { | |
144 | override: 'Ext.dom.UnderlayPool', | |
145 | ||
146 | checkOut: function () { | |
147 | var cache = this.cache, | |
148 | len = cache.length, | |
149 | el; | |
150 | ||
151 | // do cleanup because some of the objects might have been destroyed | |
152 | while (len--) { | |
153 | if (cache[len].destroyed) { | |
154 | cache.splice(len, 1); | |
155 | } | |
156 | } | |
157 | // end do cleanup | |
158 | ||
159 | el = cache.shift(); | |
160 | ||
161 | if (!el) { | |
162 | el = Ext.Element.create(this.elementConfig); | |
163 | el.setVisibilityMode(2); | |
164 | //<debug> | |
165 | // tell the spec runner to ignore this element when checking if the dom is clean | |
166 | el.dom.setAttribute('data-sticky', true); | |
167 | //</debug> | |
168 | } | |
169 | ||
170 | return el; | |
171 | } | |
172 | }); | |
173 | ||
a2d8b9a9 DC |
174 | // 'Enter' in Textareas and aria multiline fields should not activate the |
175 | // defaultbutton, fixed in extjs 6.0.2 | |
176 | Ext.define('PVE.panel.Panel', { | |
177 | override: 'Ext.panel.Panel', | |
178 | ||
179 | fireDefaultButton: function(e) { | |
180 | if (e.target.getAttribute('aria-multiline') === 'true' || | |
181 | e.target.tagName === "TEXTAREA") { | |
182 | return true; | |
183 | } | |
184 | return this.callParent(arguments); | |
185 | } | |
186 | }); | |
187 | ||
bb64de6e DM |
188 | // if the order of the values are not the same in originalValue and value |
189 | // extjs will not overwrite value, but marks the field dirty and thus | |
190 | // the reset button will be enabled (but clicking it changes nothing) | |
191 | // so if the arrays are not the same after resetting, we | |
192 | // clear and set it | |
193 | Ext.define('Proxmox.form.ComboBox', { | |
194 | override: 'Ext.form.field.ComboBox', | |
195 | ||
196 | reset: function() { | |
197 | // copied from combobox | |
198 | var me = this; | |
199 | me.callParent(); | |
200 | me.applyEmptyText(); | |
201 | ||
202 | // clear and set when not the same | |
203 | var value = me.getValue(); | |
204 | if (Ext.isArray(me.originalValue) && Ext.isArray(value) && !Ext.Array.equals(value, me.originalValue)) { | |
205 | me.clearValue(); | |
206 | me.setValue(me.originalValue); | |
207 | } | |
208 | } | |
209 | }); | |
210 | ||
211 | // should be fixed with ExtJS 6.0.2, see: | |
212 | // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll | |
213 | Ext.define('Proxmox.Datepicker', { | |
214 | override: 'Ext.picker.Date', | |
215 | hideMode: 'visibility' | |
216 | }); | |
217 | ||
a55813d6 DM |
218 | // ExtJS 6.0.1 has no setSubmitValue() (although you find it in the docs). |
219 | // Note: this.submitValue is a boolean flag, whereas getSubmitValue() returns | |
220 | // data to be submitted. | |
1d9804a9 DM |
221 | Ext.define('Proxmox.form.field.Text', { |
222 | override: 'Ext.form.field.Text', | |
223 | ||
224 | setSubmitValue: function(v) { | |
225 | this.submitValue = v; | |
226 | }, | |
1d9804a9 DM |
227 | }); |
228 | ||
bb64de6e DM |
229 | // force alert boxes to be rendered with an Error Icon |
230 | // since Ext.Msg is an object and not a prototype, we need to override it | |
231 | // after the framework has been initiated | |
232 | Ext.onReady(function() { | |
233 | /*jslint confusion: true */ | |
234 | Ext.override(Ext.Msg, { | |
235 | alert: function(title, message, fn, scope) { | |
236 | if (Ext.isString(title)) { | |
237 | var config = { | |
238 | title: title, | |
239 | message: message, | |
240 | icon: this.ERROR, | |
241 | buttons: this.OK, | |
242 | fn: fn, | |
243 | scope : scope, | |
244 | minWidth: this.minWidth | |
245 | }; | |
246 | return this.show(config); | |
247 | } | |
248 | } | |
249 | }); | |
250 | /*jslint confusion: false */ | |
251 | }); | |
252 | Ext.define('Ext.ux.IFrame', { | |
253 | extend: 'Ext.Component', | |
254 | ||
255 | alias: 'widget.uxiframe', | |
256 | ||
257 | loadMask: 'Loading...', | |
258 | ||
259 | src: 'about:blank', | |
260 | ||
261 | renderTpl: [ | |
262 | '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>' | |
263 | ], | |
264 | childEls: ['iframeEl'], | |
265 | ||
266 | initComponent: function () { | |
267 | this.callParent(); | |
268 | ||
269 | this.frameName = this.frameName || this.id + '-frame'; | |
270 | }, | |
271 | ||
272 | initEvents : function() { | |
273 | var me = this; | |
274 | me.callParent(); | |
275 | me.iframeEl.on('load', me.onLoad, me); | |
276 | }, | |
277 | ||
278 | initRenderData: function() { | |
279 | return Ext.apply(this.callParent(), { | |
280 | src: this.src, | |
281 | frameName: this.frameName | |
282 | }); | |
283 | }, | |
284 | ||
285 | getBody: function() { | |
286 | var doc = this.getDoc(); | |
287 | return doc.body || doc.documentElement; | |
288 | }, | |
289 | ||
290 | getDoc: function() { | |
291 | try { | |
292 | return this.getWin().document; | |
293 | } catch (ex) { | |
294 | return null; | |
295 | } | |
296 | }, | |
297 | ||
298 | getWin: function() { | |
299 | var me = this, | |
300 | name = me.frameName, | |
301 | win = Ext.isIE | |
302 | ? me.iframeEl.dom.contentWindow | |
303 | : window.frames[name]; | |
304 | return win; | |
305 | }, | |
306 | ||
307 | getFrame: function() { | |
308 | var me = this; | |
309 | return me.iframeEl.dom; | |
310 | }, | |
311 | ||
312 | beforeDestroy: function () { | |
313 | this.cleanupListeners(true); | |
314 | this.callParent(); | |
315 | }, | |
316 | ||
317 | cleanupListeners: function(destroying){ | |
318 | var doc, prop; | |
319 | ||
320 | if (this.rendered) { | |
321 | try { | |
322 | doc = this.getDoc(); | |
323 | if (doc) { | |
324 | /*jslint nomen: true*/ | |
325 | Ext.get(doc).un(this._docListeners); | |
326 | /*jslint nomen: false*/ | |
327 | if (destroying && doc.hasOwnProperty) { | |
328 | for (prop in doc) { | |
329 | if (doc.hasOwnProperty(prop)) { | |
330 | delete doc[prop]; | |
331 | } | |
332 | } | |
333 | } | |
334 | } | |
335 | } catch(e) { } | |
336 | } | |
337 | }, | |
338 | ||
339 | onLoad: function() { | |
340 | var me = this, | |
341 | doc = me.getDoc(), | |
342 | fn = me.onRelayedEvent; | |
343 | ||
344 | if (doc) { | |
345 | try { | |
346 | // These events need to be relayed from the inner document (where they stop | |
347 | // bubbling) up to the outer document. This has to be done at the DOM level so | |
348 | // the event reaches listeners on elements like the document body. The effected | |
349 | // mechanisms that depend on this bubbling behavior are listed to the right | |
350 | // of the event. | |
351 | /*jslint nomen: true*/ | |
352 | Ext.get(doc).on( | |
353 | me._docListeners = { | |
354 | mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront) | |
355 | mousemove: fn, // window resize drag detection | |
356 | mouseup: fn, // window resize termination | |
357 | click: fn, // not sure, but just to be safe | |
358 | dblclick: fn, // not sure again | |
359 | scope: me | |
360 | } | |
361 | ); | |
362 | /*jslint nomen: false*/ | |
363 | } catch(e) { | |
364 | // cannot do this xss | |
365 | } | |
366 | ||
367 | // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK! | |
368 | Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me); | |
369 | ||
370 | this.el.unmask(); | |
371 | this.fireEvent('load', this); | |
372 | ||
373 | } else if (me.src) { | |
374 | ||
375 | this.el.unmask(); | |
376 | this.fireEvent('error', this); | |
377 | } | |
378 | ||
379 | ||
380 | }, | |
381 | ||
382 | onRelayedEvent: function (event) { | |
383 | // relay event from the iframe's document to the document that owns the iframe... | |
384 | ||
385 | var iframeEl = this.iframeEl, | |
386 | ||
387 | // Get the left-based iframe position | |
388 | iframeXY = iframeEl.getTrueXY(), | |
389 | originalEventXY = event.getXY(), | |
390 | ||
391 | // Get the left-based XY position. | |
392 | // This is because the consumer of the injected event will | |
393 | // perform its own RTL normalization. | |
394 | eventXY = event.getTrueXY(); | |
395 | ||
396 | // the event from the inner document has XY relative to that document's origin, | |
397 | // so adjust it to use the origin of the iframe in the outer document: | |
398 | event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]]; | |
399 | ||
400 | event.injectEvent(iframeEl); // blame the iframe for the event... | |
401 | ||
402 | event.xy = originalEventXY; // restore the original XY (just for safety) | |
403 | }, | |
404 | ||
405 | load: function (src) { | |
406 | var me = this, | |
407 | text = me.loadMask, | |
408 | frame = me.getFrame(); | |
409 | ||
410 | if (me.fireEvent('beforeload', me, src) !== false) { | |
411 | if (text && me.el) { | |
412 | me.el.mask(text); | |
413 | } | |
414 | ||
415 | frame.src = me.src = (src || me.src); | |
416 | } | |
417 | } | |
418 | }); |