[pve-devel] [PATCH manager 2/3] Move the snapshot API test to a static function

Emmanuel Kasper e.kasper at proxmox.com
Mon Feb 6 19:03:26 CET 2017


This will allow code reuse in a following patch.

No functional change.
---
 www/manager6/qemu/Clone.js   | 25 +++++++++++++++++++++++--
 www/manager6/qemu/CmdMenu.js | 18 +-----------------
 2 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/www/manager6/qemu/Clone.js b/www/manager6/qemu/Clone.js
index 8a3b34a..cb7e670 100644
--- a/www/manager6/qemu/Clone.js
+++ b/www/manager6/qemu/Clone.js
@@ -19,8 +19,29 @@ Ext.define('PVE.window.Clone', {
 	}
     },
 
-    // if set to true, will display an extra snapshot selector combobox
-    hasSnapshots: false,
+    statics: {
+	// display a snapshot selector only if needed
+	wrap: function(nodename, vmid, isTemplate) {
+	    PVE.Utils.API2Request({
+		url: '/nodes/' + nodename + '/qemu/' + vmid +'/snapshot',
+		failure: function(response, opts) {
+		    Ext.Msg.alert('Error', response.htmlStatus);
+		},
+		success: function(response, opts) {
+		    var snapshotList = response.result.data;
+		    var hasSnapshots = snapshotList.length === 1 &&
+			snapshotList[0].name === 'current' ? false : true;
+
+		    Ext.create('PVE.window.Clone', {
+			nodename: nodename,
+			vmid: vmid,
+			isTemplate: isTemplate,
+			hasSnapshots: hasSnapshots
+		    }).show();
+		}
+	    });
+	}
+    },
 
     create_clone: function(values) {
 	var me = this;
diff --git a/www/manager6/qemu/CmdMenu.js b/www/manager6/qemu/CmdMenu.js
index eabad65..aa525b8 100644
--- a/www/manager6/qemu/CmdMenu.js
+++ b/www/manager6/qemu/CmdMenu.js
@@ -129,23 +129,7 @@ Ext.define('PVE.qemu.CmdMenu', {
 		iconCls: 'fa fa-fw fa-clone',
 		hidden: caps.vms['VM.Clone'] ? false : true,
 		handler: function() {
-		    PVE.Utils.API2Request({
-			url: '/nodes/' + nodename + '/qemu/' + vmid +'/snapshot',
-			failure: function(response, opts) {
-			    Ext.Msg.alert('Error', response.htmlStatus);
-			},
-			success: function(response, opts) {
-			    var snapshotList = response.result.data;
-			    var hasSnapshots = snapshotList.length === 1 &&
-				snapshotList[0].name === 'current' ? false : true;
-
-			    Ext.create('PVE.window.Clone', {
-				nodename: nodename,
-				vmid: vmid,
-				hasSnapshots: hasSnapshots
-			    }).show();
-			}
-		    });
+		    PVE.window.Clone.wrap(nodename, vmid, me.isTemplate);
 		}
 	    },
 	    {
-- 
2.1.4





More information about the pve-devel mailing list