]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
Buttons: add AltText
authorMatthias Heiserer <m.heiserer@proxmox.com>
Mon, 28 Mar 2022 13:07:34 +0000 (15:07 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 27 Apr 2022 12:29:54 +0000 (14:29 +0200)
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>
src/Makefile
src/button/AltText.js [new file with mode: 0644]

index dd7729e60424aa711fc204b8c08ce4b7902e6607..95da5aab3e47aea100102fd7a7916a968aa04ac5 100644 (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       \
diff --git a/src/button/AltText.js b/src/button/AltText.js
new file mode 100644 (file)
index 0000000..e74d042
--- /dev/null
@@ -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);
+       },
+    },
+});