From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 0282471EE4
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:15:03 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 000FE1B6D5
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:15:03 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id EAF0C1B6A7
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:15:00 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C38B946767
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:15:00 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed, 30 Jun 2021 17:14:57 +0200
Message-Id: <20210630151459.231895-4-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20210630151459.231895-1-d.csapak@proxmox.com>
References: <20210630151459.231895-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.711 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH widget-toolkit 3/5] APTRepositories: change
 updating button text/state to viewcontroller
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 30 Jun 2021 15:15:03 -0000

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@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