apt repos: make enable/disable text selection dependent

the size hack is copied over from pve-manager's qemu/HardwareView

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-06-23 19:38:29 +02:00
parent af48de6bf8
commit bb64cd0341

View 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'));
}
},
},
],