From d639b64c42dc52e3307556ad92ac324f6443ace8 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 14 May 2020 01:58:49 +0000 Subject: [PATCH] Bug 25475: add "Copy link" button to upload.pl This patch adds a "Copy link" button to /cgi-bin/koha/tools/upload.pl. It will create a modal that displays a URL like the following: http://kohadev.myDNSname.org:8080/cgi-bin/koha/opac-retrieve-file.pl? id=beb928969032f980056ea8269bc816fe Users can then copy the URL from that modal. If the browser supports the Clipboard API, the URL is also written to the browser's clipboard, making manually copying from the modal redundant. Test plan: 0) Apply patch 1) Go to http://localhost:8081/cgi-bin/koha/tools/upload.pl 2) Upload a file with the "Allow public downloads" box checked 3) Note the "Copy link" button in the "Actions" column 4) Click "Copy link" 5) Note that a modal is created with contents like the following: http://kohadev.myDNSname.org:8080/cgi-bin/koha/opac-retrieve-file.pl? id=beb928969032f980056ea8269bc816fe 5b) If you're using a modern browser, try Ctrl+V somewhere and note that the URL has already been copied to your clipboard 6) Manually highlight the text in the modal and Ctrl+C 7) Click outside the modal 8) Paste the URL somewhere useful like a system preference or News item 9) Profit --- .../intranet-tmpl/prog/en/modules/tools/upload.tt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt index 3ed10dcae3..6c7c4356f4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt @@ -178,6 +178,7 @@ [% END %] + [% IF record.owner == owner || CAN_user_tools_upload_manage %] [% END %] @@ -416,6 +417,23 @@ var record_id = $(this).data("record-id"); SubmitMe( 'download', record_id ); }); + $(".copy_entry").on("click",function(e){ + e.preventDefault(); + var record_hashvalue = $(this).data("record-hashvalue"); + var res = '[% Koha.Preference('OPACBaseURL') | html %]'; + res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + record_hashvalue; + if (res){ + //If Clipboard API available, use it to write secretly and directly to browser clipboard + if (navigator.clipboard){ + var promise = navigator.clipboard.writeText(res); + } + //The Clipboard API isn't available to all browsers, so show a modal for people to copy from manually + var popup = '' + $(popup).modal(); + } + + console.log(res); + }); $(".delete_entry").on("click",function(e){ e.preventDefault(); var record_id = $(this).data("record-id"); -- 2.11.0