toolkit/utils: fix whitespace

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
This commit is contained in:
Max Carrara 2023-03-15 17:26:28 +01:00 committed by Thomas Lamprecht
parent aec7e8d23c
commit ecdde39c1c
2 changed files with 235 additions and 235 deletions

View File

@ -21,7 +21,7 @@ Ext.apply(Ext.form.field.VTypes, {
IPCIDRAddressMask: /[\d./]/i, IPCIDRAddressMask: /[\d./]/i,
IP6Address: function(v) { IP6Address: function(v) {
return Proxmox.Utils.IP6_match.test(v); return Proxmox.Utils.IP6_match.test(v);
}, },
IP6AddressText: gettext('Example') + ': 2001:DB8::42', IP6AddressText: gettext('Example') + ': 2001:DB8::42',
IP6AddressMask: /[A-Fa-f0-9:]/, IP6AddressMask: /[A-Fa-f0-9:]/,
@ -42,7 +42,7 @@ Ext.apply(Ext.form.field.VTypes, {
IP6PrefixLengthMask: /[0-9]/, IP6PrefixLengthMask: /[0-9]/,
IP64Address: function(v) { IP64Address: function(v) {
return Proxmox.Utils.IP64_match.test(v); return Proxmox.Utils.IP64_match.test(v);
}, },
IP64AddressText: gettext('Example') + ': 192.168.1.1 2001:DB8::42', IP64AddressText: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
IP64AddressMask: /[A-Fa-f0-9.:]/, IP64AddressMask: /[A-Fa-f0-9.:]/,
@ -76,25 +76,25 @@ Ext.apply(Ext.form.field.VTypes, {
MacPrefixText: gettext('Example') + ': 02:8f - ' + gettext('only unicast addresses are allowed'), MacPrefixText: gettext('Example') + ': 02:8f - ' + gettext('only unicast addresses are allowed'),
BridgeName: function(v) { BridgeName: function(v) {
return (/^vmbr\d{1,4}$/).test(v); return (/^vmbr\d{1,4}$/).test(v);
}, },
VlanName: function(v) { VlanName: function(v) {
if (Proxmox.Utils.VlanInterface_match.test(v)) { if (Proxmox.Utils.VlanInterface_match.test(v)) {
return true; return true;
} else if (Proxmox.Utils.Vlan_match.test(v)) { } else if (Proxmox.Utils.Vlan_match.test(v)) {
return true; return true;
} }
return true; return true;
}, },
BridgeNameText: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999', BridgeNameText: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
BondName: function(v) { BondName: function(v) {
return (/^bond\d{1,4}$/).test(v); return (/^bond\d{1,4}$/).test(v);
}, },
BondNameText: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999', BondNameText: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999',
InterfaceName: function(v) { InterfaceName: function(v) {
return (/^[a-z][a-z0-9_]{1,20}$/).test(v); return (/^[a-z][a-z0-9_]{1,20}$/).test(v);
}, },
InterfaceNameText: gettext("Allowed characters") + ": 'a-z', '0-9', '_'<br />" + InterfaceNameText: gettext("Allowed characters") + ": 'a-z', '0-9', '_'<br />" +
gettext("Minimum characters") + ": 2<br />" + gettext("Minimum characters") + ": 2<br />" +
@ -102,7 +102,7 @@ Ext.apply(Ext.form.field.VTypes, {
gettext("Must start with") + ": 'a-z'", gettext("Must start with") + ": 'a-z'",
StorageId: function(v) { StorageId: function(v) {
return (/^[a-z][a-z0-9\-_.]*[a-z0-9]$/i).test(v); return (/^[a-z][a-z0-9\-_.]*[a-z0-9]$/i).test(v);
}, },
StorageIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'<br />" + StorageIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '-', '_', '.'<br />" +
gettext("Minimum characters") + ": 2<br />" + gettext("Minimum characters") + ": 2<br />" +
@ -110,14 +110,14 @@ Ext.apply(Ext.form.field.VTypes, {
gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />", gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />",
ConfigId: function(v) { ConfigId: function(v) {
return (/^[a-z][a-z0-9_-]+$/i).test(v); return (/^[a-z][a-z0-9_-]+$/i).test(v);
}, },
ConfigIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'<br />" + ConfigIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'<br />" +
gettext("Minimum characters") + ": 2<br />" + gettext("Minimum characters") + ": 2<br />" +
gettext("Must start with") + ": " + gettext("letter"), gettext("Must start with") + ": " + gettext("letter"),
HttpProxy: function(v) { HttpProxy: function(v) {
return (/^http:\/\/.*$/).test(v); return (/^http:\/\/.*$/).test(v);
}, },
HttpProxyText: gettext('Example') + ": http://username:password&#64;host:port/", HttpProxyText: gettext('Example') + ": http://username:password&#64;host:port/",
@ -138,7 +138,7 @@ Ext.apply(Ext.form.field.VTypes, {
// email regex used by pve-common // email regex used by pve-common
proxmoxMail: function(v) { proxmoxMail: function(v) {
return (/^[\w+-~]+(\.[\w+-~]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/).test(v); return (/^[\w+-~]+(\.[\w+-~]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/).test(v);
}, },
proxmoxMailText: gettext('Example') + ": user@example.com", proxmoxMailText: gettext('Example') + ": user@example.com",
@ -179,11 +179,11 @@ Ext.apply(Ext.form.field.VTypes, {
HostListText: gettext('Not a valid list of hosts'), HostListText: gettext('Not a valid list of hosts'),
password: function(val, field) { password: function(val, field) {
if (field.initialPassField) { if (field.initialPassField) {
let pwd = field.up('form').down(`[name=${field.initialPassField}]`); let pwd = field.up('form').down(`[name=${field.initialPassField}]`);
return val === pwd.getValue(); return val === pwd.getValue();
} }
return true; return true;
}, },
passwordText: gettext('Passwords do not match'), passwordText: gettext('Passwords do not match'),
@ -216,30 +216,30 @@ Ext.define('Proxmox.UnderlayPool', {
override: 'Ext.dom.UnderlayPool', override: 'Ext.dom.UnderlayPool',
checkOut: function() { checkOut: function() {
let cache = this.cache, let cache = this.cache,
len = cache.length, len = cache.length,
el; el;
// do cleanup because some of the objects might have been destroyed // do cleanup because some of the objects might have been destroyed
while (len--) { while (len--) {
if (cache[len].destroyed) { if (cache[len].destroyed) {
cache.splice(len, 1); cache.splice(len, 1);
} }
} }
// end do cleanup // end do cleanup
el = cache.shift(); el = cache.shift();
if (!el) { if (!el) {
el = Ext.Element.create(this.elementConfig); el = Ext.Element.create(this.elementConfig);
el.setVisibilityMode(2); el.setVisibilityMode(2);
//<debug> //<debug>
// tell the spec runner to ignore this element when checking if the dom is clean // tell the spec runner to ignore this element when checking if the dom is clean
el.dom.setAttribute('data-sticky', true); el.dom.setAttribute('data-sticky', true);
//</debug> //</debug>
} }
return el; return el;
}, },
}); });
@ -515,28 +515,28 @@ Ext.define('Proxmox.selection.CheckboxModel', {
// [ P: optimized to remove all records at once as single remove is O(n^3) slow ] // [ P: optimized to remove all records at once as single remove is O(n^3) slow ]
// records can be an index, a record or an array of records // records can be an index, a record or an array of records
doDeselect: function(records, suppressEvent) { doDeselect: function(records, suppressEvent) {
var me = this, var me = this,
selected = me.selected, selected = me.selected,
i = 0, i = 0,
len, record, len, record,
commit; commit;
if (me.locked || !me.store) { if (me.locked || !me.store) {
return false; return false;
} }
if (typeof records === "number") { if (typeof records === "number") {
// No matching record, jump out // No matching record, jump out
record = me.store.getAt(records); record = me.store.getAt(records);
if (!record) { if (!record) {
return false; return false;
} }
records = [ records = [
record, record,
]; ];
} else if (!Ext.isArray(records)) { } else if (!Ext.isArray(records)) {
records = [ records = [
records, records,
]; ];
} }
// [P] a beforedeselection, triggered by me.onSelectChange below, can block removal by // [P] a beforedeselection, triggered by me.onSelectChange below, can block removal by
// returning false, thus the original implementation removed only here in the commit fn, // returning false, thus the original implementation removed only here in the commit fn,
// which has an abysmal performance O(n^3). As blocking removal is not the norm, go do the // which has an abysmal performance O(n^3). As blocking removal is not the norm, go do the
@ -550,119 +550,119 @@ Ext.define('Proxmox.selection.CheckboxModel', {
} }
}; };
let removalBlocked = []; let removalBlocked = [];
len = records.length; len = records.length;
me.suspendChanges(); me.suspendChanges();
for (; i < len; i++) { for (; i < len; i++) {
record = records[i]; record = records[i];
if (me.isSelected(record)) { if (me.isSelected(record)) {
committed = false; committed = false;
me.onSelectChange(record, false, suppressEvent, commit); me.onSelectChange(record, false, suppressEvent, commit);
if (!committed) { if (!committed) {
removalBlocked.push(record); removalBlocked.push(record);
} }
if (me.destroyed) { if (me.destroyed) {
return false; return false;
} }
} }
} }
if (removalBlocked.length > 0) { if (removalBlocked.length > 0) {
records.remove(removalBlocked); records.remove(removalBlocked);
} }
selected.remove(records); // [P] FAST(er) selected.remove(records); // [P] FAST(er)
me.lastSelected = selected.last(); me.lastSelected = selected.last();
me.resumeChanges(); me.resumeChanges();
// fire selchange if there was a change and there is no suppressEvent flag // fire selchange if there was a change and there is no suppressEvent flag
me.maybeFireSelectionChange(records.length > 0 && !suppressEvent); me.maybeFireSelectionChange(records.length > 0 && !suppressEvent);
return records.length; return records.length;
}, },
doMultiSelect: function(records, keepExisting, suppressEvent) { doMultiSelect: function(records, keepExisting, suppressEvent) {
var me = this, var me = this,
selected = me.selected, selected = me.selected,
change = false, change = false,
result, i, len, record, commit; result, i, len, record, commit;
if (me.locked) { if (me.locked) {
return; return;
} }
records = !Ext.isArray(records) ? [records] : records; records = !Ext.isArray(records) ? [records] : records;
len = records.length; len = records.length;
if (!keepExisting && selected.getCount() > 0) { if (!keepExisting && selected.getCount() > 0) {
result = me.deselectDuringSelect(records, suppressEvent); result = me.deselectDuringSelect(records, suppressEvent);
if (me.destroyed) { if (me.destroyed) {
return; return;
} }
if (result[0]) { if (result[0]) {
// We had a failure during selection, so jump out // We had a failure during selection, so jump out
// Fire selection change if we did deselect anything // Fire selection change if we did deselect anything
me.maybeFireSelectionChange(result[1] > 0 && !suppressEvent); me.maybeFireSelectionChange(result[1] > 0 && !suppressEvent);
return; return;
} else { } else {
// Means something has been deselected, so we've had a change // Means something has been deselected, so we've had a change
change = result[1] > 0; change = result[1] > 0;
} }
} }
let gotBlocked, blockedRecords = []; let gotBlocked, blockedRecords = [];
commit = function() { commit = function() {
if (!selected.getCount()) { if (!selected.getCount()) {
me.selectionStart = record; me.selectionStart = record;
} }
gotBlocked = false; gotBlocked = false;
change = true; change = true;
}; };
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
record = records[i]; record = records[i];
if (me.isSelected(record)) { if (me.isSelected(record)) {
continue; continue;
} }
gotBlocked = true; gotBlocked = true;
me.onSelectChange(record, true, suppressEvent, commit); me.onSelectChange(record, true, suppressEvent, commit);
if (me.destroyed) { if (me.destroyed) {
return; return;
} }
if (gotBlocked) { if (gotBlocked) {
blockedRecords.push(record); blockedRecords.push(record);
} }
} }
if (blockedRecords.length > 0) { if (blockedRecords.length > 0) {
records.remove(blockedRecords); records.remove(blockedRecords);
} }
selected.add(records); selected.add(records);
me.lastSelected = record; me.lastSelected = record;
// fire selchange if there was a change and there is no suppressEvent flag // fire selchange if there was a change and there is no suppressEvent flag
me.maybeFireSelectionChange(change && !suppressEvent); me.maybeFireSelectionChange(change && !suppressEvent);
}, },
deselectDuringSelect: function(toSelect, suppressEvent) { deselectDuringSelect: function(toSelect, suppressEvent) {
var me = this, var me = this,
selected = me.selected.getRange(), selected = me.selected.getRange(),
changed = 0, changed = 0,
failed = false; failed = false;
// Prevent selection change events from firing, will happen during select // Prevent selection change events from firing, will happen during select
me.suspendChanges(); me.suspendChanges();
me.deselectingDuringSelect = true; me.deselectingDuringSelect = true;
let toDeselect = selected.filter(item => !Ext.Array.contains(toSelect, item)); let toDeselect = selected.filter(item => !Ext.Array.contains(toSelect, item));
if (toDeselect.length > 0) { if (toDeselect.length > 0) {
changed = me.doDeselect(toDeselect, suppressEvent); changed = me.doDeselect(toDeselect, suppressEvent);
if (!changed) { if (!changed) {
failed = true; failed = true;
} }
if (me.destroyed) { if (me.destroyed) {
failed = true; failed = true;
changed = 0; changed = 0;
} }
} }
me.deselectingDuringSelect = false; me.deselectingDuringSelect = false;
me.resumeChanges(); me.resumeChanges();
return [ return [
failed, failed,
changed, changed,
]; ];
}, },
}); });
@ -678,11 +678,11 @@ Ext.define('Proxmox.view.DragZone', {
override: 'Ext.view.DragZone', override: 'Ext.view.DragZone',
onItemMouseDown: function(view, record, item, index, e) { onItemMouseDown: function(view, record, item, index, e) {
// Ignore touchstart. // Ignore touchstart.
// For touch events, we use longpress. // For touch events, we use longpress.
if (e.pointerType !== 'touch') { if (e.pointerType !== 'touch') {
this.onTriggerGesture(view, record, item, index, e); this.onTriggerGesture(view, record, item, index, e);
} }
}, },
}); });
@ -766,154 +766,154 @@ Ext.define('Ext.ux.IFrame', {
src: 'about:blank', src: 'about:blank',
renderTpl: [ renderTpl: [
'<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>', '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0" allowfullscreen="true"></iframe>',
], ],
childEls: ['iframeEl'], childEls: ['iframeEl'],
initComponent: function() { initComponent: function() {
this.callParent(); this.callParent();
this.frameName = this.frameName || this.id + '-frame'; this.frameName = this.frameName || this.id + '-frame';
}, },
initEvents: function() { initEvents: function() {
let me = this; let me = this;
me.callParent(); me.callParent();
me.iframeEl.on('load', me.onLoad, me); me.iframeEl.on('load', me.onLoad, me);
}, },
initRenderData: function() { initRenderData: function() {
return Ext.apply(this.callParent(), { return Ext.apply(this.callParent(), {
src: this.src, src: this.src,
frameName: this.frameName, frameName: this.frameName,
}); });
}, },
getBody: function() { getBody: function() {
let doc = this.getDoc(); let doc = this.getDoc();
return doc.body || doc.documentElement; return doc.body || doc.documentElement;
}, },
getDoc: function() { getDoc: function() {
try { try {
return this.getWin().document; return this.getWin().document;
} catch (ex) { } catch (ex) {
return null; return null;
} }
}, },
getWin: function() { getWin: function() {
let me = this, let me = this,
name = me.frameName, name = me.frameName,
win = Ext.isIE win = Ext.isIE
? me.iframeEl.dom.contentWindow ? me.iframeEl.dom.contentWindow
: window.frames[name]; : window.frames[name];
return win; return win;
}, },
getFrame: function() { getFrame: function() {
let me = this; let me = this;
return me.iframeEl.dom; return me.iframeEl.dom;
}, },
beforeDestroy: function() { beforeDestroy: function() {
this.cleanupListeners(true); this.cleanupListeners(true);
this.callParent(); this.callParent();
}, },
cleanupListeners: function(destroying) { cleanupListeners: function(destroying) {
let doc, prop; let doc, prop;
if (this.rendered) { if (this.rendered) {
try { try {
doc = this.getDoc(); doc = this.getDoc();
if (doc) { if (doc) {
Ext.get(doc).un(this._docListeners); Ext.get(doc).un(this._docListeners);
if (destroying && doc.hasOwnProperty) { if (destroying && doc.hasOwnProperty) {
for (prop in doc) { for (prop in doc) {
if (Object.prototype.hasOwnProperty.call(doc, prop)) { if (Object.prototype.hasOwnProperty.call(doc, prop)) {
delete doc[prop]; delete doc[prop];
} }
} }
} }
} }
} catch (e) { } catch (e) {
// do nothing // do nothing
} }
} }
}, },
onLoad: function() { onLoad: function() {
let me = this, let me = this,
doc = me.getDoc(), doc = me.getDoc(),
fn = me.onRelayedEvent; fn = me.onRelayedEvent;
if (doc) { if (doc) {
try { try {
// These events need to be relayed from the inner document (where they stop // These events need to be relayed from the inner document (where they stop
// bubbling) up to the outer document. This has to be done at the DOM level so // bubbling) up to the outer document. This has to be done at the DOM level so
// the event reaches listeners on elements like the document body. The effected // the event reaches listeners on elements like the document body. The effected
// mechanisms that depend on this bubbling behavior are listed to the right // mechanisms that depend on this bubbling behavior are listed to the right
// of the event. // of the event.
Ext.get(doc).on( Ext.get(doc).on(
me._docListeners = { me._docListeners = {
mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront) mousedown: fn, // menu dismisal (MenuManager) and Window onMouseDown (toFront)
mousemove: fn, // window resize drag detection mousemove: fn, // window resize drag detection
mouseup: fn, // window resize termination mouseup: fn, // window resize termination
click: fn, // not sure, but just to be safe click: fn, // not sure, but just to be safe
dblclick: fn, // not sure again dblclick: fn, // not sure again
scope: me, scope: me,
}, },
); );
} catch (e) { } catch (e) {
// cannot do this xss // cannot do this xss
} }
// We need to be sure we remove all our events from the iframe on unload or we're going to LEAK! // We need to be sure we remove all our events from the iframe on unload or we're going to LEAK!
Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me); Ext.get(this.getWin()).on('beforeunload', me.cleanupListeners, me);
this.el.unmask(); this.el.unmask();
this.fireEvent('load', this); this.fireEvent('load', this);
} else if (me.src) { } else if (me.src) {
this.el.unmask(); this.el.unmask();
this.fireEvent('error', this); this.fireEvent('error', this);
} }
}, },
onRelayedEvent: function(event) { onRelayedEvent: function(event) {
// relay event from the iframe's document to the document that owns the iframe... // relay event from the iframe's document to the document that owns the iframe...
let iframeEl = this.iframeEl, let iframeEl = this.iframeEl,
// Get the left-based iframe position // Get the left-based iframe position
iframeXY = iframeEl.getTrueXY(), iframeXY = iframeEl.getTrueXY(),
originalEventXY = event.getXY(), originalEventXY = event.getXY(),
// Get the left-based XY position. // Get the left-based XY position.
// This is because the consumer of the injected event will // This is because the consumer of the injected event will
// perform its own RTL normalization. // perform its own RTL normalization.
eventXY = event.getTrueXY(); eventXY = event.getTrueXY();
// the event from the inner document has XY relative to that document's origin, // the event from the inner document has XY relative to that document's origin,
// so adjust it to use the origin of the iframe in the outer document: // so adjust it to use the origin of the iframe in the outer document:
event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]]; event.xy = [iframeXY[0] + eventXY[0], iframeXY[1] + eventXY[1]];
event.injectEvent(iframeEl); // blame the iframe for the event... event.injectEvent(iframeEl); // blame the iframe for the event...
event.xy = originalEventXY; // restore the original XY (just for safety) event.xy = originalEventXY; // restore the original XY (just for safety)
}, },
load: function(src) { load: function(src) {
let me = this, let me = this,
text = me.loadMask, text = me.loadMask,
frame = me.getFrame(); frame = me.getFrame();
if (me.fireEvent('beforeload', me, src) !== false) { if (me.fireEvent('beforeload', me, src) !== false) {
if (text && me.el) { if (text && me.el) {
me.el.mask(text); me.el.mask(text);
} }
frame.src = me.src = src || me.src; frame.src = me.src = src || me.src;
} }
}, },
}); });

View File

@ -565,7 +565,7 @@ utilities: {
}, },
assemble_field_data: function(values, data) { assemble_field_data: function(values, data) {
if (!Ext.isObject(data)) { if (!Ext.isObject(data)) {
return; return;
} }
Ext.Object.each(data, function(name, val) { Ext.Object.each(data, function(name, val) {