fix #4001: FileBrowser: add menu to button and selected entry label

this commit adds a label showing the currently selected entry in the
file browser and merges the "Download .tar.zst" and "Download .zip"
button into one menu button.

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
This commit is contained in:
Stefan Sterz 2022-05-05 15:52:48 +02:00 committed by Thomas Lamprecht
parent 49275c6726
commit a3faf027a1

View File

@ -76,7 +76,9 @@ Ext.define("Proxmox.window.FileBrowser", {
'd': true, // directories 'd': true, // directories
}, },
// set to true to show the tar download button // enable tar download, this will add a menu to the
// "Download" button when the selection can be downloaded as
// .tar files
enableTar: false, enableTar: false,
}, },
@ -135,13 +137,19 @@ Ext.define("Proxmox.window.FileBrowser", {
if (!selection || selection.length < 1) return; if (!selection || selection.length < 1) return;
let data = selection[0].data; let data = selection[0].data;
let st = Ext.String.format(gettext('Selected "{0}"'), atob(data.filepath));
view.lookup('selectText').setText(st);
let canDownload = view.downloadURL && view.downloadableFileTypes[data.type]; let canDownload = view.downloadURL && view.downloadableFileTypes[data.type];
let zipBtn = me.lookup('downloadBtn'); let enableMenu = view.enableTar && data.type === 'd';
let tarBtn = me.lookup('downloadTar');
zipBtn.setDisabled(!canDownload); let downloadBtn = view.lookup('downloadBtn');
tarBtn.setDisabled(!canDownload); downloadBtn.setDisabled(!canDownload || enableMenu);
zipBtn.setText(data.type === 'd' ? gettext('Download .zip') : gettext('Download')); downloadBtn.setHidden(!canDownload || enableMenu);
tarBtn.setVisible(data.type === 'd' && view.enableTar);
let menuBtn = view.lookup('menuBtn');
menuBtn.setDisabled(!canDownload || !enableMenu);
menuBtn.setHidden(!canDownload || !enableMenu);
}, },
errorHandler: function(error, msg) { errorHandler: function(error, msg) {
@ -150,7 +158,7 @@ Ext.define("Proxmox.window.FileBrowser", {
return false; return false;
} }
me.lookup('downloadBtn').setDisabled(true); me.lookup('downloadBtn').setDisabled(true);
me.lookup('downloadTar').setDisabled(true); me.lookup('menuBtn').setDisabled(true);
if (me.initialLoadDone) { if (me.initialLoadDone) {
Ext.Msg.alert(gettext('Error'), msg); Ext.Msg.alert(gettext('Error'), msg);
return true; return true;
@ -300,19 +308,40 @@ Ext.define("Proxmox.window.FileBrowser", {
}, },
], ],
buttons: [ fbar: [
{ {
text: gettext('Download .tar.zst'), text: '',
handler: 'downloadTar', xtype: 'label',
reference: 'downloadTar', reference: 'selectText',
hidden: true,
disabled: true,
}, },
{ {
text: gettext('Download .zip'), text: gettext('Download'),
xtype: 'button',
handler: 'downloadZip', handler: 'downloadZip',
reference: 'downloadBtn', reference: 'downloadBtn',
disabled: true, disabled: true,
hidden: true,
},
{
text: gettext('Download as'),
xtype: 'button',
reference: 'menuBtn',
menu: {
items: [
{
iconCls: 'fa fa-fw fa-file-zip-o',
text: gettext('.zip'),
handler: 'downloadZip',
reference: 'downloadZip',
},
{
iconCls: 'fa fa-fw fa-archive',
text: gettext('.tar.zst'),
handler: 'downloadTar',
reference: 'downloadTar',
},
],
},
}, },
], ],
}); });