ui: qemu: disk edit: refactor to more declarative style using bindings

would technically require a versioned dependency bump to widget
toolkit as the `clearOnDisable` flag is new in 3.4-2, but this is
really only for slight UX improvement, so avoid the hard dependency
bump..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-11-15 10:33:05 +01:00
parent 1e3033bc8f
commit 3f543d7ff7

View File

@ -10,29 +10,23 @@ Ext.define('PVE.qemu.HDInputPanel', {
vmconfig: {}, // used to select usused disks
viewModel: {},
viewModel: {
data: {
isScsi: false,
isVirtIO: false,
},
},
controller: {
xclass: 'Ext.app.ViewController',
onControllerChange: function(field) {
let me = this;
var value = field.getValue();
let vm = this.getViewModel();
var allowIOthread = value.match(/^(virtio|scsi)/);
me.lookup('iothread').setDisabled(!allowIOthread);
if (!allowIOthread) {
me.lookup('iothread').setValue(false);
}
var virtio = value.match(/^virtio/);
me.lookup('ssd').setDisabled(virtio);
if (virtio) {
me.lookup('ssd').setValue(false);
}
me.lookup('scsiController').setVisible(value.match(/^scsi/));
let value = field.getValue();
vm.set('isSCSI', value.match(/^scsi/));
vm.set('isVirtIO', value.match(/^virtio/));
me.fireIdChange();
},
@ -66,6 +60,10 @@ Ext.define('PVE.qemu.HDInputPanel', {
if (view.isCreate) {
vm.set('isIncludedInBackup', true);
}
if (view.confid) {
vm.set('isSCSI', view.confid.match(/^scsi/));
vm.set('isVirtIO', view.confid.match(/^virtio/));
}
},
},
@ -199,7 +197,10 @@ Ext.define('PVE.qemu.HDInputPanel', {
reference: 'scsiController',
bind: me.insideWizard ? {
value: '{current.scsihw}',
} : undefined,
visible: '{isSCSI}',
} : {
visible: '{isSCSI}',
},
renderer: PVE.Utils.render_scsihw,
submitValue: false,
hidden: true,
@ -255,19 +256,23 @@ Ext.define('PVE.qemu.HDInputPanel', {
advancedColumn1.push(
{
xtype: 'proxmoxcheckbox',
disabled: me.confid && me.confid.match(/^virtio/),
fieldLabel: gettext('SSD emulation'),
labelWidth: labelWidth,
name: 'ssd',
reference: 'ssd',
clearOnDisable: true,
bind: {
disabled: '{!isVirtIO}',
},
},
{
xtype: 'proxmoxcheckbox',
disabled: me.confid && !me.confid.match(/^(virtio|scsi)/),
name: 'iothread',
fieldLabel: 'IO thread',
labelWidth: labelWidth,
reference: 'iothread',
name: 'iothread',
clearOnDisable: true,
bind: {
disabled: '{!isVirtIO && !isSCSI}',
},
},
);