]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
apt repos: make enable/disable text selection dependent
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 23 Jun 2021 17:38:29 +0000 (19:38 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 23 Jun 2021 17:38:34 +0000 (19:38 +0200)
the size hack is copied over from pve-manager's qemu/HardwareView

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/node/APTRepositories.js

index 5a9e08af6558c4a11b5993072aa24430929fae1f..49e46b304f4fa47e329d1edad6376e9585e189de 100644 (file)
@@ -70,7 +70,10 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
        '-',
        {
            xtype: 'proxmoxButton',
-           text: gettext('Enable') + '/' + gettext('Disable'),
+           text: gettext('Enable'),
+           defaultText: gettext('Enable'),
+           altText: gettext('Disable'),
+           id: 'repoEnableButton',
            disabled: true,
            handler: function(button, event, record) {
                let me = this;
@@ -99,6 +102,18 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
                    },
                });
            },
+           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 });
+               },
+           },
        },
     ],
 
@@ -279,6 +294,19 @@ 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', {
@@ -351,6 +379,13 @@ 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'));
+               }
+           },
        },
     ],