[pve-devel] [PATCH manager 4/9] Make the Snapshot selector an optional parameter in the Clone Window

Emmanuel Kasper e.kasper at proxmox.com
Thu Jan 12 10:13:57 CET 2017


The snapshot selector was known to confuse first time pve users.
Some wondered that they had no snapshot called 'current' in their
snapshot trees, and other thought that snapshots would be included
in the copied image.

So before displaying the Clone Window, do an API call to verify
if the source VM has snapshots.
---
 www/manager6/qemu/Clone.js   |  5 ++++-
 www/manager6/qemu/CmdMenu.js | 20 ++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/www/manager6/qemu/Clone.js b/www/manager6/qemu/Clone.js
index 3cca65e..50e74e0 100644
--- a/www/manager6/qemu/Clone.js
+++ b/www/manager6/qemu/Clone.js
@@ -19,6 +19,9 @@ Ext.define('PVE.window.Clone', {
 	}
     },
 
+    // if set to true, will display an extra snapshot selector combobox
+    hasSnapshots: false,
+
     create_clone: function(values) {
 	var me = this;
 
@@ -182,7 +185,7 @@ Ext.define('PVE.window.Clone', {
 	    fieldLabel: gettext('Snapshot'),
             nodename: me.nodename,
             vmid: me.vmid,
-	    hidden: me.isTemplate ? true : false,
+	    hidden: me.isTemplate || !me.hasSnapshots ? true : false,
             disabled: false,
 	    allowBlank: false,
 	    value : me.snapname,
diff --git a/www/manager6/qemu/CmdMenu.js b/www/manager6/qemu/CmdMenu.js
index 7a95e36..eabad65 100644
--- a/www/manager6/qemu/CmdMenu.js
+++ b/www/manager6/qemu/CmdMenu.js
@@ -129,11 +129,23 @@ Ext.define('PVE.qemu.CmdMenu', {
 		iconCls: 'fa fa-fw fa-clone',
 		hidden: caps.vms['VM.Clone'] ? false : true,
 		handler: function() {
-		    var win = Ext.create('PVE.window.Clone', {
-			nodename: nodename,
-			vmid: vmid
+		    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();
+			}
 		    });
-		    win.show();
 		}
 	    },
 	    {
-- 
2.1.4





More information about the pve-devel mailing list