]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
window/FileBrowser: add optional 'tar.zst' button
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 12 Apr 2022 11:04:15 +0000 (13:04 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 13 Apr 2022 08:34:51 +0000 (10:34 +0200)
only show it when enabled in config (so that we can hide it where
that is not supported, which is in PVE right now)

also changes the text between 'Download' and 'Download .zip' depending
if the selected entry is a directory or not

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/window/FileBrowser.js

index 99a7a854fee90fb983473d4861d9c4f27c577617..2efa9886a8dd148615b2c5c532e4ba35029b184a 100644 (file)
@@ -75,6 +75,9 @@ Ext.define("Proxmox.window.FileBrowser", {
            'f': true, // "normal" files
            'd': true, // directories
        },
+
+       // set to true to show the tar download button
+       enableTar: false,
     },
 
     controller: {
@@ -89,7 +92,15 @@ Ext.define("Proxmox.window.FileBrowser", {
            return url.href;
        },
 
-       downloadFile: function() {
+       downloadTar: function() {
+           this.downloadFile(true);
+       },
+
+       downloadZip: function() {
+           this.downloadFile(false);
+       },
+
+       downloadFile: function(tar) {
            let me = this;
            let view = me.getView();
            let tree = me.lookup('tree');
@@ -105,7 +116,12 @@ Ext.define("Proxmox.window.FileBrowser", {
            params.filepath = data.filepath;
            atag.download = data.text;
            if (data.type === 'd') {
-               atag.download += ".zip";
+               if (tar) {
+                   params.tar = 1;
+                   atag.download += ".tar.zst";
+               } else {
+                   atag.download += ".zip";
+               }
            }
            atag.href = me.buildUrl(view.downloadURL, params);
            atag.click();
@@ -120,12 +136,18 @@ Ext.define("Proxmox.window.FileBrowser", {
 
            let data = selection[0].data;
            let canDownload = view.downloadURL && view.downloadableFileTypes[data.type];
-           me.lookup('downloadBtn').setDisabled(!canDownload);
+           let zipBtn = me.lookup('downloadBtn');
+           let tarBtn = me.lookup('downloadTar');
+           zipBtn.setDisabled(!canDownload);
+           tarBtn.setDisabled(!canDownload);
+           zipBtn.setText(data.type === 'd' ? gettext('Download .zip') : gettext('Download'));
+           tarBtn.setVisible(data.type === 'd' && view.enableTar);
        },
 
        errorHandler: function(error, msg) {
            let me = this;
            me.lookup('downloadBtn').setDisabled(true);
+           me.lookup('downloadTar').setDisabled(true);
            if (me.initialLoadDone) {
                Ext.Msg.alert(gettext('Error'), msg);
                return true;
@@ -245,8 +267,15 @@ Ext.define("Proxmox.window.FileBrowser", {
 
     buttons: [
        {
-           text: gettext('Download'),
-           handler: 'downloadFile',
+           text: gettext('Download .tar.zst'),
+           handler: 'downloadTar',
+           reference: 'downloadTar',
+           hidden: true,
+           disabled: true,
+       },
+       {
+           text: gettext('Download .zip'),
+           handler: 'downloadZip',
            reference: 'downloadBtn',
            disabled: true,
        },