Buttons: add AltText

The same code is used once in widget toolkit and twice in PVE already,
so it makes sense to add it as a separate button.

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Matthias Heiserer 2022-03-28 15:07:34 +02:00 committed by Thomas Lamprecht
parent 8315a64201
commit 463177281c
2 changed files with 23 additions and 0 deletions

View File

@ -45,6 +45,7 @@ JSSRC= \
form/ACME.js \
form/UserSelector.js \
button/Button.js \
button/AltText.js \
button/HelpButton.js \
grid/ObjectGrid.js \
grid/PendingObjectGrid.js \

22
src/button/AltText.js Normal file
View File

@ -0,0 +1,22 @@
Ext.define('Proxmox.button.AltText', {
extend: 'Proxmox.button.Button',
xtype: 'proxmoxAltTextButton',
defaultText: "",
altText: "",
listeners: {
// HACK: calculate the max button width on first render to avoid toolbar glitches
render: function(button) {
let me = this;
button.setText(me.altText);
let altWidth = button.getSize().width;
button.setText(me.defaultText);
let defaultWidth = button.getSize().width;
button.setWidth(defaultWidth > altWidth ? defaultWidth : altWidth);
},
},
});