[pve-devel] [PATCH 8/8] add clone panel form

Alexandre Derumier aderumier at odiso.com
Wed Dec 12 13:32:43 CET 2012


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 www/manager/Makefile      |    1 +
 www/manager/qemu/Clone.js |  141 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 142 insertions(+)
 create mode 100644 www/manager/qemu/Clone.js

diff --git a/www/manager/Makefile b/www/manager/Makefile
index d14ee66..0baed3a 100644
--- a/www/manager/Makefile
+++ b/www/manager/Makefile
@@ -101,6 +101,7 @@ JSSRC= 				                 	\
 	qemu/ScsiHwEdit.js				\
 	qemu/Options.js					\
 	qemu/Snapshot.js				\
+	qemu/Clone.js					\
 	qemu/SnapshotTree.js				\
 	qemu/Config.js					\
 	qemu/CreateWizard.js				\
diff --git a/www/manager/qemu/Clone.js b/www/manager/qemu/Clone.js
new file mode 100644
index 0000000..e111d5a
--- /dev/null
+++ b/www/manager/qemu/Clone.js
@@ -0,0 +1,141 @@
+Ext.define('PVE.window.Clone', {
+    extend: 'Ext.window.Window',
+
+    resizable: false,
+
+
+    create_clone: function(snapname, name, newvmid) {
+	var me = this;
+        var params =  { name: name, clonefrom: me.vmid, vmid: newvmid };
+
+        if (snapname && snapname !== 'current') {
+            params.snapname = snapname;
+        }
+
+	PVE.Utils.API2Request({
+	    params: params,
+	    url: '/nodes/' + me.nodename + '/qemu',
+	    waitMsgTarget: me,
+	    method: 'POST',
+	    failure: function(response, opts) {
+		Ext.Msg.alert('Error', response.htmlStatus);
+	    },
+	    success: function(response, options) {
+		me.close();
+	    }
+	});
+    },
+
+    initComponent : function() {
+	var me = this;
+
+	if (!me.nodename) {
+	    throw "no node name specified";
+	}
+
+	if (!me.vmid) {
+	    throw "no VM ID specified";
+	}
+
+	var items = [
+	    {
+		xtype: 'displayfield',
+		name: 'snapname',
+		value: me.snapname,
+		fieldLabel: 'Template Name',
+		vtype: 'StorageId',
+		allowBlank: false
+	    },
+	    {
+                xtype: 'pveVMIDSelector',
+                name: 'newvmid',
+                value: '',
+                loadNextFreeVMID: true,
+                validateExists: false
+            },
+
+	];
+
+
+	items.push({
+	    xtype: 'textfield',
+	    grow: true,
+	    name: 'name',
+	    allowBlank: false,
+	    fieldLabel: 'Name'
+	});
+
+
+	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 = "Clone Template '" + me.snapname + " of VM " + me.vmid;
+	submitBtn = Ext.create('Ext.Button', {
+	    text: gettext('Clone'),
+	    handler: function() {
+		if (form.isValid()) {
+		    var values = form.getValues();
+		    me.create_clone(me.snapname, values.name, values.newvmid);
+		}
+	    }
+	});
+
+	Ext.apply(me, {
+	    modal: true,
+	    width: 300,
+	    height: 200,
+	    border: false,
+	    layout: 'fit',
+	    buttons: [ submitBtn ],
+	    items: [ me.formPanel ]
+	});
+
+
+	me.callParent();
+
+	if (!me.snapname) {
+	    return;
+	}
+
+        var url;
+
+        if (me.snapsname) {
+	    url = '/nodes/' + me.nodename + '/qemu/' + me.vmid + "/snapshot/" + me.snapname + '/config';
+        } else {
+	    url = '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/config';
+        }
+
+	// else load data
+	PVE.Utils.API2Request({
+	    url: url,
+	    waitMsgTarget: me,
+	    method: 'GET',
+	    failure: function(response, opts) {
+		Ext.Msg.alert('Error', response.htmlStatus);
+		me.close();
+	    },
+	    success: function(response, options) {
+		var data = response.result.data;
+		var kvarray = [];
+		Ext.Object.each(data, function(key, value) {
+		    if (key === 'description' || key === 'snaptime') {
+			return;
+		    }
+		    kvarray.push({ key: key, value: value });
+		});
+
+	    }
+	});
+    }
+});
-- 
1.7.10.4




More information about the pve-devel mailing list