[pve-devel] [PATCH manager 2/2] ui: backup: protect button: use dynamic protect/unprotect text

Fabian Ebner f.ebner at proxmox.com
Fri Nov 12 12:28:34 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    | 22 +++++++++++++++++++++-
 www/manager6/storage/BackupView.js | 24 +++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/www/manager6/grid/BackupView.js b/www/manager6/grid/BackupView.js
index c08fb67d..cbdac02e 100644
--- a/www/manager6/grid/BackupView.js
+++ b/www/manager6/grid/BackupView.js
@@ -12,6 +12,7 @@ Ext.define('PVE.grid.BackupView', {
 	let me = this;
 
 	me.down('#removeButton').updateStatus(record);
+	me.down('#protectButton').updateStatus(record);
     },
 
     initComponent: function() {
@@ -314,8 +315,14 @@ Ext.define('PVE.grid.BackupView', {
 		    },
 		    {
 			xtype: 'proxmoxButton',
-			text: gettext('Change Protection'),
+			text: gettext('Protect'),
+			defaultText: gettext('Protect'),
+			altText: gettext('Unprotect'),
 			disabled: true,
+			itemId: 'protectButton',
+			updateStatus: function(record) {
+			    this.setText(record?.data.protected ? this.altText : this.defaultText);
+			},
 			handler: function(button, event, record) {
 			    const volid = record.data.volid;
 			    const storage = storagesel.getValue();
@@ -330,6 +337,19 @@ Ext.define('PVE.grid.BackupView', {
 				success: (response) => reload(),
 			    });
 			},
+			listeners: {
+			    render: function(btn) {
+				// HACK: calculate the max button width on first render to avoid
+				// toolbar glitches
+				let defSize = btn.getSize().width;
+
+				btn.setText(btn.altText);
+				let altSize = btn.getSize().width;
+
+				btn.setText(btn.defaultText);
+				btn.setSize({ width: altSize > defSize ? altSize : defSize });
+			    },
+			},
 		    },
 		    '-',
 		    delete_btn,
diff --git a/www/manager6/storage/BackupView.js b/www/manager6/storage/BackupView.js
index 42fd6623..606581cc 100644
--- a/www/manager6/storage/BackupView.js
+++ b/www/manager6/storage/BackupView.js
@@ -11,6 +11,7 @@ Ext.define('PVE.storage.BackupView', {
 	let me = this;
 
 	me.down('#removeButton').updateStatus(record);
+	me.down('#protectButton').updateStatus(record);
     },
 
     initComponent: function() {
@@ -181,8 +182,14 @@ Ext.define('PVE.storage.BackupView', {
 	    },
 	    {
 		xtype: 'proxmoxButton',
-		text: gettext('Change Protection'),
+		text: gettext('Protect'),
+		defaultText: gettext('Protect'),
+		altText: gettext('Unprotect'),
 		disabled: true,
+		itemId: 'protectButton',
+		updateStatus: function(record) {
+		    this.setText(record?.data.protected ? this.altText : this.defaultText);
+		},
 		handler: function(button, event, record) {
 		    const volid = record.data.volid;
 		    Proxmox.Utils.API2Request({
@@ -194,6 +201,19 @@ Ext.define('PVE.storage.BackupView', {
 			success: (response) => reload(),
 		    });
 		},
+		listeners: {
+		    render: function(btn) {
+			// HACK: calculate the max button width on first render to avoid
+			// toolbar glitches
+			let defSize = btn.getSize().width;
+
+			btn.setText(btn.altText);
+			let altSize = btn.getSize().width;
+
+			btn.setText(btn.defaultText);
+			btn.setSize({ width: altSize > defSize ? altSize : defSize });
+		    },
+		},
 	    },
 	    '-',
 	    pruneButton,
@@ -228,6 +248,8 @@ Ext.define('PVE.storage.BackupView', {
 
 	me.callParent();
 
+	me.on('selectionchange', (model, records) => me.updateButtonStatus(records[0]));
+
 	me.store.on('load', () => me.updateButtonStatus(me.selModel.getSelection()[0]));
     },
 });
-- 
2.30.2






More information about the pve-devel mailing list