dd0f5ef3d5
This allows to display a 'CT', a 'VM', or a 'CT/VM' label to be displayed, depending on the context. Currently when restoring a CT backup or creating a CT via the wizard, we are asked to enter a *VM* ID, which is confusing.
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
Ext.define('PVE.form.GuestIDSelector', {
|
|
extend: 'Ext.form.field.Number',
|
|
alias: 'widget.pveGuestIDSelector',
|
|
|
|
allowBlank: false,
|
|
|
|
minValue: 100,
|
|
|
|
maxValue: 999999999,
|
|
|
|
validateExists: undefined,
|
|
|
|
loadNextFreeID: false,
|
|
|
|
guestType: undefined,
|
|
|
|
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';
|
|
|
|
if (me.guestType === 'lxc') {
|
|
label = Ext.String.format(label, 'CT');
|
|
unknownID = Ext.String.format(gettext(unknownID), 'CT');
|
|
inUseID = Ext.String.format(gettext(inUseID), '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');
|
|
}
|
|
|
|
Ext.apply(me, {
|
|
fieldLabel: label,
|
|
listeners: {
|
|
'change': function(field, newValue, oldValue) {
|
|
if (!Ext.isDefined(me.validateExists)) {
|
|
return;
|
|
}
|
|
PVE.Utils.API2Request({
|
|
params: { vmid: newValue },
|
|
url: '/cluster/nextid',
|
|
method: 'GET',
|
|
success: function(response, opts) {
|
|
if (me.validateExists === true) {
|
|
me.markInvalid(unknownID);
|
|
}
|
|
},
|
|
failure: function(response, opts) {
|
|
if (me.validateExists === false) {
|
|
me.markInvalid(inUseID);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
me.callParent();
|
|
|
|
if (me.loadNextFreeID) {
|
|
PVE.Utils.API2Request({
|
|
url: '/cluster/nextid',
|
|
method: 'GET',
|
|
success: function(response, opts) {
|
|
me.setRawValue(response.result.data);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|