From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 982F5C9F2
 for <pbs-devel@lists.proxmox.com>; Tue, 12 Apr 2022 13:04:20 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 8E278DC4A
 for <pbs-devel@lists.proxmox.com>; Tue, 12 Apr 2022 13:04:20 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 20122DC13
 for <pbs-devel@lists.proxmox.com>; Tue, 12 Apr 2022 13:04:19 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id ED678415F2
 for <pbs-devel@lists.proxmox.com>; Tue, 12 Apr 2022 13:04:18 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Tue, 12 Apr 2022 13:04:15 +0200
Message-Id: <20220412110418.3360746-4-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20220412110418.3360746-1-d.csapak@proxmox.com>
References: <20220412110418.3360746-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.139 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [atag.download]
Subject: [pbs-devel] [PATCH widget-toolkit 1/1] window/FileBrowser: add
 optional 'tar.zst' button
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 12 Apr 2022 11:04:20 -0000

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>
---
 src/window/FileBrowser.js | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/src/window/FileBrowser.js b/src/window/FileBrowser.js
index 99a7a85..2efa988 100644
--- a/src/window/FileBrowser.js
+++ b/src/window/FileBrowser.js
@@ -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,
 	},
-- 
2.30.2