[pve-devel] applied: [PATCH manager] ui: factor out pending changes revert button

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Oct 30 11:48:58 CET 2019


makes no sense to have the, more or less, exact same 25 line method 5
times..

could be moved to widget TK, but that's for another time.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 www/manager6/Makefile             |  1 +
 www/manager6/button/Revert.js     | 38 +++++++++++++++++++++++++++++++
 www/manager6/lxc/DNS.js           | 32 ++------------------------
 www/manager6/lxc/Options.js       | 31 ++-----------------------
 www/manager6/lxc/Resources.js     | 25 ++------------------
 www/manager6/qemu/HardwareView.js | 26 +++------------------
 www/manager6/qemu/Options.js      | 33 +++------------------------
 7 files changed, 51 insertions(+), 135 deletions(-)
 create mode 100644 www/manager6/button/Revert.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index aa460c3b..b7ffc44b 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -8,6 +8,7 @@ JSSRC= 				                 	\
 	menu/MenuItem.js				\
 	menu/TemplateMenu.js				\
 	button/ConsoleButton.js				\
+	button/Revert.js				\
 	button/Split.js					\
 	controller/StorageEdit.js			\
 	qemu/CmdMenu.js					\
diff --git a/www/manager6/button/Revert.js b/www/manager6/button/Revert.js
new file mode 100644
index 00000000..3d846c6c
--- /dev/null
+++ b/www/manager6/button/Revert.js
@@ -0,0 +1,38 @@
+Ext.define('PVE.button.PendingRevert', {
+    extend: 'Proxmox.button.Button',
+    alias: 'widget.pvePendingRevertButton',
+
+    text: gettext('Revert'),
+    disabled: true,
+    config: {
+	pendingGrid: null,
+	baseurl: undefined,
+    },
+
+    handler: function() {
+	let view = this.pendingGrid;
+
+	let rec = view.getSelectionModel().getSelection()[0];
+	if (!rec) return;
+
+	let rowdef = view.rows[rec.data.key] || {};
+	let keys = rowdef.multiKey ||  [ rec.data.key ];
+
+	Proxmox.Utils.API2Request({
+	    url: this.baseurl || view.editorConfig.url,
+	    waitMsgTarget: view,
+	    selModel: view.getSelectionModel(),
+	    method: 'PUT',
+	    params: {
+		'revert': keys.join(',')
+	    },
+	    callback: () => view.reload(),
+	    failure: (response) => Ext.Msg.alert('Error', response.htmlStatus),
+	});
+    },
+
+    initComponent: function() {
+	if (!this.pendingGrid) throw "revert button requires a pendingGrid";
+	this.callParent(arguments);
+    },
+});
diff --git a/www/manager6/lxc/DNS.js b/www/manager6/lxc/DNS.js
index f5b85db5..bf110f09 100644
--- a/www/manager6/lxc/DNS.js
+++ b/www/manager6/lxc/DNS.js
@@ -213,38 +213,10 @@ 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 revert_btn = new PVE.button.PendingRevert({
+	    pendingGrid: me,
 	});
 
-
 	var set_button_status = function() {
 	    var sm = me.getSelectionModel();
 	    var rec = sm.getSelection()[0];
diff --git a/www/manager6/lxc/Options.js b/www/manager6/lxc/Options.js
index 8ed3a5fc..409f8b70 100644
--- a/www/manager6/lxc/Options.js
+++ b/www/manager6/lxc/Options.js
@@ -161,35 +161,8 @@ 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 revert_btn = new PVE.button.PendingRevert({
+	    pendingGrid: me,
 	});
 
 	var set_button_status = function() {
diff --git a/www/manager6/lxc/Resources.js b/www/manager6/lxc/Resources.js
index 73533ba8..f70f9e02 100644
--- a/www/manager6/lxc/Resources.js
+++ b/www/manager6/lxc/Resources.js
@@ -215,29 +215,8 @@ 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 revert_btn = new PVE.button.PendingRevert({
+	    pendingGrid: me,
 	});
 
 	var set_button_status = function() {
diff --git a/www/manager6/qemu/HardwareView.js b/www/manager6/qemu/HardwareView.js
index 29cdb68c..3f6273c4 100644
--- a/www/manager6/qemu/HardwareView.js
+++ b/www/manager6/qemu/HardwareView.js
@@ -500,29 +500,9 @@ Ext.define('PVE.qemu.HardwareView', {
 	    }
 	});
 
-	var revert_btn = new Proxmox.button.Button({
-	    text: gettext('Revert'),
-	    selModel: sm,
-	    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() {
-			reload();
-		    },
-		    failure: function (response, opts) {
-			Ext.Msg.alert('Error',response.htmlStatus);
-		    }
-		});
-	    }
+	var revert_btn = new PVE.button.PendingRevert({
+	    pendingGrid: me,
+	    baseurl: '/api2/extjs/' + baseurl,
 	});
 
 	var efidisk_menuitem = Ext.create('Ext.menu.Item',{
diff --git a/www/manager6/qemu/Options.js b/www/manager6/qemu/Options.js
index 1ec79a95..ef66fcfd 100644
--- a/www/manager6/qemu/Options.js
+++ b/www/manager6/qemu/Options.js
@@ -309,36 +309,9 @@ Ext.define('PVE.qemu.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 revert_btn = new PVE.button.PendingRevert({
+	    pendingGrid: me,
+	});
 
 	var set_button_status = function() {
 	    var sm = me.getSelectionModel();
-- 
2.20.1





More information about the pve-devel mailing list