[pve-devel] [PATCH manager] gui: add revert button for lxc pending changes

Oguz Bektas o.bektas at proxmox.com
Mon Oct 21 17:26:34 CEST 2019


adds the pending button for Resources, Options and DNS screens.

Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
---
 www/manager6/lxc/DNS.js       | 39 +++++++++++++++++++++++--
 www/manager6/lxc/Options.js   | 54 +++++++++++++++++++++++++++++++++--
 www/manager6/lxc/Resources.js | 31 +++++++++++++++++++-
 3 files changed, 119 insertions(+), 5 deletions(-)

diff --git a/www/manager6/lxc/DNS.js b/www/manager6/lxc/DNS.js
index 89e2c694..ceca1d34 100644
--- a/www/manager6/lxc/DNS.js
+++ b/www/manager6/lxc/DNS.js
@@ -213,6 +213,38 @@ Ext.define('PVE.lxc.DNS', {
 	    handler: run_editor
 	});
 
+	var revert_btn = new Proxmox.button.Button({
+	    text: gettext('Revert'),
+	    disabled: true,
+	    handler: function() {
+		var sm = me.getSelectionModel();
+		var rec = sm.getSelection()[0];
+		if (!rec) {
+		    return;
+		}
+
+		var rowdef = me.rows[rec.data.key] || {};
+		var keys = rowdef.multiKey ||  [ rec.data.key ];
+		var revert = keys.join(',');
+
+		Proxmox.Utils.API2Request({
+		    url: '/api2/extjs/' + baseurl,
+		    waitMsgTarget: me,
+		    method: 'PUT',
+		    params: {
+			'revert': revert
+		    },
+		    callback: function() {
+			me.reload();
+		    },
+		    failure: function (response, opts) {
+			Ext.Msg.alert('Error',response.htmlStatus);
+		    }
+		});
+	    }
+	});
+
+
 	var set_button_status = function() {
 	    var sm = me.getSelectionModel();
 	    var rec = sm.getSelection()[0];
@@ -221,8 +253,11 @@ Ext.define('PVE.lxc.DNS', {
 		edit_btn.disable();
 		return;
 	    }
-	    var rowdef = rows[rec.data.key];
+	    var key = rec.data.key;
+	    var rowdef = rows[key];
+	    var pending = rec.data['delete'] || me.hasPendingChanges(key);
 	    edit_btn.setDisabled(!rowdef.editor);
+	    revert_btn.setDisabled(!pending);
 	};
 
 	Ext.apply(me, {
@@ -230,7 +265,7 @@ Ext.define('PVE.lxc.DNS', {
 	    selModel: sm,
 	    cwidth1: 150,
 	    run_editor: run_editor,
-	    tbar: [ edit_btn ],
+	    tbar: [ edit_btn, revert_btn ],
 	    rows: rows,
 	    editorConfig: {
 		url: "/api2/extjs/" + baseurl
diff --git a/www/manager6/lxc/Options.js b/www/manager6/lxc/Options.js
index 5e1e0222..b33d233f 100644
--- a/www/manager6/lxc/Options.js
+++ b/www/manager6/lxc/Options.js
@@ -161,17 +161,67 @@ Ext.define('PVE.lxc.Options', {
 	    handler: function() { me.run_editor(); }
 	});
 
+	var revert_btn = new Proxmox.button.Button({
+	    text: gettext('Revert'),
+	    disabled: true,
+	    handler: function() {
+		var sm = me.getSelectionModel();
+		var rec = sm.getSelection()[0];
+		if (!rec) {
+		    return;
+		}
+
+		var rowdef = me.rows[rec.data.key] || {};
+		var keys = rowdef.multiKey ||  [ rec.data.key ];
+		var revert = keys.join(',');
+
+		Proxmox.Utils.API2Request({
+		    url: '/api2/extjs/' + baseurl,
+		    waitMsgTarget: me,
+		    method: 'PUT',
+		    params: {
+			'revert': revert
+		    },
+		    callback: function() {
+			me.reload();
+		    },
+		    failure: function (response, opts) {
+			Ext.Msg.alert('Error',response.htmlStatus);
+		    }
+		});
+	    }
+	});
+
+	var set_button_status = function() {
+	    var sm = me.getSelectionModel();
+	    var rec = sm.getSelection()[0];
+
+	    if (!rec) {
+		edit_btn.disable();
+		return;
+	    }
+
+	    var key = rec.data.key;
+	    var pending = rec.data['delete'] || me.hasPendingChanges(key);
+	    var rowdef = rows[key];
+
+	    edit_btn.setDisabled(!rowdef.editor);
+	    revert_btn.setDisabled(!pending);
+	};
+
+
 	Ext.apply(me, {
 	    url: "/api2/json/nodes/" + nodename + "/lxc/" + vmid + "/pending",
 	    selModel: sm,
 	    interval: 5000,
-	    tbar: [ edit_btn ],
+	    tbar: [ edit_btn, revert_btn ],
 	    rows: rows,
 	    editorConfig: {
 		url: '/api2/extjs/' + baseurl
 	    },
 	    listeners: {
-		itemdblclick: me.run_editor
+		itemdblclick: me.run_editor,
+		selectionchange: set_button_status
 	    }
 	});
 
diff --git a/www/manager6/lxc/Resources.js b/www/manager6/lxc/Resources.js
index 8b924a49..b31e101a 100644
--- a/www/manager6/lxc/Resources.js
+++ b/www/manager6/lxc/Resources.js
@@ -215,6 +215,31 @@ Ext.define('PVE.lxc.RessourceView', {
 	    handler: run_move
 	});
 
+	var revert_btn = new Proxmox.button.Button({
+	    text: gettext('Revert'),
+	    selModel: me.selModel,
+	    disabled: true,
+	    handler: function(b, e, rec) {
+		var rowdef = me.rows[rec.data.key] || {};
+		var keys = rowdef.multiKey ||  [ rec.data.key ];
+		var revert = keys.join(',');
+		Proxmox.Utils.API2Request({
+		    url: '/api2/extjs/' + baseurl,
+		    waitMsgTarget: me,
+		    method: 'PUT',
+		    params: {
+			'revert': revert
+		    },
+		    callback: function() {
+			me.rstore.load();
+		    },
+		    failure: function (response, opts) {
+			Ext.Msg.alert('Error',response.htmlStatus);
+		    }
+		});
+	    }
+	});
+
 	var set_button_status = function() {
 	    var rec = me.selModel.getSelection()[0];
 
@@ -222,12 +247,14 @@ Ext.define('PVE.lxc.RessourceView', {
 		edit_btn.disable();
 		remove_btn.disable();
 		resize_btn.disable();
+		revert_btn.distable();
 		return;
 	    }
 	    var key = rec.data.key;
 	    var value = rec.data.value;
 	    var rowdef = rows[key];
 
+	    var pending = rec.data['delete'] || me.hasPendingChanges(key);
 	    var isDisk = (rowdef.tdCls == 'pve-itype-icon-storage');
 
 	    var noedit = rec.data['delete'] || !rowdef.editor;
@@ -242,6 +269,7 @@ Ext.define('PVE.lxc.RessourceView', {
 	    remove_btn.setDisabled(!isDisk || rec.data.key === 'rootfs' || !diskCap);
 	    resize_btn.setDisabled(!isDisk || !diskCap);
 	    move_btn.setDisabled(!isDisk || !diskCap);
+	    revert_btn.setDisabled(!pending);
 
 	};
 	
@@ -299,7 +327,8 @@ Ext.define('PVE.lxc.RessourceView', {
 		edit_btn,
 		remove_btn,
 		resize_btn,
-		move_btn
+		move_btn,
+		revert_btn
 	    ],
 	    rows: rows,
 	    sorterFn: sorterFn,
-- 
2.20.1




More information about the pve-devel mailing list