[pve-devel] [PATCH manager 1/2] ui: backup: disable remove button when backup is protected

Fabian Ebner f.ebner at proxmox.com
Fri Nov 12 12:28:33 CET 2021


Suggested-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 www/manager6/grid/BackupView.js    | 18 +++++++++++++++++-
 www/manager6/storage/BackupView.js | 22 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/www/manager6/grid/BackupView.js b/www/manager6/grid/BackupView.js
index fdc385a8..c08fb67d 100644
--- a/www/manager6/grid/BackupView.js
+++ b/www/manager6/grid/BackupView.js
@@ -8,6 +8,12 @@ Ext.define('PVE.grid.BackupView', {
     stateful: true,
     stateId: 'grid-guest-backup',
 
+    updateButtonStatus: function(record) {
+	let me = this;
+
+	me.down('#removeButton').updateStatus(record);
+    },
+
     initComponent: function() {
 	var me = this;
 
@@ -62,7 +68,10 @@ Ext.define('PVE.grid.BackupView', {
 	        vmtypeFilter,
 		searchFilter,
 		vmidFilter,
-		],
+	    ],
+	    listeners: {
+		load: () => me.updateButtonStatus(me.selModel.getSelection()[0]),
+	    },
 	});
 
 	let updateFilter = function() {
@@ -197,6 +206,10 @@ Ext.define('PVE.grid.BackupView', {
 	    selModel: sm,
 	    dangerous: true,
 	    delay: 5,
+	    itemId: 'removeButton',
+	    updateStatus: function(record) {
+		this.setDisabled(!record || record.data.protected);
+	    },
 	    confirmMsg: function(rec) {
 		var msg = Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
 					    "'" + rec.data.volid + "'");
@@ -379,6 +392,9 @@ Ext.define('PVE.grid.BackupView', {
 		    renderer: PVE.Utils.render_backup_verification,
 		},
 	    ],
+	    listeners: {
+		selectionchange: (model, records) => me.updateButtonStatus(records[0]),
+	    },
 	});
 
 	me.callParent();
diff --git a/www/manager6/storage/BackupView.js b/www/manager6/storage/BackupView.js
index dca140fe..42fd6623 100644
--- a/www/manager6/storage/BackupView.js
+++ b/www/manager6/storage/BackupView.js
@@ -5,6 +5,14 @@ Ext.define('PVE.storage.BackupView', {
 
     showColumns: ['name', 'notes', 'protected', 'date', 'format', 'size'],
 
+    useCustomRemoveButton: true,
+
+    updateButtonStatus: function(record) {
+	let me = this;
+
+	me.down('#removeButton').updateStatus(record);
+    },
+
     initComponent: function() {
 	var me = this;
 
@@ -189,6 +197,18 @@ Ext.define('PVE.storage.BackupView', {
 	    },
 	    '-',
 	    pruneButton,
+	    {
+		xtype: 'proxmoxStdRemoveButton',
+		itemId: 'removeButton',
+		selModel: sm,
+		delay: 5,
+		callback: () => reload(),
+		baseurl: `/api2/extjs/nodes/${nodename}/storage/${me.storage}/content`,
+		enableFn: (record) => !record.data.protected,
+		updateStatus: function(record) { // enableFn is not called after store load
+		    this.setDisabled(!record || record.data.protected);
+		},
+	    },
 	);
 
 	if (isPBS) {
@@ -207,5 +227,7 @@ Ext.define('PVE.storage.BackupView', {
 	}
 
 	me.callParent();
+
+	me.store.on('load', () => me.updateButtonStatus(me.selModel.getSelection()[0]));
     },
 });
-- 
2.30.2






More information about the pve-devel mailing list