guestType: undefined,
+ validator: function(value) {
+ var me = this;
+
+ if (!Ext.isNumeric(value) ||
+ value < me.minValue ||
+ value > me.maxValue) {
+ // check is done by ExtJS
+ return true;
+ }
+
+ if (me.validateExists === true && !me.exists) {
+ return me.unknownID;
+ }
+
+ if (me.validateExists === false && me.exists) {
+ return me.inUseID;
+ }
+
+ return true;
+ },
+
initComponent: function() {
var me = this;
var label = '{0} ID';
- var unknownID = 'This {0} ID does not exists';
- var inUseID = 'This {0} ID is already in use';
+ var unknownID = gettext('This {0} ID does not exist');
+ var inUseID = gettext('This {0} ID is already in use');
+ var type = 'CT/VM';
if (me.guestType === 'lxc') {
- label = Ext.String.format(label, 'CT');
- unknownID = Ext.String.format(gettext(unknownID), 'CT');
- inUseID = Ext.String.format(gettext(inUseID), 'CT');
+ type = 'CT';
} else if (me.guestType === 'qemu') {
- label = Ext.String.format(label, 'VM');
- unknownID = Ext.String.format(gettext(unknownID), 'VM');
- inUseID = Ext.String.format(gettext(inUseID), 'VM');
- } else {
- label = Ext.String.format(label, 'CT/VM');
- unknownID = Ext.String.format(gettext(unknownID), 'CT/VM');
- inUseID = Ext.String.format(gettext(inUseID), 'CT/VM');
+ type = 'VM';
}
+ me.label = Ext.String.format(label, type);
+ me.unknownID = Ext.String.format(unknownID, type);
+ me.inUseID = Ext.String.format(inUseID, type);
+
Ext.apply(me, {
- fieldLabel: label,
+ fieldLabel: me.label,
listeners: {
'change': function(field, newValue, oldValue) {
if (!Ext.isDefined(me.validateExists)) {
return;
}
- PVE.Utils.API2Request({
+ Proxmox.Utils.API2Request({
params: { vmid: newValue },
url: '/cluster/nextid',
method: 'GET',
success: function(response, opts) {
- if (me.validateExists === true) {
- me.markInvalid(unknownID);
- }
+ me.exists = false;
+ me.validate();
},
failure: function(response, opts) {
- if (me.validateExists === false) {
- me.markInvalid(inUseID);
- }
- }
+ me.exists = true;
+ me.validate();
+ },
});
- }
- }
+ },
+ },
});
me.callParent();
if (me.loadNextFreeID) {
- PVE.Utils.API2Request({
+ Proxmox.Utils.API2Request({
url: '/cluster/nextid',
method: 'GET',
success: function(response, opts) {
me.setRawValue(response.result.data);
- }
+ },
});
}
- }
+ },
});