From 2ff06f35fda75554e8fb78718ecd4cc374c609a6 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:44:55 +0200 Subject: [PATCH] [QSLPrint] Added export button for selected QSOs --- application/views/qslprint/qslprint.php | 9 +++-- assets/js/sections/qslprint.js | 53 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/application/views/qslprint/qslprint.php b/application/views/qslprint/qslprint.php index e8f1cfbb2..3e7746bfd 100644 --- a/application/views/qslprint/qslprint.php +++ b/application/views/qslprint/qslprint.php @@ -1,3 +1,6 @@ + result() != NULL) { echo ''; ?> -

- -

+

+ +

" class="btn btn-primary"> diff --git a/assets/js/sections/qslprint.js b/assets/js/sections/qslprint.js index 538613671..59c9fe556 100644 --- a/assets/js/sections/qslprint.js +++ b/assets/js/sections/qslprint.js @@ -244,3 +244,56 @@ function removeSelectedQsos() { } }); } + +function exportSelectedQsos() { + var elements = $('.qslprint tbody input:checked'); + var nElements = elements.length; + if (nElements == 0) { + return; + } + $('.exportselected').prop("disabled", true); + + var id_list=[]; + elements.each(function() { + let id = $(this).first().closest('tr').attr('id'); + id = id.match(/\d/g); + id = id.join(""); + id_list.push(id); + }); + + xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + var a; + if (xhttp.readyState === 4 && xhttp.status === 200) { + // Trick for making downloadable link + a = document.createElement('a'); + a.href = window.URL.createObjectURL(xhttp.response); + // Give filename you wish to download + // Get the current date and time + const now = new Date(); + + // Format the date and time as UTC Ymd-Hi + const year = now.getUTCFullYear(); + const month = String(now.getUTCMonth() + 1).padStart(2, '0'); // Months are zero-based + const day = String(now.getUTCDate()).padStart(2, '0'); + const hours = String(now.getUTCHours()).padStart(2, '0'); + const minutes = String(now.getUTCMinutes()).padStart(2, '0'); + + // Create the formatted filename + const filename = `${user_callsign}-${year}${month}${day}-${hours}${minutes}.adi`; + a.download = filename; + a.style.display = 'none'; + document.body.appendChild(a); + a.click(); + } + }; + + // Post data to URL which handles post request + xhttp.open("POST", site_url+'/logbookadvanced/export_to_adif', true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + // You should set responseType as blob for binary responses + xhttp.responseType = 'blob'; + xhttp.send("id=" + JSON.stringify(id_list, null, 2)); + + $('.exportselected').prop("disabled", false); +}