[pve-devel] [PATCH widget-toolkit 3/5] APTRepositories: change updating button text/state to viewcontroller

Dominik Csapak d.csapak at proxmox.com
Wed Jun 30 17:14:57 CEST 2021


we already have a viewmodel we can use, and so the handler does
not have to navigate the component tree up/down

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/node/APTRepositories.js | 41 ++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/src/node/APTRepositories.js b/src/node/APTRepositories.js
index 1985e50..23cd984 100644
--- a/src/node/APTRepositories.js
+++ b/src/node/APTRepositories.js
@@ -81,6 +81,9 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
 	    altText: gettext('Disable'),
 	    id: 'repoEnableButton',
 	    disabled: true,
+	    bind: {
+		text: '{enableButtonText}',
+	    },
 	    handler: function(button, event, record) {
 		let me = this;
 		let panel = me.up('proxmoxNodeAPTRepositories');
@@ -290,19 +293,6 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
 
 	me.callParent();
     },
-
-    listeners: {
-	selectionchange: function() {
-	    let me = this;
-
-	    if (me.onSelectionChange) {
-		let sm = me.getSelectionModel();
-		let rec = sm.getSelection()[0];
-
-		me.onSelectionChange(rec, sm);
-	    }
-	},
-    },
 });
 
 Ext.define('Proxmox.node.APTRepositories', {
@@ -314,6 +304,20 @@ Ext.define('Proxmox.node.APTRepositories', {
 
     product: 'Proxmox VE', // default
 
+    controller: {
+	xclass: 'Ext.app.ViewController',
+
+	selectionChange: function(grid, selection) {
+	    let me = this;
+	    if (!selection || selection.length < 1) {
+		return;
+	    }
+	    let rec = selection[0];
+	    let vm = me.getViewModel();
+	    vm.set('selectionenabled', rec.get('Enabled'));
+	},
+    },
+
     viewModel: {
 	data: {
 	    product: 'Proxmox VE', // default
@@ -321,9 +325,12 @@ Ext.define('Proxmox.node.APTRepositories', {
 	    subscriptionActive: '',
 	    noSubscriptionRepo: '',
 	    enterpriseRepo: '',
+	    selectionenabled: false,
 	},
 	formulas: {
 	    noErrors: (get) => get('errorCount') === 0,
+	    enableButtonText: (get) => get('selectionenabled')
+		? gettext('Disable') : gettext('Enable'),
 	    mainWarning: function(get) {
 		// Not yet initialized
 		if (get('subscriptionActive') === '' ||
@@ -390,12 +397,8 @@ Ext.define('Proxmox.node.APTRepositories', {
 		nodename: '{nodename}',
 	    },
 	    majorUpgradeAllowed: false, // TODO get release information from an API call?
-	    onSelectionChange: function(rec, sm) {
-		let me = this;
-		if (rec) {
-		    let btn = me.up('proxmoxNodeAPTRepositories').down('#repoEnableButton');
-		    btn.setText(rec.get('Enabled') ? gettext('Disable') : gettext('Enable'));
-		}
+	    listeners: {
+		selectionchange: 'selectionChange',
 	    },
 	},
     ],
-- 
2.30.2






More information about the pve-devel mailing list