[pve-devel] [PATCH manager 2/3] Rework Migrate Window with declarative synthax

Emmanuel Kasper e.kasper at proxmox.com
Thu Aug 24 11:45:19 CEST 2017


Also group all qemu vs LXC tests in a single place.
---
 www/manager6/window/Migrate.js | 217 ++++++++++++++++++++++-------------------
 1 file changed, 116 insertions(+), 101 deletions(-)

diff --git a/www/manager6/window/Migrate.js b/www/manager6/window/Migrate.js
index 17ef8f67..1434d40c 100644
--- a/www/manager6/window/Migrate.js
+++ b/www/manager6/window/Migrate.js
@@ -1,65 +1,70 @@
 Ext.define('PVE.window.Migrate', {
     extend: 'Ext.window.Window',
 
-    resizable: false,
-
-    migrate: function(target, online) {
-	var me = this;
-	var params = {
-	    target: target
-	};
-
-	if (me.vmtype === 'qemu') {
-	    params.online = online;
-	} else {
-	    params.restart = online;
-	}
-
-	PVE.Utils.API2Request({
-	    params: params,
-	    url: '/nodes/' + me.nodename + '/' + me.vmtype + '/' + me.vmid + "/migrate",
-	    waitMsgTarget: me,
-	    method: 'POST',
-	    failure: function(response, opts) {
-		Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+    config: {
+	vmtype: undefined,
+	nodename: undefined,
+	vmid: undefined
+    },
+ // private, used to store the migration mode after checking if the guest runs
+    liveMode: undefined,
+
+    controller: {
+	xclass: 'Ext.app.ViewController',
+	control: {
+	    'panel[reference=formPanel]': {
+		validityChange: function(panel, isValid) {
+		    this.lookup('submitButton').setDisabled(!isValid);
+		}
 	    },
-	    success: function(response, options) {
-		var upid = response.result.data;
-		var extraTitle = Ext.String.format(' ({0} ---> {1})', me.nodename, target);
-
-		var win = Ext.create('PVE.window.TaskViewer', {
-		    upid: upid,
-		    extraTitle: extraTitle
-		});
-		win.show();
-		me.close();
+	    'button[reference=submitButton]': {
+		click: function() {
+		    var me = this;
+		    var view = me.getView();
+
+		    var values = me.lookup('formPanel').getValues();
+		    var params = {
+			target: values.target
+		    };
+
+		    if (values.online) {
+			params[view.liveMode] = values.online;
+		    }
+
+		    PVE.Utils.API2Request({
+			params: params,
+			url: '/nodes/' + view.nodename + '/' + view.vmtype + '/' + view.vmid + '/migrate',
+			waitMsgTarget: view,
+			method: 'POST',
+			failure: function(response, opts) {
+			    Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+			},
+			success: function(response, options) {
+			    var upid = response.result.data;
+			    var extraTitle = Ext.String.format(' ({0} ---> {1})', view.nodename, params.target);
+
+			    Ext.create('PVE.window.TaskViewer', {
+				upid: upid,
+				extraTitle: extraTitle
+			    }).show();
+
+			    view.close();
+			}
+		    });
+		}
 	    }
-	});
-    },
-
-    initComponent : function() {
-	var me = this;
-
-	if (!me.nodename) {
-	    throw "no node name specified";
-	}
-
-	if (!me.vmid) {
-	    throw "no VM ID specified";
-	}
-
-	if (!me.vmtype) {
-	    throw "no VM type specified";
-	}
-
-	var running = false;
-	var vmrec = PVE.data.ResourceStore.findRecord('vmid', me.vmid,
-						      0, false, false, true);
-	if (vmrec && vmrec.data && vmrec.data.running) {
-	    running = true;
 	}
+    },
 
-	me.formPanel = Ext.create('Ext.form.Panel', {
+    width: 350,
+    modal: true,
+    layout: 'auto',
+    border: false,
+    resizable: false,
+    items: [
+	{
+	    xtype: 'form',
+	    reference: 'formPanel',
 	    bodyPadding: 10,
 	    border: false,
 	    fieldDefaults: {
@@ -69,70 +74,80 @@ Ext.define('PVE.window.Migrate', {
 	    items: [
 		{
 		    xtype: 'pveNodeSelector',
+		    reference: 'pveNodeSelector',
 		    name: 'target',
 		    fieldLabel: gettext('Target node'),
 		    allowBlank: false,
-		    disallowedNodes: [me.nodename],
+		    disallowedNodes: undefined,
 		    onlineValidator: true
 		},
 		{
 		    xtype: 'pvecheckbox',
+		    reference: 'onlineToggle',
 		    name: 'online',
 		    uncheckedValue: 0,
 		    defaultValue: 0,
-		    checked: running,
-		    fieldLabel: me.vmtype === 'qemu' ? gettext('Online') : gettext('Restart Mode')
+		    checked: false,
+		    fieldLabel: gettext('Restart Mode')
 		}
-	    ]
-	});
-
-	var form = me.formPanel.getForm();
+		]
+	}
+    ],
+    buttons: [
+	{
+	    xtype: 'pveHelpButton',
+	    reference: 'pveHelpButton',
+	    onlineHelp: 'pct_migration',
+	    listenToGlobalEvent: false,
+	    hidden: false
+	},
+	'->',
+	{
+	    xtype: 'button',
+	    reference: 'submitButton',
+	    text: gettext('Migrate')
+	}
+    ],
 
-	var submitBtn = Ext.create('Ext.Button', {
-	    text: gettext('Migrate'),
-	    handler: function() {
-		var values = form.getValues();
-		me.migrate(values.target, values.online);
-	    }
-	});
+    initComponent : function() {
+	var me = this;
 
-	var helpConfig;
-	// fixme:
-	// the onlinehelp parser needs
-	// that every id is explicitely written
-	// can we do this better?
-	if (me.vmtype === 'qemu') {
-	    helpConfig = {
-		onlineHelp: 'qm_migration',
-		listenToGlobalEvent: false,
-		hidden: false
-	    };
-	} else {
-	    helpConfig = {
-		onlineHelp: 'pct_migration',
-		listenToGlobalEvent: false,
-		hidden: false
-	    };
+	if (!me.nodename) {
+	    throw "no node name specified";
 	}
 
-	var helpBtn = Ext.create('PVE.button.Help', helpConfig);
+	if (!me.vmid) {
+	    throw "no VM ID specified";
+	}
 
-	Ext.apply(me, {
-	    title: gettext('Migrate') + ((me.vmtype === 'qemu')?' VM ':' CT ') + me.vmid,
-	    width: 350,
-	    modal: true,
-	    layout: 'auto',
-	    border: false,
-	    items: [ me.formPanel ],
-	    buttons: [ helpBtn, '->', submitBtn ]
-	});
+	if (!me.vmtype) {
+	    throw "no VM type specified";
+	}
 
 	me.callParent();
 
-	me.mon(me.formPanel, 'validitychange', function(fp, isValid) {
-	    submitBtn.setDisabled(!isValid);
-	});
+	var title = gettext('Migrate') + (' CT ') + me.vmid;
+	me.liveMode = 'restart';
+
+	if (me.vmtype === 'qemu') {
+	    me.lookup('onlineToggle').setFieldLabel(gettext('Online'));
+	    me.lookup('pveHelpButton').setHelpConfig({
+		onlineHelp: 'qm_migration'
+	    });
+	    title = gettext('Migrate') + (' VM ') + me.vmid;
+	    me.liveMode = 'online';
+	}
+	me.setTitle(title);
+
+	var running = false;
+	var vmrec = PVE.data.ResourceStore.findRecord('vmid', me.vmid,
+	    0, false, false, true);
+	if (vmrec && vmrec.data && vmrec.data.running) {
+	    running = true;
+	}
+	me.lookup('onlineToggle').setValue(running);
 
-	me.formPanel.isValid();
+	me.lookup('pveNodeSelector').disallowedNodes = [me.nodename];
+	me.lookup('formPanel').isValid();
     }
-});
+});
\ No newline at end of file
-- 
2.11.0





More information about the pve-devel mailing list