[pve-devel] [PATCH manager 19/19] use Proxmox.button.StdRemoveButton where possible

Dominik Csapak d.csapak at proxmox.com
Thu Dec 21 13:36:22 CET 2017


most 'Remove' buttons we have used the same code pattern over and over,
with the StdRemoveButton we have a component which does all of this for
us

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/dc/AuthView.js          | 25 ++++----------------
 www/manager6/dc/Backup.js            | 20 ++++------------
 www/manager6/dc/GroupView.js         | 23 ++++---------------
 www/manager6/dc/PoolView.js          | 23 ++++---------------
 www/manager6/dc/SecurityGroups.js    | 24 ++++++--------------
 www/manager6/dc/StorageView.js       | 23 ++++---------------
 www/manager6/dc/UserView.js          | 25 ++++----------------
 www/manager6/grid/BackupView.js      | 31 ++++++-------------------
 www/manager6/grid/FirewallAliases.js | 21 +++--------------
 www/manager6/grid/FirewallRules.js   | 40 +++++++++-----------------------
 www/manager6/grid/Replication.js     | 27 ++++------------------
 www/manager6/ha/Groups.js            | 21 ++++-------------
 www/manager6/ha/Resources.js         | 25 +++++++-------------
 www/manager6/panel/IPSet.js          | 44 ++++++------------------------------
 www/manager6/storage/ContentView.js  | 25 ++++----------------
 15 files changed, 81 insertions(+), 316 deletions(-)

diff --git a/www/manager6/dc/AuthView.js b/www/manager6/dc/AuthView.js
index 5c47f442..d2d152a8 100644
--- a/www/manager6/dc/AuthView.js
+++ b/www/manager6/dc/AuthView.js
@@ -46,31 +46,14 @@ Ext.define('PVE.dc.AuthView', {
 	    handler: run_editor
 	});
 
