From 6d714f02029cd0918dc71b153451c99bb37e0442 Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Wed, 9 Dec 2020 16:29:40 +0100
Subject: [PATCH] EHN: set filename of exported bookmarks to
 bookmarked_entities.tsv

---
 src/core/js/ext_bookmarks.js | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/core/js/ext_bookmarks.js b/src/core/js/ext_bookmarks.js
index 178280d9..d99ff362 100644
--- a/src/core/js/ext_bookmarks.js
+++ b/src/core/js/ext_bookmarks.js
@@ -243,6 +243,23 @@ var ext_bookmarks = function ($, logger, config) {
         return `${preamble}${header}${rows.join(newline)}`;
     }
 
+    /**
+     * Download the table with a given filename.
+     *
+     * This method adds a temporay <A> element to the dom tree and triggers
+     * "click" because otherwise the filename cannot be set.
+     *
+     * See also:
+     * https://stackoverflow.com/questions/21177078/javascript-download-csv-as-file
+     */
+    const download = function (table, filename) {
+        console.log("download");
+        const link = $(`<a style="display: none" download="${filename}" href="${table}"/>`);
+        $("body").append(link);
+        link[0].click();
+        link.remove();
+    }
+
     /**
      * Trigger the download of the TSV table with all current bookmarks.
      *
@@ -261,7 +278,7 @@ var ext_bookmarks = function ($, logger, config) {
         const uri = get_collection_link(ids);
         const leading_comments = [encodeURIComponent(`#Link to all entities: ${uri}`)];
         const export_table = await get_export_table(ids, undefined, undefined, undefined, leading_comments);
-        window.location.href = export_table;
+        download(export_table, "bookmarked_entities.tsv");
     }
 
     /**
-- 
GitLab