[pve-devel] [PATCH pve-manager] requires manual entering VM id before enabling the delete Button for VMs

Emmanuel Kasper e.kasper at proxmox.com
Mon Mar 21 10:35:04 CET 2016


suggested by a user in https://bugzilla.proxmox.com/show_bug.cgi?id=360#c7
similar to the way github handles the deleting of a repository

fixes: #360
---
 PVE/ExtJSIndex6.pm                 |  1 +
 www/manager6/lxc/Config.js         | 14 ++-----
 www/manager6/qemu/Config.js        | 14 ++-----
 www/manager6/window/SafeDestroy.js | 86 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 20 deletions(-)
 create mode 100644 www/manager6/window/SafeDestroy.js

diff --git a/PVE/ExtJSIndex6.pm b/PVE/ExtJSIndex6.pm
index 0cd5efe..59648e6 100644
--- a/PVE/ExtJSIndex6.pm
+++ b/PVE/ExtJSIndex6.pm
@@ -112,6 +112,7 @@ window/Wizard.js
 window/NotesEdit.js
 window/Backup.js
 window/Restore.js
+window/SafeDestroy.js
 panel/NotesView.js
 grid/CheckColumn.js
 grid/SelectFeature.js
diff --git a/www/manager6/lxc/Config.js b/www/manager6/lxc/Config.js
index ea0ca13..1eafdb5 100644
--- a/www/manager6/lxc/Config.js
+++ b/www/manager6/lxc/Config.js
@@ -87,17 +87,11 @@ Ext.define('PVE.lxc.Config', {
 	var removeBtn = Ext.create('PVE.button.Button', {
 	    text: gettext('Remove'),
 	    disabled: !caps.vms['VM.Allocate'],
-	    dangerous: true,
-	    confirmMsg: Ext.String.format(gettext('Are you sure you want to remove VM {0}? This will permanently erase all VM data.'), vmid),
 	    handler: function() {
-		PVE.Utils.API2Request({
-		    url: base_url,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    failure: function(response, opts) {
-			Ext.Msg.alert('Error', response.htmlStatus);
-		    }
-		});
+		Ext.create('PVE.window.SafeDestroy', {
+		    vmid: vmid,
+		    base_url: base_url
+		}).show();
 	    }
 	});
 
diff --git a/www/manager6/qemu/Config.js b/www/manager6/qemu/Config.js
index ee01f38..dce4792 100644
--- a/www/manager6/qemu/Config.js
+++ b/www/manager6/qemu/Config.js
@@ -98,17 +98,11 @@ Ext.define('PVE.qemu.Config', {
 	var removeBtn = Ext.create('PVE.button.Button', {
 	    text: gettext('Remove'),
 	    disabled: !caps.vms['VM.Allocate'],
-	    dangerous: true,
-	    confirmMsg: Ext.String.format(gettext('Are you sure you want to remove VM {0}? This will permanently erase all VM data.'), vmid),
 	    handler: function() {
-		PVE.Utils.API2Request({
-		    url: base_url,
-		    method: 'DELETE',
-		    waitMsgTarget: me,
-		    failure: function(response, opts) {
-			Ext.Msg.alert('Error', response.htmlStatus);
-		    }
-		});
+		Ext.create('PVE.window.SafeDestroy', {
+		    vmid: vmid,
+		    base_url: base_url
+		}).show();
 	    }
 	});
 
diff --git a/www/manager6/window/SafeDestroy.js b/www/manager6/window/SafeDestroy.js
new file mode 100644
index 0000000..aa0e478
--- /dev/null
+++ b/www/manager6/window/SafeDestroy.js
@@ -0,0 +1,86 @@
+/* Popup a message window
+ * where the user has to manually enter the ressource ID
+ * to enable the destroy button
+ */
+Ext.define('PVE.window.SafeDestroy', {
+    extend: 'Ext.window.Window',
+    alias: 'widget.pveSafeDestroy',
+    title: gettext('Are you sure ?'),
+    modal: true,
+    buttonAlign: 'center',
+
+    items: [
+		{
+		    itemId: 'safepanel',
+		    xtype: 'container',
+		    padding: 10,
+		    width: 450,
+		    layout: {
+			type: 'vbox',
+			align: 'stretch'
+		    },
+		    items: [
+			{
+			    itemId: 'message',
+			    xtype: 'textarea',
+			    editable: false,
+			},
+			{
+			    itemId: 'input',
+			    xtype: 'numberfield',
+			    name: 'VM id',
+			    fieldLabel: gettext('Please enter the VM ID to confirm'),
+			    hideTrigger:true,
+			    allowBlank: false,
+			    listeners: {
+				change: function(f, value) {
+				    if (value === this.vmid) {
+					this.submitBtn.enable();
+				    } else {
+					this.submitBtn.disable();
+				    }
+				}
+			    }
+			}
+		    ]
+		}
+     ],
+    buttons: [
+	{
+	    id: 'removeButton',
+	    text: gettext('Remove'),
+	    disabled: true,
+	    handler: function () {
+		var me = this;
+		PVE.Utils.API2Request({
+		    url: me.base_url,
+		    method: 'DELETE',
+		    waitMsgTarget: me,
+		    failure: function(response, opts) {
+			Ext.Msg.alert('Error', response.htmlStatus);
+		    }
+		});
+		me.up('window').close();
+	    }
+	}, {
+	    text: gettext('Cancel'),
+	    handler: function() {
+		this.up('window').close();
+	    }
+	}
+    ],
+
+    initComponent: function() {
+	var me = this;
+	me.callParent();
+
+	var msg = Ext.String.format(gettext('Are you sure you want to remove VM {0}? This will permanently erase all VM data.'), me.vmid);
+	me.getComponent('safepanel').getComponent('message').setValue(msg);
+
+	var submitBtn = me.down('toolbar').getComponent('removeButton');
+	submitBtn.base_url= me.base_url;
+
+	me.getComponent('safepanel').getComponent('input').vmid = me.vmid;
+	me.getComponent('safepanel').getComponent('input').submitBtn = submitBtn;
+    }
+});
\ No newline at end of file
-- 
2.1.4





More information about the pve-devel mailing list