Convert the VMIDSelector to a generic GuestIDSelector
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.
This commit is contained in:
parent
eb2d6f1e85
commit
dd0f5ef3d5
@ -36,7 +36,7 @@ JSSRC= \
|
||||
form/GroupSelector.js \
|
||||
form/UserSelector.js \
|
||||
form/RoleSelector.js \
|
||||
form/VMIDSelector.js \
|
||||
form/GuestIDSelector.js \
|
||||
form/MemoryField.js \
|
||||
form/NetworkCardSelector.js \
|
||||
form/DiskFormatSelector.js \
|
||||
|
75
www/manager6/form/GuestIDSelector.js
Normal file
75
www/manager6/form/GuestIDSelector.js
Normal file
@ -0,0 +1,75 @@
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
@ -1,56 +0,0 @@
|
||||
Ext.define('PVE.form.VMIDSelector', {
|
||||
extend: 'Ext.form.field.Number',
|
||||
alias: 'widget.pveVMIDSelector',
|
||||
|
||||
allowBlank: false,
|
||||
|
||||
minValue: 100,
|
||||
|
||||
maxValue: 999999999,
|
||||
|
||||
validateExists: undefined,
|
||||
|
||||
loadNextFreeVMID: false,
|
||||
|
||||
initComponent: function() {
|
||||
var me = this;
|
||||
|
||||
Ext.applyIf(me, {
|
||||
fieldLabel: 'VM ID',
|
||||
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(gettext('This VM ID does not exists'));
|
||||
}
|
||||
},
|
||||
failure: function(response, opts) {
|
||||
if (me.validateExists === false) {
|
||||
me.markInvalid(gettext('This VM ID is already in use'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
me.callParent();
|
||||
|
||||
if (me.loadNextFreeVMID) {
|
||||
PVE.Utils.API2Request({
|
||||
url: '/cluster/nextid',
|
||||
method: 'GET',
|
||||
success: function(response, opts) {
|
||||
me.setRawValue(response.result.data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
@ -33,11 +33,11 @@ Ext.define('PVE.ha.VMResourceInputPanel', {
|
||||
|
||||
me.column1 = [
|
||||
{
|
||||
xtype: me.vmid ? 'displayfield' : 'pveVMIDSelector',
|
||||
xtype: me.vmid ? 'displayfield' : 'pveGuestIDSelector',
|
||||
name: 'vmid',
|
||||
fieldLabel: 'VM ID',
|
||||
fieldLabel: (me.vmid && me.guestType === 'ct') ? 'CT' : 'VM',
|
||||
value: me.vmid,
|
||||
loadNextFreeVMID: false,
|
||||
loadNextGuestID: false,
|
||||
validateExists: true
|
||||
},
|
||||
{
|
||||
@ -111,6 +111,7 @@ Ext.define('PVE.ha.VMResourceEdit', {
|
||||
extend: 'PVE.window.Edit',
|
||||
|
||||
vmid: undefined,
|
||||
guestType: undefined,
|
||||
|
||||
initComponent : function() {
|
||||
var me = this;
|
||||
@ -127,11 +128,12 @@ Ext.define('PVE.ha.VMResourceEdit', {
|
||||
|
||||
var ipanel = Ext.create('PVE.ha.VMResourceInputPanel', {
|
||||
create: me.create,
|
||||
vmid: me.vmid
|
||||
vmid: me.vmid,
|
||||
guestType: me.guestType
|
||||
});
|
||||
|
||||
Ext.apply(me, {
|
||||
subject: gettext('VM Resource'),
|
||||
subject: gettext('CT/VM Resource'),
|
||||
isAdd: true,
|
||||
items: [ ipanel ]
|
||||
});
|
||||
|
@ -56,10 +56,11 @@ Ext.define('PVE.ha.ResourcesView', {
|
||||
if (res[1] !== 'vm' && res[1] !== 'ct') {
|
||||
return;
|
||||
}
|
||||
|
||||
var guestType = res[1];
|
||||
var vmid = res[2];
|
||||
|
||||
var win = Ext.create('PVE.ha.VMResourceEdit',{
|
||||
guestType: guestType,
|
||||
vmid: vmid
|
||||
});
|
||||
win.on('destroy', reload);
|
||||
|
@ -194,10 +194,11 @@ Ext.define('PVE.lxc.CreateWizard', {
|
||||
}
|
||||
},
|
||||
{
|
||||
xtype: 'pveVMIDSelector',
|
||||
name: 'vmid',
|
||||
xtype: 'pveGuestIDSelector',
|
||||
name: 'vmid', // backend only knows vmid
|
||||
guestType: 'lxc',
|
||||
value: '',
|
||||
loadNextFreeVMID: true,
|
||||
loadNextFreeID: true,
|
||||
validateExists: false
|
||||
},
|
||||
{
|
||||
|
@ -179,10 +179,11 @@ Ext.define('PVE.window.Clone', {
|
||||
|
||||
col1.push(
|
||||
{
|
||||
xtype: 'pveVMIDSelector',
|
||||
xtype: 'pveGuestIDSelector',
|
||||
name: 'newvmid',
|
||||
guestType: 'qemu',
|
||||
value: '',
|
||||
loadNextFreeVMID: true,
|
||||
loadNextGuestVMID: true,
|
||||
validateExists: false
|
||||
},
|
||||
{
|
||||
|
@ -62,10 +62,11 @@ Ext.define('PVE.qemu.CreateWizard', {
|
||||
}
|
||||
},
|
||||
{
|
||||
xtype: 'pveVMIDSelector',
|
||||
xtype: 'pveGuestIDSelector',
|
||||
name: 'vmid',
|
||||
guestType: 'qemu',
|
||||
value: '',
|
||||
loadNextFreeVMID: true,
|
||||
loadNextFreeID: true,
|
||||
validateExists: false
|
||||
},
|
||||
{
|
||||
|
@ -27,6 +27,22 @@ Ext.define('PVE.window.Restore', {
|
||||
allowBlank: true
|
||||
});
|
||||
|
||||
var IDfield;
|
||||
if (me.vmid) {
|
||||
IDfield = Ext.create('Ext.form.field.Display', {
|
||||
name: 'vmid',
|
||||
value: me.vmid,
|
||||
fieldLabel: (me.vmtype === 'lxc') ? 'CT' : 'VM'
|
||||
});
|
||||
} else {
|
||||
IDfield = Ext.create('PVE.form.GuestIDSelector', {
|
||||
name: 'vmid',
|
||||
guestType: me.vmtype,
|
||||
loadNextGuestID: true,
|
||||
validateExists: false
|
||||
});
|
||||
}
|
||||
|
||||
me.formPanel = Ext.create('Ext.form.Panel', {
|
||||
bodyPadding: 10,
|
||||
border: false,
|
||||
@ -41,14 +57,7 @@ Ext.define('PVE.window.Restore', {
|
||||
fieldLabel: gettext('Source')
|
||||
},
|
||||
storagesel,
|
||||
{
|
||||
xtype: me.vmid ? 'displayfield' : 'pveVMIDSelector',
|
||||
name: 'vmid',
|
||||
fieldLabel: 'VM ID',
|
||||
value: me.vmid,
|
||||
loadNextFreeVMID: me.vmid ? false: true,
|
||||
validateExists: false
|
||||
}
|
||||
IDfield
|
||||
]
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user