-	var remove_btn = new PVE.button.Button({
-	    text: gettext('Remove'),
-	    disabled: true,
+	var remove_btn = Ext.create('Proxmox.button.StdRemoveButton', {
+	    baseurl: '/access/domains/',
 	    selModel: sm,
-	    confirmMsg: function (rec) {
-		return Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
-					 "'" + rec.data.realm + "'");
-	    },
 	    enableFn: function(rec) {
 		return !(rec.data.type === 'pve' || rec.data.type === 'pam');
 	    },
-	    handler: function(btn, event, rec) {
-		var realm = rec.data.realm;
-
-		PVE.Utils.API2Request({
-		    url: '/access/domains/' + realm,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    callback: function() {
-			reload();
-		    },
-		    failure: function (response, opts) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    }
-		});
+	    callback: function() {
+		reload();
 	    }
         });
 
diff --git a/www/manager6/dc/Backup.js b/www/manager6/dc/Backup.js
index 235bea6f..64f99e32 100644
--- a/www/manager6/dc/Backup.js
+++ b/www/manager6/dc/Backup.js
@@ -362,23 +362,11 @@ Ext.define('PVE.dc.BackupView', {
 	    handler: run_editor
 	});
 
-	var remove_btn = new PVE.button.Button({
-	    text: gettext('Remove'),
-	    disabled: true,
+	var remove_btn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
-	    confirmMsg: gettext('Are you sure you want to remove this entry'),
-	    handler: function(btn, event, rec) {
-		PVE.Utils.API2Request({
-		    url: '/cluster/backup/' + rec.data.id,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    callback: function() {
-			reload();
-		    },
-		    failure: function (response, opts) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    }
-		});
+	    baseurl: '/cluster/backup',
+	    callback: function() {
+		reload();
 	    }
 	});
 
diff --git a/www/manager6/dc/GroupView.js b/www/manager6/dc/GroupView.js
index 31fc286b..ce679732 100644
--- a/www/manager6/dc/GroupView.js
+++ b/www/manager6/dc/GroupView.js
@@ -25,27 +25,12 @@ Ext.define('PVE.dc.GroupView', {
 
 	var sm = Ext.create('Ext.selection.RowModel', {});
 
-	var remove_btn = new PVE.button.Button({
-	    text: gettext('Remove'),
-	    disabled: true,
+	var remove_btn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
-	    confirmMsg: function (rec) {
-		return Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
-					 "'" + rec.data.groupid + "'");
+	    callback: function() {
+		reload();
 	    },
-	    handler: function(btn, event, rec) {
-		PVE.Utils.API2Request({
-		    url: '/access/groups/' + rec.data.groupid,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    callback: function() {
-			reload();
-		    },
-		    failure: function (response, opts) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    }
-		});
-	    }
+	    baseurl: '/access/groups/'
 	});
 
 	var run_editor = function() {
diff --git a/www/manager6/dc/PoolView.js b/www/manager6/dc/PoolView.js
index 8b44d28f..b844f724 100644
--- a/www/manager6/dc/PoolView.js
+++ b/www/manager6/dc/PoolView.js
@@ -25,26 +25,11 @@ Ext.define('PVE.dc.PoolView', {
 
 	var sm = Ext.create('Ext.selection.RowModel', {});
 
-	var remove_btn = new PVE.button.Button({
-	    text: gettext('Remove'),
-	    disabled: true,
+	var remove_btn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
-	    confirmMsg: function (rec) {
-		return Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
-					 "'" + rec.data.poolid + "'");
-	    },
-	    handler: function(btn, event, rec) {
-		PVE.Utils.API2Request({
-		    url: '/pools/' + rec.data.poolid,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    callback: function() {
-			reload();
-		    },
-		    failure: function (response, opts) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    }
-		});
+	    baseurl: '/pools/',
+	    callback: function () {
+		reload();
 	    }
 	});
 
diff --git a/www/manager6/dc/SecurityGroups.js b/www/manager6/dc/SecurityGroups.js
index 0872eb0a..906f2171 100644
--- a/www/manager6/dc/SecurityGroups.js
+++ b/www/manager6/dc/SecurityGroups.js
@@ -149,24 +149,14 @@ Ext.define('PVE.SecurityGroupList', {
 	    }
 	});
 
-	me.removeBtn = new PVE.button.Button({
-	    text: gettext('Remove'),
+	me.removeBtn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
-	    disabled: true,
-	    handler: function() {
-		var rec = sm.getSelection()[0];
-		if (!rec || !me.base_url) {
-		    return;
-		}
-		PVE.Utils.API2Request({
-		    url: me.base_url + '/' + rec.data.group,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    failure: function(response, options) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    },
-		    callback: reload
-		});
+	    baseurl: me.base_url + '/',
+	    enableFn: function(rec) {
+		return (rec && me.base_url);
+	    },
+	    callback: function() {
+		reload();
 	    }
 	});
 
diff --git a/www/manager6/dc/StorageView.js b/www/manager6/dc/StorageView.js
index 8f5a055c..9255c6e6 100644
--- a/www/manager6/dc/StorageView.js
+++ b/www/manager6/dc/StorageView.js
@@ -77,26 +77,11 @@ Ext.define('PVE.dc.StorageView', {
 	    handler: run_editor
 	});
 
-	var remove_btn = new PVE.button.Button({
-	    text: gettext('Remove'),
-	    disabled: true,
+	var remove_btn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
-	    confirmMsg: function (rec) {
-		return Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
-					 "'" + rec.data.storage + "'");
-	    },
-	    handler: function(btn, event, rec) {
-		PVE.Utils.API2Request({
-		    url: '/storage/' + rec.data.storage,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    callback: function() {
-			reload();
-		    },
-		    failure: function (response, opts) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    }
-		});
+	    baseurl: '/storage/',
+	    callback: function() {
+		reload();
 	    }
 	});
 
diff --git a/www/manager6/dc/UserView.js b/www/manager6/dc/UserView.js
index 4d2238e3..b14d8d9e 100644
--- a/www/manager6/dc/UserView.js
+++ b/www/manager6/dc/UserView.js
@@ -81,34 +81,17 @@ Ext.define('PVE.dc.UserView', {
 
 	var sm = Ext.create('Ext.selection.RowModel', {});
 
-	var remove_btn = new PVE.button.Button({
-	    text: gettext('Remove'),
-	    disabled: true,
+	var remove_btn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
+	    baseurl: '/access/users/',
 	    enableFn: function(rec) {
 		if (!caps.access['User.Modify']) {
 		    return false;
 		}
 		return rec.data.userid !== 'root at pam';
 	    },
-	    confirmMsg: function (rec) {
-		return Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
-					 "'" + rec.data.userid + "'");
-	    },
-	    handler: function(btn, event, rec) {
-		var userid = rec.data.userid;
-
-		PVE.Utils.API2Request({
-		    url: '/access/users/' + userid,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    callback: function() {
-			reload();
-		    },
-		    failure: function (response, opts) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    }
-		});
+	    callback: function() {
+		reload();
 	    }
         });
  
diff --git a/www/manager6/grid/BackupView.js b/www/manager6/grid/BackupView.js
index 15ae85db..a15b77b1 100644
--- a/www/manager6/grid/BackupView.js
+++ b/www/manager6/grid/BackupView.js
@@ -156,11 +156,9 @@ Ext.define('PVE.grid.BackupView', {
 	    }
 	});
 
-	var delete_btn = Ext.create('PVE.button.Button', {
-	    text: gettext('Remove'),
-	    disabled: true,
+	var delete_btn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
-	    dangerous: true,	    
+	    dangerous: true,
 	    confirmMsg: function(rec) {
 		var msg = Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
 					    "'" + rec.data.volid + "'");
@@ -168,27 +166,12 @@ Ext.define('PVE.grid.BackupView', {
 
 		return msg;
 	    },
-	    enableFn: function(rec) {
-		return !!rec;
-	    },
-	    handler: function(b, e, rec){
+	    getUrl: function(rec) {
 		var storage = storagesel.getValue();
-		if (!storage) {
-		    return;
-		}
-
-		var volid = rec.data.volid;
-		PVE.Utils.API2Request({
-		    url: "/nodes/" + nodename + "/storage/" + storage + "/content/" + volid,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    failure: function(response, opts) {
-			Ext.Msg.alert('Error', response.htmlStatus);
-		    },
-		    success: function(response, options) {
-			reload();
-		    }
-		});
+		return '/nodes/' + nodename + '/storage/' + storage + '/content/' + rec.data.volid;
+	    },
+	    callback: function() {
+		reload();
 	    }
 	});
 
diff --git a/www/manager6/grid/FirewallAliases.js b/www/manager6/grid/FirewallAliases.js
index af20a665..f3ec3d5b 100644
--- a/www/manager6/grid/FirewallAliases.js
+++ b/www/manager6/grid/FirewallAliases.js
@@ -152,25 +152,10 @@ Ext.define('PVE.FirewallAliases', {
 	    }
 	});
 
-	me.removeBtn = new PVE.button.Button({
-	    text: gettext('Remove'),
+	me.removeBtn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
-	    disabled: true,
-	    handler: function() {
-		var rec = sm.getSelection()[0];
-		if (!rec) {
-		    return;
-		}
-		PVE.Utils.API2Request({
-		    url: me.base_url + '/' + rec.data.name,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    failure: function(response, options) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    },
-		    callback: reload
-		});
-	    }
+	    baseurl: me.base_url + '/',
+	    callback: reload
 	});
 
 
diff --git a/www/manager6/grid/FirewallRules.js b/www/manager6/grid/FirewallRules.js
index f0163629..64834c40 100644
--- a/www/manager6/grid/FirewallRules.js
+++ b/www/manager6/grid/FirewallRules.js
@@ -408,6 +408,7 @@ Ext.define('PVE.FirewallRules', {
 	    me.store.removeAll();
 	} else {
 	    me.addBtn.setDisabled(false);
+	    me.removeBtn.baseurl = url + '/';
 	    if (me.groupBtn) {
 		me.groupBtn.setDisabled(false);
 	    }
@@ -468,26 +469,6 @@ Ext.define('PVE.FirewallRules', {
 	});
     },
 
-    deleteRule: function(rule) {
-        var me = this;
-
-	if (!me.base_url) {
-	    return;
-	}
-
-	PVE.Utils.API2Request({
-	    url: me.base_url + '/' + rule.pos.toString() +
-		'?digest=' + encodeURIComponent(rule.digest),
-	    method: 'DELETE',
-	    waitMsgTarget: me,
-	    failure: function(response, options) {
-		Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-	    },
-	    callback: function() {
-		me.store.load();
-	    }
-	});
-    },
 
     initComponent: function() {
 	/*jslint confusion: true */
@@ -606,16 +587,17 @@ Ext.define('PVE.FirewallRules', {
 	    });
 	}
 
-	me.removeBtn = Ext.create('PVE.button.Button',{
-	    text: gettext('Remove'),
+	me.removeBtn = Ext.create('Proxmox.button.StdRemoveButton',{
 	    selModel: sm,
-	    disabled: true,
-	    handler: function() {
-		var rec = sm.getSelection()[0];
-		if (!rec) {
-		    return;
-		}
-		me.deleteRule(rec.data);
+	    baseurl: me.base_url + '/',
+	    confirmMsg: false,
+	    getRecordName: function(rec) {
+		var rule = rec.data;
+		return rule.pos.toString() +
+		    '?digest=' + encodeURIComponent(rule.digest);
+	    },
+	    callback: function() {
+		me.store.load();
 	    }
 	});
 
diff --git a/www/manager6/grid/Replication.js b/www/manager6/grid/Replication.js
index 035cba2d..6c2fc529 100644
--- a/www/manager6/grid/Replication.js
+++ b/www/manager6/grid/Replication.js
@@ -129,6 +129,8 @@ Ext.define('PVE.window.ReplicaEdit', {
     }
 });
 
+/*jslint confusion: true */
+/* callback is a function and string */
 Ext.define('PVE.grid.ReplicaView', {
     extend: 'Ext.grid.Panel',
     xtype: 'pveReplicaView',
@@ -166,20 +168,6 @@ Ext.define('PVE.grid.ReplicaView', {
 	    win.show();
 	},
 
-	removeJob: function(button,event,rec) {
-	    var me = this.getView();
-	    var controller = this;
-	    PVE.Utils.API2Request({
-		url: '/api2/extjs/cluster/replication/' + rec.data.id,
-		waitMsgTarget: me,
-		method: 'DELETE',
-		callback: function() { controller.reload(); },
-		failure: function (response, opts) {
-		    Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		}
-	    });
-	},
-
 	scheduleJobNow: function(button,event,rec) {
 	    var me = this.getView();
 	    var controller = this;
@@ -266,16 +254,11 @@ Ext.define('PVE.grid.ReplicaView', {
 	    disabled: true
 	},
 	{
-	    xtype: 'pveButton',
-	    text: gettext('Remove'),
+	    xtype: 'proxmoxStdRemoveButton',
 	    itemId: 'removeButton',
-	    handler: 'removeJob',
+	    baseurl: '/api2/extjs/cluster/replication/',
 	    dangerous: true,
-	    confirmMsg: function(rec) {
-		var msg = Ext.String.format(gettext("Are you sure you want to remove entry {0}"), rec.id);
-		return msg;
-	    },
-	    disabled: true
+	    callback: 'reload'
 	},
 	{
 	    xtype: 'pveButton',
diff --git a/www/manager6/ha/Groups.js b/www/manager6/ha/Groups.js
index c8c5a427..466a5232 100644
--- a/www/manager6/ha/Groups.js
+++ b/www/manager6/ha/Groups.js
@@ -36,24 +36,11 @@ Ext.define('PVE.ha.GroupsView', {
             win.show();
 	};
 
-	var remove_btn = new PVE.button.Button({
-	    text: gettext('Remove'),
-	    disabled: true,
+	var remove_btn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
-	    handler: function(btn, event, rec) {
-		var group = rec.data.group;
-
-		PVE.Utils.API2Request({
-		    url: '/cluster/ha/groups/' + group,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    callback: function() {
-			reload();
-		    },
-		    failure: function (response, opts) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    }
-		});
+	    baseurl: '/cluster/ha/groups/',
+	    callback: function() {
+		reload();
 	    }
 	});
 	
diff --git a/www/manager6/ha/Resources.js b/www/manager6/ha/Resources.js
index 314d56e4..189f90e1 100644
--- a/www/manager6/ha/Resources.js
+++ b/www/manager6/ha/Resources.js
@@ -67,24 +67,15 @@ Ext.define('PVE.ha.ResourcesView', {
             win.show();
 	};
 
-	var remove_btn = new PVE.button.Button({
-	    text: gettext('Remove'),
-	    disabled: true,
+	var remove_btn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
-	    handler: function(btn, event, rec) {
-		var sid = rec.data.sid;
-
-		PVE.Utils.API2Request({
-		    url: '/cluster/ha/resources/' + sid,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    callback: function() {
-			reload();
-		    },
-		    failure: function (response, opts) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    }
-		});
+	    baseurl: '/cluster/ha/resources/',
+	    getUrl: function(rec) {
+		var me = this;
+		return me.baseurl + '/' + rec.get('sid');
+	    },
+	    callback: function() {
+		reload();
 	    }
 	});
 	
diff --git a/www/manager6/panel/IPSet.js b/www/manager6/panel/IPSet.js
index 4ae23a57..d4b36928 100644
--- a/www/manager6/panel/IPSet.js
+++ b/www/manager6/panel/IPSet.js
@@ -129,25 +129,10 @@ Ext.define('PVE.IPSetList', {
 	    }
 	});
 
-	me.removeBtn = new PVE.button.Button({
-	    text: gettext('Remove'),
+	me.removeBtn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
-	    disabled: true,
-	    handler: function() {
-		var rec = sm.getSelection()[0];
-		if (!rec || !me.base_url) {
-		    return;
-		}
-		PVE.Utils.API2Request({
-		    url: me.base_url + '/' + rec.data.name,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    failure: function(response, options) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    },
-		    callback: reload
-		});
-	    }
+	    baseurl: me.base_url + '/',
+	    callback: reload
 	});
 
 	Ext.apply(me, {
@@ -287,6 +272,7 @@ Ext.define('PVE.IPSetGrid', {
 	    me.store.removeAll();
 	} else {
 	    me.addBtn.setDisabled(false);
+	    me.removeBtn.baseurl = url + '/';
 	    me.store.setProxy({
 		type: 'pve',
 		url: '/api2/json' + url
@@ -350,26 +336,10 @@ Ext.define('PVE.IPSetGrid', {
 	    }
 	});
 
-	me.removeBtn = new PVE.button.Button({
-	    text: gettext('Remove'),
+	me.removeBtn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
-	    disabled: true,
-	    handler: function() {
-		var rec = sm.getSelection()[0];
-		if (!rec || !me.base_url) {
-		    return;
-		}
-
-		PVE.Utils.API2Request({
-		    url: me.base_url + '/' + rec.data.cidr,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    failure: function(response, options) {
-			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-		    },
-		    callback: reload
-		});
-	    }
+	    baseurl: me.base_url + '/',
+	    callback: reload
 	});
 
 	var render_errors = function(value, metaData, record) {
diff --git a/www/manager6/storage/ContentView.js b/www/manager6/storage/ContentView.js
index 47bd199a..c5d856cb 100644
--- a/www/manager6/storage/ContentView.js
+++ b/www/manager6/storage/ContentView.js
@@ -438,30 +438,15 @@ Ext.define('PVE.storage.ContentView', {
 		    }
 		},
 		{
-		    xtype: 'pveButton',
-		    text: gettext('Remove'),
+		    xtype: 'proxmoxStdRemoveButton',
 		    selModel: sm,
-		    disabled: true,
-		    confirmMsg: function(rec) {
-			return Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
-						 "'" + rec.data.volid + "'");
-		    },
 		    enableFn: function(rec) {
 			return rec && rec.data.content !== 'images';
 		    },
-		    handler: function(b, e, rec) {
-			PVE.Utils.API2Request({
-			    url: baseurl + '/' + rec.data.volid,
-			    method: 'DELETE',
-			    waitMsgTarget: me,
-			    callback: function() {
-				reload();
-			    },
-			    failure: function (response, opts) {
-				Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-			    }
-			});
-		    }
+		    callback: function() {
+			reload();
+		    },
+		    baseurl: baseurl + '/'
 		},
 		templateButton,
 		uploadButton,
-- 
2.11.0





More information about the pve-devel mailing list