]>
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, { | |
01031528 | 8 | IPAddress: function(v) { |
bb64de6e DM |
9 | return Proxmox.Utils.IP4_match.test(v); |
10 | }, | |
01031528 | 11 | IPAddressText: gettext('Example') + ': 192.168.1.1', |
05a977a2 | 12 | IPAddressMask: /[\d.]/i, |
bb64de6e | 13 | |
01031528 | 14 | IPCIDRAddress: function(v) { |
05a977a2 | 15 | let result = Proxmox.Utils.IP4_cidr_match.exec(v); |
bb64de6e DM |
16 | // limits according to JSON Schema see |
17 | // pve-common/src/PVE/JSONSchema.pm | |
01031528 | 18 | return result !== null && result[1] >= 8 && result[1] <= 32; |
bb64de6e | 19 | }, |
05a977a2 TL |
20 | IPCIDRAddressText: gettext('Example') + ': 192.168.1.1/24<br>' + gettext('Valid CIDR Range') + ': 8-32', |
21 | IPCIDRAddressMask: /[\d./]/i, | |
bb64de6e | 22 | |
01031528 | 23 | IP6Address: function(v) { |
bb64de6e DM |
24 | return Proxmox.Utils.IP6_match.test(v); |
25 | }, | |
01031528 | 26 | IP6AddressText: gettext('Example') + ': 2001:DB8::42', |
bb64de6e DM |
27 | IP6AddressMask: /[A-Fa-f0-9:]/, |
28 | ||
01031528 | 29 | IP6CIDRAddress: function(v) { |
05a977a2 | 30 | let result = Proxmox.Utils.IP6_cidr_match.exec(v); |
bb64de6e DM |
31 | // limits according to JSON Schema see |
32 | // pve-common/src/PVE/JSONSchema.pm | |
01031528 | 33 | return result !== null && result[1] >= 8 && result[1] <= 128; |
bb64de6e | 34 | }, |
05a977a2 TL |
35 | IP6CIDRAddressText: gettext('Example') + ': 2001:DB8::42/64<br>' + gettext('Valid CIDR Range') + ': 8-128', |
36 | IP6CIDRAddressMask: /[A-Fa-f0-9:/]/, | |
bb64de6e | 37 | |
01031528 | 38 | IP6PrefixLength: function(v) { |
bb64de6e DM |
39 | return v >= 0 && v <= 128; |
40 | }, | |
01031528 TL |
41 | IP6PrefixLengthText: gettext('Example') + ': X, where 0 <= X <= 128', |
42 | IP6PrefixLengthMask: /[0-9]/, | |
bb64de6e | 43 | |
01031528 | 44 | IP64Address: function(v) { |
bb64de6e DM |
45 | return Proxmox.Utils.IP64_match.test(v); |
46 | }, | |
01031528 | 47 | IP64AddressText: gettext('Example') + ': 192.168.1.1 2001:DB8::42', |
05a977a2 | 48 | IP64AddressMask: /[A-Fa-f0-9.:]/, |
bb64de6e | 49 | |
577b6c75 | 50 | IP64CIDRAddress: function(v) { |
05a977a2 | 51 | let result = Proxmox.Utils.IP64_cidr_match.exec(v); |
577b6c75 ML |
52 | if (result === null) { |
53 | return false; | |
54 | } | |
55 | if (result[1] !== undefined) { | |
56 | return result[1] >= 8 && result[1] <= 128; | |
57 | } else if (result[2] !== undefined) { | |
58 | return result[2] >= 8 && result[2] <= 32; | |
59 | } else { | |
60 | return false; | |
61 | } | |
62 | }, | |
63 | IP64CIDRAddressText: gettext('Example') + ': 192.168.1.1/24 2001:DB8::42/64', | |
05a977a2 | 64 | IP64CIDRAddressMask: /[A-Fa-f0-9.:/]/, |
577b6c75 | 65 | |
bb64de6e DM |
66 | MacAddress: function(v) { |
67 | return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v); | |
68 | }, | |
69 | MacAddressMask: /[a-fA-F0-9:]/, | |
70 | MacAddressText: gettext('Example') + ': 01:23:45:67:89:ab', | |
71 | ||
01031528 | 72 | MacPrefix: function(v) { |
add18fad | 73 | return (/^[a-f0-9][02468ace](?::[a-f0-9]{2}){0,2}:?$/i).test(v); |
8f449655 TL |
74 | }, |
75 | MacPrefixMask: /[a-fA-F0-9:]/, | |
ffe26505 | 76 | MacPrefixText: gettext('Example') + ': 02:8f - ' + gettext('only unicast addresses are allowed'), |
8f449655 | 77 | |
bb64de6e DM |
78 | BridgeName: function(v) { |
79 | return (/^vmbr\d{1,4}$/).test(v); | |
80 | }, | |
8aefd47c AD |
81 | VlanName: function(v) { |
82 | if (Proxmox.Utils.VlanInterface_match.test(v)) { | |
83 | return true; | |
84 | } else if (Proxmox.Utils.Vlan_match.test(v)) { | |
85 | return true; | |
86 | } | |
87 | return true; | |
88 | }, | |
bb64de6e DM |
89 | BridgeNameText: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999', |
90 | ||
91 | BondName: function(v) { | |
92 | return (/^bond\d{1,4}$/).test(v); | |
93 | }, | |
94 | BondNameText: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999', | |
95 | ||
96 | InterfaceName: function(v) { | |
97 | return (/^[a-z][a-z0-9_]{1,20}$/).test(v); | |
98 | }, | |
05a977a2 TL |
99 | InterfaceNameText: gettext("Allowed characters") + ": 'a-z', '0-9', '_'<br />" + |
100 | gettext("Minimum characters") + ": 2<br />" + | |
101 | gettext("Maximum characters") + ": 21<br />" + | |
bb64de6e DM |
102 | gettext("Must start with") + ": 'a-z'", |
103 | ||
01031528 | 104 | StorageId: function(v) { |
05a977a2 | 105 | return (/^[a-z][a-z0-9\-_.]*[a-z0-9]$/i).test(v); |
bb64de6e | 106 | }, |
05a977a2 TL |
107 | StorageIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'<br />" + |
108 | gettext("Minimum characters") + ": 2<br />" + | |
bb64de6e DM |
109 | gettext("Must start with") + ": 'A-Z', 'a-z'<br />" + |
110 | gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />", | |
111 | ||
01031528 | 112 | ConfigId: function(v) { |
05a977a2 | 113 | return (/^[a-z][a-z0-9_]+$/i).test(v); |
bb64de6e | 114 | }, |
05a977a2 TL |
115 | ConfigIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'<br />" + |
116 | gettext("Minimum characters") + ": 2<br />" + | |
bb64de6e DM |
117 | gettext("Must start with") + ": " + gettext("letter"), |
118 | ||
01031528 | 119 | HttpProxy: function(v) { |
bb64de6e DM |
120 | return (/^http:\/\/.*$/).test(v); |
121 | }, | |
122 | HttpProxyText: gettext('Example') + ": http://username:password@host:port/", | |
123 | ||
124 | DnsName: function(v) { | |
125 | return Proxmox.Utils.DnsName_match.test(v); | |
126 | }, | |
127 | DnsNameText: gettext('This is not a valid DNS name'), | |
128 | ||
129 | // workaround for https://www.sencha.com/forum/showthread.php?302150 | |
130 | proxmoxMail: function(v) { | |
05a977a2 | 131 | return (/^(\w+)([-+.][\w]+)*@(\w[-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v); |
bb64de6e DM |
132 | }, |
133 | proxmoxMailText: gettext('Example') + ": user@example.com", | |
134 | ||
ba916e58 DC |
135 | DnsOrIp: function(v) { |
136 | if (!Proxmox.Utils.DnsName_match.test(v) && | |
694a76f6 | 137 | !Proxmox.Utils.IP64_match.test(v)) { |
ba916e58 DC |
138 | return false; |
139 | } | |
140 | ||
141 | return true; | |
142 | }, | |
694a76f6 | 143 | DnsOrIpText: gettext('Not a valid DNS name or IP address.'), |
ba916e58 | 144 | |
5252b7f1 DC |
145 | HostPort: function(v) { |
146 | return Proxmox.Utils.HostPort_match.test(v) || | |
147 | Proxmox.Utils.HostPortBrackets_match.test(v) || | |
148 | Proxmox.Utils.IP6_dotnotation_match.test(v); | |
149 | }, | |
a9bea104 | 150 | HostPortText: gettext('Host/IP address or optional port is invalid'), |
5252b7f1 | 151 | |
bb64de6e | 152 | HostList: function(v) { |
05a977a2 TL |
153 | let list = v.split(/[ ,;]+/); |
154 | let i; | |
bb64de6e | 155 | for (i = 0; i < list.length; i++) { |
05a977a2 | 156 | if (list[i] === '') { |
bb64de6e DM |
157 | continue; |
158 | } | |
159 | ||
160 | if (!Proxmox.Utils.HostPort_match.test(list[i]) && | |
161 | !Proxmox.Utils.HostPortBrackets_match.test(list[i]) && | |
162 | !Proxmox.Utils.IP6_dotnotation_match.test(list[i])) { | |
163 | return false; | |
164 | } | |
165 | } | |
166 | ||
167 | return true; | |
168 | }, | |
36704a2f DM |
169 | HostListText: gettext('Not a valid list of hosts'), |
170 | ||
171 | password: function(val, field) { | |
172 | if (field.initialPassField) { | |
05a977a2 TL |
173 | let pwd = field.up('form').down(`[name=${field.initialPassField}]`); |
174 | return val === pwd.getValue(); | |
36704a2f DM |
175 | } |
176 | return true; | |
177 | }, | |
178 | ||
01031528 | 179 | passwordText: gettext('Passwords do not match'), |
dcd5a0c6 SI |
180 | |
181 | email: function(value) { | |
df096ae3 | 182 | let emailre = /^[\w+~-]+(\.[\w+~-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/; |
dcd5a0c6 SI |
183 | return emailre.test(value); |
184 | }, | |
bb64de6e DM |
185 | }); |
186 | ||
aea77b2c DC |
187 | // Firefox 52+ Touchscreen bug |
188 | // see https://www.sencha.com/forum/showthread.php?336762-Examples-don-t-work-in-Firefox-52-touchscreen/page2 | |
189 | // and https://bugzilla.proxmox.com/show_bug.cgi?id=1223 | |
190 | Ext.define('EXTJS_23846.Element', { | |
01031528 | 191 | override: 'Ext.dom.Element', |
aea77b2c | 192 | }, function(Element) { |
05a977a2 | 193 | let supports = Ext.supports, |
aea77b2c DC |
194 | proto = Element.prototype, |
195 | eventMap = proto.eventMap, | |
196 | additiveEvents = proto.additiveEvents; | |
197 | ||
198 | if (Ext.os.is.Desktop && supports.TouchEvents && !supports.PointerEvents) { | |
199 | eventMap.touchstart = 'mousedown'; | |
200 | eventMap.touchmove = 'mousemove'; | |
201 | eventMap.touchend = 'mouseup'; | |
202 | eventMap.touchcancel = 'mouseup'; | |
203 | ||
204 | additiveEvents.mousedown = 'mousedown'; | |
205 | additiveEvents.mousemove = 'mousemove'; | |
206 | additiveEvents.mouseup = 'mouseup'; | |
207 | additiveEvents.touchstart = 'touchstart'; | |
208 | additiveEvents.touchmove = 'touchmove'; | |
209 | additiveEvents.touchend = 'touchend'; | |
210 | additiveEvents.touchcancel = 'touchcancel'; | |
211 | ||
212 | additiveEvents.pointerdown = 'mousedown'; | |
213 | additiveEvents.pointermove = 'mousemove'; | |
214 | additiveEvents.pointerup = 'mouseup'; | |
215 | additiveEvents.pointercancel = 'mouseup'; | |
216 | } | |
217 | }); | |
218 | ||
219 | Ext.define('EXTJS_23846.Gesture', { | |
01031528 | 220 | override: 'Ext.event.publisher.Gesture', |
aea77b2c | 221 | }, function(Gesture) { |
05a977a2 | 222 | let gestures = Gesture.instance; |
aea77b2c DC |
223 | |
224 | if (Ext.supports.TouchEvents && !Ext.isWebKit && Ext.os.is.Desktop) { | |
05a977a2 TL |
225 | gestures.handledDomEvents.push('mousedown', 'mousemove', 'mouseup'); |
226 | gestures.registerEvents(); | |
aea77b2c DC |
227 | } |
228 | }); | |
229 | ||
acfbf255 DC |
230 | Ext.define('EXTJS_18900.Pie', { |
231 | override: 'Ext.chart.series.Pie', | |
232 | ||
233 | // from 6.0.2 | |
01031528 | 234 | betweenAngle: function(x, a, b) { |
05a977a2 | 235 | let pp = Math.PI * 2, |
acfbf255 DC |
236 | offset = this.rotationOffset; |
237 | ||
238 | if (a === b) { | |
239 | return false; | |
240 | } | |
241 | ||
242 | if (!this.getClockwise()) { | |
243 | x *= -1; | |
244 | a *= -1; | |
245 | b *= -1; | |
246 | a -= offset; | |
247 | b -= offset; | |
248 | } else { | |
249 | a += offset; | |
250 | b += offset; | |
251 | } | |
252 | ||
253 | x -= a; | |
254 | b -= a; | |
255 | ||
256 | // Normalize, so that both x and b are in the [0,360) interval. | |
257 | x %= pp; | |
258 | b %= pp; | |
259 | x += pp; | |
260 | b += pp; | |
261 | x %= pp; | |
262 | b %= pp; | |
263 | ||
264 | // Because 360 * n angles will be normalized to 0, | |
265 | // we need to treat b === 0 as a special case. | |
266 | return x < b || b === 0; | |
267 | }, | |
268 | }); | |
269 | ||
3c158249 TL |
270 | // we always want the number in x.y format and never in, e.g., x,y |
271 | Ext.define('PVE.form.field.Number', { | |
272 | override: 'Ext.form.field.Number', | |
01031528 | 273 | submitLocaleSeparator: false, |
3c158249 TL |
274 | }); |
275 | ||
bb64de6e DM |
276 | // ExtJs 5-6 has an issue with caching |
277 | // see https://www.sencha.com/forum/showthread.php?308989 | |
278 | Ext.define('Proxmox.UnderlayPool', { | |
279 | override: 'Ext.dom.UnderlayPool', | |
280 | ||
01031528 | 281 | checkOut: function() { |
05a977a2 | 282 | let cache = this.cache, |
bb64de6e DM |
283 | len = cache.length, |
284 | el; | |
285 | ||
286 | // do cleanup because some of the objects might have been destroyed | |
287 | while (len--) { | |
288 | if (cache[len].destroyed) { | |
289 | cache.splice(len, 1); | |
290 | } | |
291 | } | |
292 | // end do cleanup | |
293 | ||
294 | el = cache.shift(); | |
295 | ||
296 | if (!el) { | |
297 | el = Ext.Element.create(this.elementConfig); | |
298 | el.setVisibilityMode(2); | |
299 | //<debug> | |
300 | // tell the spec runner to ignore this element when checking if the dom is clean | |
301 | el.dom.setAttribute('data-sticky', true); | |
302 | //</debug> | |
303 | } | |
304 | ||
305 | return el; | |
01031528 | 306 | }, |
bb64de6e DM |
307 | }); |
308 | ||
a2d8b9a9 DC |
309 | // 'Enter' in Textareas and aria multiline fields should not activate the |
310 | // defaultbutton, fixed in extjs 6.0.2 | |
311 | Ext.define('PVE.panel.Panel', { | |
312 | override: 'Ext.panel.Panel', | |
313 | ||
314 | fireDefaultButton: function(e) { | |
315 | if (e.target.getAttribute('aria-multiline') === 'true' || | |
316 | e.target.tagName === "TEXTAREA") { | |
317 | return true; | |
318 | } | |
319 | return this.callParent(arguments); | |
01031528 | 320 | }, |
a2d8b9a9 DC |
321 | }); |
322 | ||
bb64de6e DM |
323 | // if the order of the values are not the same in originalValue and value |
324 | // extjs will not overwrite value, but marks the field dirty and thus | |
325 | // the reset button will be enabled (but clicking it changes nothing) | |
326 | // so if the arrays are not the same after resetting, we | |
327 | // clear and set it | |
328 | Ext.define('Proxmox.form.ComboBox', { | |
329 | override: 'Ext.form.field.ComboBox', | |
330 | ||
331 | reset: function() { | |
332 | // copied from combobox | |
05a977a2 | 333 | let me = this; |
bb64de6e | 334 | me.callParent(); |
bb64de6e DM |
335 | |
336 | // clear and set when not the same | |
05a977a2 TL |
337 | let value = me.getValue(); |
338 | if (Ext.isArray(me.originalValue) && Ext.isArray(value) && | |
339 | !Ext.Array.equals(value, me.originalValue)) { | |
bb64de6e DM |
340 | me.clearValue(); |
341 | me.setValue(me.originalValue); | |
342 | } | |
50032132 DC |
343 | }, |
344 | ||
345 | // we also want to open the trigger on editable comboboxes by default | |
346 | initComponent: function() { | |
347 | let me = this; | |
348 | me.callParent(); | |
349 | ||
350 | if (me.editable) { | |
351 | // The trigger.picker causes first a focus event on the field then | |
352 | // toggles the selection picker. Thus skip expanding in this case, | |
353 | // else our focus listener expands and the picker.trigger then | |
354 | // collapses it directly afterwards. | |
355 | Ext.override(me.triggers.picker, { | |
356 | onMouseDown: function(e) { | |
357 | // copied "should we focus" check from Ext.form.trigger.Trigger | |
358 | if (e.pointerType !== 'touch' && !this.field.owns(Ext.Element.getActiveElement())) { | |
359 | me.skip_expand_on_focus = true; | |
360 | } | |
361 | this.callParent(arguments); | |
01031528 | 362 | }, |
50032132 DC |
363 | }); |
364 | ||
365 | me.on("focus", function(combobox) { | |
366 | if (!combobox.isExpanded && !combobox.skip_expand_on_focus) { | |
367 | combobox.expand(); | |
368 | } | |
369 | combobox.skip_expand_on_focus = false; | |
370 | }); | |
371 | } | |
372 | }, | |
bb64de6e DM |
373 | }); |
374 | ||
47d1c80c TL |
375 | // when refreshing a grid/tree view, restoring the focus moves the view back to |
376 | // the previously focused item. Save scroll position before refocusing. | |
377 | Ext.define(null, { | |
378 | override: 'Ext.view.Table', | |
379 | ||
380 | jumpToFocus: false, | |
381 | ||
382 | saveFocusState: function() { | |
05a977a2 TL |
383 | let me = this, |
384 | store = me.dataSource, | |
385 | actionableMode = me.actionableMode, | |
386 | navModel = me.getNavigationModel(), | |
387 | focusPosition = actionableMode ? me.actionPosition : navModel.getPosition(true), | |
388 | refocusRow, refocusCol; | |
389 | ||
390 | if (focusPosition) { | |
391 | // Separate this from the instance that the nav model is using. | |
392 | focusPosition = focusPosition.clone(); | |
393 | ||
394 | // Exit actionable mode. | |
395 | // We must inform any Actionables that they must relinquish control. | |
396 | // Tabbability must be reset. | |
397 | if (actionableMode) { | |
398 | me.ownerGrid.setActionableMode(false); | |
399 | } | |
47d1c80c | 400 | |
05a977a2 TL |
401 | // Blur the focused descendant, but do not trigger focusLeave. |
402 | me.el.dom.focus(); | |
403 | ||
404 | // Exiting actionable mode navigates to the owning cell, so in either focus mode we must | |
405 | // clear the navigation position | |
406 | navModel.setPosition(); | |
407 | ||
408 | // The following function will attempt to refocus back in the same mode to the same cell | |
409 | // as it was at before based upon the previous record (if it's still inthe store), or the row index. | |
410 | return function() { | |
411 | // If we still have data, attempt to refocus in the same mode. | |
412 | if (store.getCount()) { | |
413 | // Adjust expectations of where we are able to refocus according to what kind of destruction | |
414 | // might have been wrought on this view's DOM during focus save. | |
415 | refocusRow = Math.min(focusPosition.rowIdx, me.all.getCount() - 1); | |
416 | refocusCol = Math.min(focusPosition.colIdx, | |
417 | me.getVisibleColumnManager().getColumns().length - 1); | |
418 | refocusRow = store.contains(focusPosition.record) ? focusPosition.record : refocusRow; | |
419 | focusPosition = new Ext.grid.CellContext(me).setPosition(refocusRow, refocusCol); | |
420 | ||
421 | if (actionableMode) { | |
422 | me.ownerGrid.setActionableMode(true, focusPosition); | |
423 | } else { | |
424 | me.cellFocused = true; | |
47d1c80c TL |
425 | |
426 | // we sometimes want to scroll back to where we were | |
05a977a2 TL |
427 | let x = me.getScrollX(); |
428 | let y = me.getScrollY(); | |
47d1c80c | 429 | |
05a977a2 TL |
430 | // Pass "preventNavigation" as true so that that does not cause selection. |
431 | navModel.setPosition(focusPosition, null, null, null, true); | |
47d1c80c TL |
432 | |
433 | if (!me.jumpToFocus) { | |
01031528 | 434 | me.scrollTo(x, y); |
47d1c80c | 435 | } |
05a977a2 TL |
436 | } |
437 | } else { // No rows - focus associated column header | |
438 | focusPosition.column.focus(); | |
439 | } | |
440 | }; | |
441 | } | |
442 | return Ext.emptyFn; | |
01031528 | 443 | }, |
47d1c80c TL |
444 | }); |
445 | ||
bb64de6e DM |
446 | // should be fixed with ExtJS 6.0.2, see: |
447 | // https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll | |
448 | Ext.define('Proxmox.Datepicker', { | |
449 | override: 'Ext.picker.Date', | |
01031528 | 450 | hideMode: 'visibility', |
bb64de6e DM |
451 | }); |
452 | ||
a55813d6 DM |
453 | // ExtJS 6.0.1 has no setSubmitValue() (although you find it in the docs). |
454 | // Note: this.submitValue is a boolean flag, whereas getSubmitValue() returns | |
455 | // data to be submitted. | |
1d9804a9 DM |
456 | Ext.define('Proxmox.form.field.Text', { |
457 | override: 'Ext.form.field.Text', | |
458 | ||
459 | setSubmitValue: function(v) { | |
460 | this.submitValue = v; | |
461 | }, | |
1d9804a9 DM |
462 | }); |
463 | ||
d78eb5ec DC |
464 | // make mousescrolling work in firefox in the containers overflowhandler, |
465 | // by using only the 'wheel' event not 'mousewheel'(fixed in 7.3) | |
466 | // also reverse the scrolldirection (fixed in 7.3) | |
467 | // and reduce the default increment | |
1fb41f2e TL |
468 | Ext.define(null, { |
469 | override: 'Ext.layout.container.boxOverflow.Scroller', | |
470 | ||
d78eb5ec DC |
471 | wheelIncrement: 1, |
472 | ||
473 | getWheelDelta: function(e) { | |
474 | return -e.getWheelDelta(e); | |
475 | }, | |
476 | ||
477 | onOwnerRender: function(owner) { | |
478 | var me = this, | |
479 | scrollable = { | |
480 | isBoxOverflowScroller: true, | |
481 | x: false, | |
482 | y: false, | |
483 | listeners: { | |
484 | scrollend: this.onScrollEnd, | |
485 | scope: this, | |
486 | }, | |
487 | }; | |
488 | ||
489 | // If no obstrusive scrollbars, allow natural scrolling on mobile touch devices | |
490 | if (!Ext.scrollbar.width() && !Ext.platformTags.desktop) { | |
491 | scrollable[owner.layout.horizontal ? 'x' : 'y'] = true; | |
1fb41f2e | 492 | } else { |
d78eb5ec DC |
493 | me.wheelListener = me.layout.innerCt.on( |
494 | 'wheel', me.onMouseWheel, me, { destroyable: true }, | |
495 | ); | |
1fb41f2e | 496 | } |
1fb41f2e | 497 | |
d78eb5ec | 498 | owner.setScrollable(scrollable); |
01031528 | 499 | }, |
d78eb5ec DC |
500 | }); |
501 | ||
502 | // extj 6.7 reversed mousewheel direction... (fixed in 7.3) | |
503 | // https://forum.sencha.com/forum/showthread.php?472517-Mousewheel-scroll-direction-in-numberfield-with-spinners | |
504 | // alse use the 'wheel' event instead of 'mousewheel' (fixed in 7.3) | |
505 | Ext.define('Proxmox.form.field.Spinner', { | |
506 | override: 'Ext.form.field.Spinner', | |
507 | ||
508 | onRender: function() { | |
509 | var me = this, | |
510 | spinnerTrigger = me.getTrigger('spinner'); | |
1fb41f2e | 511 | |
d78eb5ec DC |
512 | me.callParent(); |
513 | ||
514 | // Init up/down arrow keys | |
515 | if (me.keyNavEnabled) { | |
516 | me.spinnerKeyNav = new Ext.util.KeyNav({ | |
517 | target: me.inputEl, | |
518 | scope: me, | |
519 | up: me.spinUp, | |
520 | down: me.spinDown, | |
521 | }); | |
522 | ||
523 | me.inputEl.on({ | |
524 | keyup: me.onInputElKeyUp, | |
525 | scope: me, | |
526 | }); | |
527 | } | |
528 | ||
529 | // Init mouse wheel | |
530 | if (me.mouseWheelEnabled) { | |
531 | me.mon(me.bodyEl, 'wheel', me.onMouseWheel, me); | |
532 | } | |
533 | ||
534 | // in v4 spinUpEl/spinDownEl were childEls, now they are children of the trigger. | |
535 | // create references for compatibility | |
536 | me.spinUpEl = spinnerTrigger.upEl; | |
537 | me.spinDownEl = spinnerTrigger.downEl; | |
538 | }, | |
539 | ||
540 | onMouseWheel: function(e) { | |
541 | var me = this, | |
542 | delta; | |
543 | if (me.hasFocus) { | |
544 | delta = e.getWheelDelta(); | |
545 | if (delta > 0) { | |
546 | me.spinDown(); | |
547 | } else if (delta < 0) { | |
548 | me.spinUp(); | |
549 | } | |
550 | e.stopEvent(); | |
551 | me.onSpinEnd(); | |
552 | } | |
553 | }, | |
1fb41f2e TL |
554 | }); |
555 | ||
312310e0 DC |
556 | // add '@' to the valid id |
557 | Ext.define('Proxmox.validIdReOverride', { | |
558 | override: 'Ext.Component', | |
05a977a2 | 559 | validIdRe: /^[a-z_][a-z0-9\-_@]*$/i, |
312310e0 DC |
560 | }); |
561 | ||
98d894d8 DC |
562 | Ext.define('Proxmox.selection.CheckboxModel', { |
563 | override: 'Ext.selection.CheckboxModel', | |
564 | ||
1f628e9c | 565 | // [P] use whole checkbox cell to multiselect, not only the checkbox |
98d894d8 | 566 | checkSelector: '.x-grid-cell-row-checker', |
1f628e9c | 567 | |
ea2b3fd7 TL |
568 | // TODO: remove all optimizations below to an override for parent 'Ext.selection.Model' ?? |
569 | ||
1f628e9c TL |
570 | // [ P: optimized to remove all records at once as single remove is O(n^3) slow ] |
571 | // records can be an index, a record or an array of records | |
572 | doDeselect: function(records, suppressEvent) { | |
573 | var me = this, | |
574 | selected = me.selected, | |
575 | i = 0, | |
576 | len, record, | |
577 | commit; | |
578 | if (me.locked || !me.store) { | |
579 | return false; | |
580 | } | |
581 | if (typeof records === "number") { | |
582 | // No matching record, jump out | |
583 | record = me.store.getAt(records); | |
584 | if (!record) { | |
585 | return false; | |
586 | } | |
587 | records = [ | |
588 | record, | |
589 | ]; | |
590 | } else if (!Ext.isArray(records)) { | |
591 | records = [ | |
592 | records, | |
593 | ]; | |
594 | } | |
595 | // [P] a beforedeselection, triggered by me.onSelectChange below, can block removal by | |
596 | // returning false, thus the original implementation removed only here in the commit fn, | |
597 | // which has an abysmal performance O(n^3). As blocking removal is not the norm, go do the | |
598 | // reverse, record blocked records and remove them from the to-be-removed array before | |
599 | // applying it. A FF86 i9-9900K on 10k records goes from >40s to ~33ms for >90% deselection | |
600 | let committed = false; | |
601 | commit = function() { | |
602 | committed = true; | |
603 | if (record === me.selectionStart) { | |
604 | me.selectionStart = null; | |
605 | } | |
606 | }; | |
607 | let removalBlocked = []; | |
608 | len = records.length; | |
609 | me.suspendChanges(); | |
610 | for (; i < len; i++) { | |
611 | record = records[i]; | |
612 | if (me.isSelected(record)) { | |
613 | committed = false; | |
614 | me.onSelectChange(record, false, suppressEvent, commit); | |
615 | if (!committed) { | |
616 | removalBlocked.push(record); | |
617 | } | |
618 | if (me.destroyed) { | |
619 | return false; | |
620 | } | |
621 | } | |
622 | } | |
623 | if (removalBlocked.length > 0) { | |
624 | records.remove(removalBlocked); | |
625 | } | |
626 | selected.remove(records); // [P] FAST(er) | |
627 | me.lastSelected = selected.last(); | |
628 | me.resumeChanges(); | |
629 | // fire selchange if there was a change and there is no suppressEvent flag | |
630 | me.maybeFireSelectionChange(records.length > 0 && !suppressEvent); | |
ea2b3fd7 TL |
631 | return records.length; |
632 | }, | |
633 | ||
634 | ||
635 | doMultiSelect: function(records, keepExisting, suppressEvent) { | |
636 | var me = this, | |
637 | selected = me.selected, | |
638 | change = false, | |
639 | result, i, len, record, commit; | |
640 | ||
641 | if (me.locked) { | |
642 | return; | |
643 | } | |
644 | ||
645 | records = !Ext.isArray(records) ? [records] : records; | |
646 | len = records.length; | |
647 | if (!keepExisting && selected.getCount() > 0) { | |
648 | result = me.deselectDuringSelect(records, suppressEvent); | |
649 | if (me.destroyed) { | |
650 | return; | |
651 | } | |
652 | if (result[0]) { | |
653 | // We had a failure during selection, so jump out | |
654 | // Fire selection change if we did deselect anything | |
655 | me.maybeFireSelectionChange(result[1] > 0 && !suppressEvent); | |
656 | return; | |
657 | } else { | |
658 | // Means something has been deselected, so we've had a change | |
659 | change = result[1] > 0; | |
660 | } | |
661 | } | |
662 | ||
663 | let gotBlocked, blockedRecords = []; | |
664 | commit = function() { | |
665 | if (!selected.getCount()) { | |
666 | me.selectionStart = record; | |
667 | } | |
668 | gotBlocked = false; | |
669 | change = true; | |
670 | }; | |
671 | ||
672 | for (i = 0; i < len; i++) { | |
673 | record = records[i]; | |
674 | if (me.isSelected(record)) { | |
675 | continue; | |
676 | } | |
677 | ||
678 | gotBlocked = true; | |
679 | me.onSelectChange(record, true, suppressEvent, commit); | |
680 | if (me.destroyed) { | |
681 | return; | |
682 | } | |
683 | if (gotBlocked) { | |
684 | blockedRecords.push(record); | |
685 | } | |
686 | } | |
687 | if (blockedRecords.length > 0) { | |
688 | records.remove(blockedRecords); | |
689 | } | |
690 | selected.add(records); | |
691 | me.lastSelected = record; | |
692 | ||
693 | // fire selchange if there was a change and there is no suppressEvent flag | |
694 | me.maybeFireSelectionChange(change && !suppressEvent); | |
695 | }, | |
696 | deselectDuringSelect: function(toSelect, suppressEvent) { | |
697 | var me = this, | |
698 | selected = me.selected.getRange(), | |
699 | changed = 0, | |
700 | failed = false; | |
701 | // Prevent selection change events from firing, will happen during select | |
702 | me.suspendChanges(); | |
703 | me.deselectingDuringSelect = true; | |
704 | let toDeselect = selected.filter(item => !Ext.Array.contains(toSelect, item)); | |
705 | if (toDeselect.length > 0) { | |
706 | changed = me.doDeselect(toDeselect, suppressEvent); | |
707 | if (!changed) { | |
708 | failed = true; | |
709 | } | |
710 | if (me.destroyed) { | |
711 | failed = true; | |
712 | changed = 0; | |
713 | } | |
714 | } | |
715 | me.deselectingDuringSelect = false; | |
716 | me.resumeChanges(); | |
717 | return [ | |
718 | failed, | |
719 | changed, | |
720 | ]; | |
1f628e9c | 721 | }, |
98d894d8 DC |
722 | }); |
723 | ||
518dd0b6 DC |
724 | // override the download server url globally, for privacy reasons |
725 | Ext.draw.Container.prototype.defaultDownloadServerUrl = "-"; | |
726 | ||
322de562 DC |
727 | // stop nulling of properties |
728 | Ext.define('Proxmox.Component', { | |
729 | override: 'Ext.Component', | |
730 | clearPropertiesOnDestroy: false, | |
731 | }); | |
732 | ||
bb64de6e DM |
733 | // force alert boxes to be rendered with an Error Icon |
734 | // since Ext.Msg is an object and not a prototype, we need to override it | |
735 | // after the framework has been initiated | |
736 | Ext.onReady(function() { | |
bb64de6e | 737 | Ext.override(Ext.Msg, { |
05a977a2 | 738 | alert: function(title, message, fn, scope) { // eslint-disable-line consistent-return |
bb64de6e | 739 | if (Ext.isString(title)) { |
05a977a2 | 740 | let config = { |
bb64de6e DM |
741 | title: title, |
742 | message: message, | |
743 | icon: this.ERROR, | |
744 | buttons: this.OK, | |
745 | fn: fn, | |
01031528 TL |
746 | scope: scope, |
747 | minWidth: this.minWidth, | |
bb64de6e DM |
748 | }; |
749 | return this.show(config); | |
750 | } | |
01031528 | 751 | }, |
bb64de6e | 752 | }); |
bb64de6e DM |
753 | }); |
754 | Ext.define('Ext.ux.IFrame', { | |
755 | extend: 'Ext.Component', | |
756 | ||
757 | alias: 'widget.uxiframe', | |
758 | ||
759 | loadMask: 'Loading...', | |
760 | ||
761 | src: 'about:blank', | |
762 | ||
763 | renderTpl: [ | |
01031528 | 764 | '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>', |
bb64de6e DM |
765 | ], |
766 | childEls: ['iframeEl'], | |
767 | ||
01031528 | 768 | initComponent: function() { |
bb64de6e DM |
769 | this.callParent(); |
770 | ||
771 | this.frameName = this.frameName || this.id + '-frame'; | |
772 | }, | |
773 | ||
01031528 | 774 | initEvents: function() { |
05a977a2 | 775 | let me = this; |
bb64de6e DM |
776 | me.callParent(); |
777 | me.iframeEl.on('load', me.onLoad, me); | |
778 | }, | |
779 | ||
780 | initRenderData: function() { | |
781 | return Ext.apply(this.callParent(), { | |
782 | src: this.src, | |
01031528 | 783 | frameName: this.frameName, |
bb64de6e DM |
784 | }); |
785 | }, | |
786 | ||
787 | getBody: function() { | |
05a977a2 | 788 | let doc = this.getDoc(); |
bb64de6e DM |
789 | return doc.body || doc.documentElement; |
790 | }, | |
791 | ||
792 | getDoc: function() { | |
793 | try { | |
794 | return this.getWin().document; | |
795 | } catch (ex) { | |
796 | return null; | |
797 | } | |
798 | }, | |
799 | ||
800 | getWin: function() { | |
05a977a2 | 801 | let me = this, |
bb64de6e DM |
802 | name = me.frameName, |
803 | win = Ext.isIE | |
804 | ? me.iframeEl.dom.contentWindow | |
805 | : window.frames[name]; | |
806 | return win; | |
807 | }, | |
808 | ||
809 | getFrame: function() { | |
05a977a2 | 810 | let me = this; |
bb64de6e DM |
811 | return me.iframeEl.dom; |
812 | }, | |
813 | ||
01031528 | 814 | beforeDestroy: function() { |
bb64de6e DM |
815 | this.cleanupListeners(true); |
816 | this.callParent(); | |
817 | }, | |
818 | ||
01031528 | 819 | cleanupListeners: function(destroying) { |
05a977a2 | 820 | let doc, prop; |
bb64de6e DM |
821 | |
822 | if (this.rendered) { | |
823 | try { | |
824 | doc = this.getDoc(); | |
825 | if (doc) { | |
bb64de6e | 826 | Ext.get(doc).un(this._docListeners); |
bb64de6e DM |
827 | if (destroying && doc.hasOwnProperty) { |
828 | for (prop in doc) { | |
05a977a2 | 829 | if (Object.prototype.hasOwnProperty.call(doc, prop)) { |
bb64de6e DM |
830 | delete doc[prop]; |
831 | } | |
832 | } | |
833 | } | |
834 | } | |
05a977a2 TL |
835 | } catch (e) { |
836 | // do nothing | |
837 | } | |
bb64de6e DM |
838 | } |
839 | }, | |
840 | ||
841 | onLoad: function() { | |
05a977a2 | 842 | let me = this, |
bb64de6e DM |
843 | doc = me.getDoc(), |
844 | fn = me.onRelayedEvent; | |
845 | ||
846 | if (doc) { | |
847 | try { | |
848 | // These events need to be relayed from the inner document (where they stop | |
849 | // bubbling) up to the outer document. This has to be done at the DOM level so | |
850 | // the event reaches listeners on elements like the document body. The effected | |
851 | // mechanisms that depend on this bubbling behavior are listed to the right | |
852 | // of the event. | |
bb64de6e DM |
853 | Ext.get(doc).on( |
854 | me._docListeners = { | |
855 | mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront) | |
856 | mousemove: fn, // window resize drag detection | |
01031528 TL |
857 | mouseup: fn, // window resize termination |
858 | click: fn, // not sure, but just to be safe | |
859 | dblclick: fn, // not sure again | |
860 | scope: me, | |
861 | }, | |
bb64de6e | 862 | ); |
01031528 | 863 | } catch (e) { |
bb64de6e DM |
864 | // cannot do this xss |
865 | } | |
866 | ||
867 | // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK! | |
868 | Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me); | |
869 | ||
870 | this.el.unmask(); | |
871 | this.fireEvent('load', this); | |
bb64de6e | 872 | } else if (me.src) { |
bb64de6e DM |
873 | this.el.unmask(); |
874 | this.fireEvent('error', this); | |
875 | } | |
bb64de6e DM |
876 | }, |
877 | ||
01031528 | 878 | onRelayedEvent: function(event) { |
bb64de6e DM |
879 | // relay event from the iframe's document to the document that owns the iframe... |
880 | ||
05a977a2 | 881 | let iframeEl = this.iframeEl, |
bb64de6e DM |
882 | |
883 | // Get the left-based iframe position | |
884 | iframeXY = iframeEl.getTrueXY(), | |
885 | originalEventXY = event.getXY(), | |
886 | ||
887 | // Get the left-based XY position. | |
888 | // This is because the consumer of the injected event will | |
889 | // perform its own RTL normalization. | |
890 | eventXY = event.getTrueXY(); | |
891 | ||
892 | // the event from the inner document has XY relative to that document's origin, | |
893 | // so adjust it to use the origin of the iframe in the outer document: | |
894 | event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]]; | |
895 | ||
896 | event.injectEvent(iframeEl); // blame the iframe for the event... | |
897 | ||
898 | event.xy = originalEventXY; // restore the original XY (just for safety) | |
899 | }, | |
900 | ||
01031528 | 901 | load: function(src) { |
05a977a2 | 902 | let me = this, |
bb64de6e DM |
903 | text = me.loadMask, |
904 | frame = me.getFrame(); | |
905 | ||
906 | if (me.fireEvent('beforeload', me, src) !== false) { | |
907 | if (text && me.el) { | |
908 | me.el.mask(text); | |
909 | } | |
910 | ||
01031528 | 911 | frame.src = me.src = src || me.src; |
bb64de6e | 912 | } |
01031528 | 913 | }, |
bb64de6e | 914 | }); |