[pve-devel] [PATCH manager 4/4] ui: hdmove: modernize/refactor

Aaron Lauterer a.lauterer at proxmox.com
Fri Nov 12 10:53:35 CET 2021


Signed-off-by: Aaron Lauterer <a.lauterer at proxmox.com>
---
 www/manager6/qemu/HDMove.js       | 239 +++++++++++++++++-------------
 www/manager6/qemu/HardwareView.js |   1 +
 2 files changed, 134 insertions(+), 106 deletions(-)

diff --git a/www/manager6/qemu/HDMove.js b/www/manager6/qemu/HDMove.js
index 181b7bdc..6e9b748f 100644
--- a/www/manager6/qemu/HDMove.js
+++ b/www/manager6/qemu/HDMove.js
@@ -1,48 +1,147 @@
 Ext.define('PVE.window.HDMove', {
     extend: 'Ext.window.Window',
+    mixins: ['Proxmox.Mixin.CBind'],
 
     resizable: false,
+    modal: true,
+    width: 350,
+    border: false,
+    layout: 'fit',
+
+    cbindData: function() {
+	let me = this;
+	let qemu = me.type === 'qemu';
+	return {
+	    disk: me.disk,
+	    diskOrVolume: qemu ? 'disk' : 'volume',
+	    diskOrVolumeLabel: qemu ? gettext('Disk') : gettext('Mount Point'),
+	    storageContent: qemu ? 'images' : 'rootdir',
+	    hideFormat: me.disk === 'tpmstate0',
+	    nodename: me.nodename,
+	    title: qemu ? gettext("Move disk") : gettext('Move Volume'),
+	};
+    },
 
+    cbind: {
+	title: '{title}',
+    },
 
-    move_disk: function(disk, storage, format, delete_disk) {
-	var me = this;
-	var qemu = me.type === 'qemu';
-	var params = {};
-	params.storage = storage;
-	params[qemu ? 'disk':'volume'] = disk;
-
-	if (format && qemu) {
-	    params.format = format;
-	}
-
-	if (delete_disk) {
-	    params.delete = 1;
-	}
+    controller: {
+	xclass: 'Ext.app.ViewController',
+
+	move_disk: function(disk, storage, format, delete_disk) {
+	    let me = this;
+	    let view = me.getView();
+	    let qemu = view.type === 'qemu';
+	    let params = {};
+	    params.storage = storage;
+	    params[qemu ? 'disk':'volume'] = disk;
+
+	    if (format && qemu) {
+		params.format = format;
+	    }
+
+	    if (delete_disk) {
+		params.delete = 1;
+	    }
+
+	    let url = '/nodes/' + view.nodename + '/' + view.type + '/' + view.vmid + '/';
+	    url += qemu ? 'move_disk' : 'move_volume';
+
+	    Proxmox.Utils.API2Request({
+		params: params,
+		url: url,
+		waitMsgTarget: me.getView(),
+		method: 'POST',
+		failure: function(response, opts) {
+		    Ext.Msg.alert('Error', response.htmlStatus);
+		},
+		success: function(response, options) {
+		    let upid = response.result.data;
+		    let win = Ext.create('Proxmox.window.TaskViewer', {
+			upid: upid,
+		    });
+		    win.show();
+		    win.on('destroy', function() { view.close(); });
+		},
+	    });
+	},
+
+	onMoveClick: function() {
+		let me = this;
+		let view = me.getView();
+		let form = me.lookup('moveFormPanel').getForm();
+		if (form.isValid()) {
+		    let values = form.getValues();
+		    me.move_disk(view.disk, values.hdstorage, values.diskformat,
+				 values.deleteDisk);
+		}
+	},
 
-	var url = '/nodes/' + me.nodename + '/' + me.type + '/' + me.vmid + '/';
-	url += qemu ? 'move_disk' : 'move_volume';
+	validateForm: function (fp, isValid) {
+	    this.getView().lookup('submitButton').setDisabled(!isValid);
+	},
+    },
 
-	Proxmox.Utils.API2Request({
-	    params: params,
-	    url: url,
-	    waitMsgTarget: me,
-	    method: 'POST',
-	    failure: function(response, opts) {
-		Ext.Msg.alert('Error', response.htmlStatus);
+    buttons: [
+	{
+	    xtype: 'button',
+	    reference: 'submitButton',
+	    cbind: {
+		text: '{title}',
 	    },
-	    success: function(response, options) {
-		var upid = response.result.data;
-		var win = Ext.create('Proxmox.window.TaskViewer', {
-		    upid: upid,
-		});
-		win.show();
-		win.on('destroy', function() { me.close(); });
+	    handler: 'onMoveClick',
+	    disabled: true,
+	},
+    ],
+
+    items: [
+	{
+	    xtype: 'form',
+	    reference: 'moveFormPanel',
+	    bodyPadding: 10,
+	    border: false,
+	    fieldDefaults: {
+		labelWidth: 100,
+		anchor: '100%',
 	    },
-	});
-    },
+	    listeners: {
+		validitychange: 'validateForm',
+	    },
+	    items: [
+		{
+		    xtype: 'displayfield',
+		    cbind: {
+			name: '{diskOrVolume}',
+			fieldLabel: '{diskOrVolumeLabel}',
+			value: '{disk}',
+		    },
+		    vtype: 'StorageId',
+		    allowBlank: false,
+		},
+		{
+		    xtype: 'pveDiskStorageSelector',
+		    storageLabel: gettext('Target Storage'),
+		    cbind: {
+			nodename: '{nodename}',
+			storageContent: '{storageContent}',
+			hideFormat: '{hideFormat}',
+		    },
+		    hideSize: true,
+		},
+		{
+		    xtype: 'proxmoxcheckbox',
+		    fieldLabel: gettext('Delete source'),
+		    name: 'deleteDisk',
+		    uncheckedValue: 0,
+		    checked: false,
+		},
+	    ],
+	},
+    ],
 
     initComponent: function() {
-	var me = this;
+	let me = this;
 
 	if (!me.nodename) {
 	    throw "no node name specified";
@@ -53,81 +152,9 @@ Ext.define('PVE.window.HDMove', {
 	}
 
 	if (!me.type) {
-	    me.type = 'qemu';
+	    throw "no type specified";
 	}
 
-	var qemu = me.type === 'qemu';
-
-        var items = [
-            {
-                xtype: 'displayfield',
-                name: qemu ? 'disk' : 'volume',
-                value: me.disk,
-                fieldLabel: qemu ? gettext('Disk') : gettext('Mount Point'),
-                vtype: 'StorageId',
-                allowBlank: false,
-            },
-        ];
-
-	items.push({
-	    xtype: 'pveDiskStorageSelector',
-	    storageLabel: gettext('Target Storage'),
-	    nodename: me.nodename,
-	    storageContent: qemu ? 'images' : 'rootdir',
-	    hideSize: true,
-	    hideFormat: me.disk === 'tpmstate0',
-	});
-
-	items.push({
-	    xtype: 'proxmoxcheckbox',
-	    fieldLabel: gettext('Delete source'),
-	    name: 'deleteDisk',
-	    uncheckedValue: 0,
-	    checked: false,
-	});
-
-	me.formPanel = Ext.create('Ext.form.Panel', {
-	    bodyPadding: 10,
-	    border: false,
-	    fieldDefaults: {
-		labelWidth: 100,
-		anchor: '100%',
-	    },
-	    items: items,
-	});
-
-	var form = me.formPanel.getForm();
-
-	var submitBtn;
-
-	me.title = qemu ? gettext("Move disk") : gettext('Move Volume');
-	submitBtn = Ext.create('Ext.Button', {
-	    text: me.title,
-	    handler: function() {
-		if (form.isValid()) {
-		    var values = form.getValues();
-		    me.move_disk(me.disk, values.hdstorage, values.diskformat,
-				 values.deleteDisk);
-		}
-	    },
-	});
-
-	Ext.apply(me, {
-	    modal: true,
-	    width: 350,
-	    border: false,
-	    layout: 'fit',
-	    buttons: [submitBtn],
-	    items: [me.formPanel],
-	});
-
-
 	me.callParent();
-
-	me.mon(me.formPanel, 'validitychange', function(fp, isValid) {
-	    submitBtn.setDisabled(!isValid);
-	});
-
-	me.formPanel.isValid();
     },
 });
diff --git a/www/manager6/qemu/HardwareView.js b/www/manager6/qemu/HardwareView.js
index 44d70665..e7ee1dbe 100644
--- a/www/manager6/qemu/HardwareView.js
+++ b/www/manager6/qemu/HardwareView.js
@@ -415,6 +415,7 @@ Ext.define('PVE.qemu.HardwareView', {
 		disk: rec.data.key,
 		nodename: nodename,
 		vmid: vmid,
+		type: 'qemu',
 	    });
 
 	    win.show();
-- 
2.30.2






More information about the pve-devel mailing list