[pve-devel] [PATCH 7/9] snapshot tree : add create_template, delete_template, clone_template

Alexandre Derumier aderumier at odiso.com
Tue Dec 18 10:18:23 CET 2012


fixme : enablefn bug (is_template sub)

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 www/manager/qemu/SnapshotTree.js |  117 +++++++++++++++++++++++++++++++++++---
 1 file changed, 109 insertions(+), 8 deletions(-)

diff --git a/www/manager/qemu/SnapshotTree.js b/www/manager/qemu/SnapshotTree.js
index 0fd1b82..3f28720 100644
--- a/www/manager/qemu/SnapshotTree.js
+++ b/www/manager/qemu/SnapshotTree.js
@@ -38,15 +38,15 @@ Ext.define('PVE.qemu.SnapshotTree', {
 		Ext.Array.each(response.result.data, function(item) {
 		    item.leaf = true;
 		    item.children = [];
+
+	            var running = item.running ? '-running' : '';
+        	    var template = item.template ? '-template' : '';
+
 		    if (item.name === 'current') {
 			digest = item.digest + item.running;
-			if (item.running) {
-			    item.iconCls = 'x-tree-node-computer-running';
-			} else {
-			    item.iconCls = 'x-tree-node-computer';
-			}
+	                item.iconCls = 'x-tree-node-computer' + running + template;
 		    } else {
-			item.iconCls = 'x-tree-node-snapshot';
+                        item.iconCls = 'x-tree-node-snapshot' + template;
 		    }
 		    idhash[item.name] = item;
 		});
@@ -99,6 +99,14 @@ Ext.define('PVE.qemu.SnapshotTree', {
 		record.data.name !== 'current' && !record.data.snapstate;
 	};
 
+	var valid_template = function(record) {
+	    return record && record.data && record.data.template;
+	};
+
+	var valid_not_template = function(record) {
+	    return record && record.data && !record.data.template && !record.data.snapstate;
+	};
+
 	var run_editor = function() {
 	    var rec = sm.getSelection()[0];
 	    if (valid_snapshot(rec)) {
@@ -112,6 +120,19 @@ Ext.define('PVE.qemu.SnapshotTree', {
 	    }
 	};
 
+	var run_clone = function() {
+	    var rec = sm.getSelection()[0];
+	    if (valid_template(rec)) {
+		var win = Ext.create('PVE.window.Clone', { 
+		    snapname: rec.data.name,
+		    nodename: me.nodename,
+		    vmid: me.vmid
+		});
+		win.show();
+		me.mon(win, 'close', me.reload, me);
+	    }
+	};
+
 	var editBtn = new PVE.button.Button({
 	    text: gettext('Edit'),
 	    disabled: true,
@@ -203,15 +224,95 @@ Ext.define('PVE.qemu.SnapshotTree', {
 	    }
 	});
 
+
+	var templateBtn = new PVE.button.Button({
+	    text: gettext('Create Template'),
+	    enableFn: valid_not_template,
+	    disabled: true,
+	    selModel: sm,
+            handler: function(btn, event) {
+                var rec = sm.getSelection()[0];
+                if (!rec) {
+                    return;
+                }
+		var params = {};
+
+                if (rec.data.name && rec.data.name !== 'current') {
+                    params.snapname = rec.data.name;
+                } 
+
+                PVE.Utils.API2Request({
+                    url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/template',
+                    params: params,
+                    method: 'POST',
+                    waitMsgTarget: me,
+                    callback: function() {
+                        me.reload();
+                    },
+                    failure: function (response, opts) {
+                        Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+                    },
+                    success: function(response, options) {
+                        //win.show();
+                    }
+                });
+            }
+
+	});
+
+	var templatedeleteBtn = new PVE.button.Button({
+	    text: gettext('Delete Template'),
+	    enableFn: valid_template,
+	    disabled: true,
+	    selModel: sm,
+            handler: function(btn, event) {
+                var rec = sm.getSelection()[0];
+                if (!rec) {
+                    return;
+                }
+		var params = { delete:1 };
+
+                if (rec.data.name && rec.data.name !== 'current') {
+                    params.snapname = rec.data.name;
+                } 
+
+                PVE.Utils.API2Request({
+                    url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/template',
+                    params: params,
+                    method: 'POST',
+                    waitMsgTarget: me,
+                    callback: function() {
+                        me.reload();
+                    },
+                    failure: function (response, opts) {
+                        Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+                    },
+                    success: function(response, options) {
+                        //win.show();
+                    }
+                });
+            }
+
+	});
+
+	var cloneBtn = new PVE.button.Button({ 
+	    text: gettext('Clone Template'),
+	    disabled: true,
+	    selModel: sm,
+	    enableFn: valid_template,
+	    handler: run_clone
+	});
+
+
 	Ext.apply(me, {
 	    layout: 'fit',
 	    rootVisible: false,
 	    animate: false,
 	    sortableColumns: false,
 	    selModel: sm,
-	    tbar: [ snapshotBtn, rollbackBtn, removeBtn, editBtn ],
+	    tbar: [ snapshotBtn, rollbackBtn, removeBtn, editBtn, templateBtn, templatedeleteBtn, cloneBtn ],
 	    fields: [ 
-		'name', 'description', 'snapstate', 'vmstate', 'running',
+		'name', 'description', 'snapstate', 'vmstate', 'running', 'template',
 		{ name: 'snaptime', type: 'date', dateFormat: 'timestamp' }
 	    ],
 	    columns: [
-- 
1.7.10.4




More information about the pve-devel mailing list