diff --git a/package.json b/package.json index 25832f28..2c695d0c 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "license": "CC-BY-NC-SA-4.0", "dependencies": { - "@odit/lfk-client-js": "0.8.0", + "@odit/lfk-client-js": "0.9.2", "check-password-strength": "^2.0.2", "csvtojson": "^2.0.10", "gridjs": "3.3.0", diff --git a/src/components/cards/AddCardBulkModal.svelte b/src/components/cards/AddCardBulkModal.svelte index 81d68633..1ab16278 100644 --- a/src/components/cards/AddCardBulkModal.svelte +++ b/src/components/cards/AddCardBulkModal.svelte @@ -22,19 +22,19 @@ if (e.keyCode === 13) { if (createbtnenabled === true) { createbtnenabled = false; - submit(); + submit_with_print(); } } }; })(); - function submit() { + function submit_without_print() { if (processed_last_submit === true) { processed_last_submit = false; const toast = Toastify({ text: $_("creating-blanco-cards"), duration: -1, }).showToast(); - RunnerCardService.runnerCardControllerPostBlancoBulk(card_count) + RunnerCardService.runnerCardControllerPostBlancoBulk(card_count, false) .then((result) => { bulk_modal_open = false; // @@ -54,6 +54,80 @@ }); } } + + function submit_with_print() { + if (processed_last_submit === true) { + processed_last_submit = false; + const toast = Toastify({ + text: $_("creating-blanco-cards"), + duration: -1, + }).showToast(); + RunnerCardService.runnerCardControllerPostBlancoBulk(card_count, true) + .then((result) => { + bulk_modal_open = false; + // + Toastify({ + text: $_("created-blanco-cards"), + duration: 500, + backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)", + }).showToast(); + current_cards = current_cards.concat(result); + const toast = Toastify({ + text: $_("generating-pdf"), + duration: -1, + }).showToast(); + fetch( + `${config.baseurl}/documents/cards?&download=true&key=${config.documentserver_key}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(result), + } + ) + .then((response) => { + if (response.status != "200") { + toast.hideToast(); + Toastify({ + text: $_("pdf-generation-failed"), + duration: 3500, + backgroundColor: + "linear-gradient(90deg, hsla(281, 37%, 45%, 1) 0%, hsla(1, 62%, 48%, 1) 100%)", + }).showToast(); + } else { + return response.blob(); + } + }) + .then((blob) => { + const url = window.URL.createObjectURL(blob); + let a = document.createElement("a"); + a.href = url; + a.download = "Bulkcards.pdf"; + document.body.appendChild(a); + a.click(); + a.remove(); + toast.hideToast(); + Toastify({ + text: $_("pdf-successfully-generated"), + duration: 3500, + backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)", + }).showToast(); + }) + .catch((err) => { + console.error(err); + }); + }) + .catch((err) => { + // + }) + .finally(() => { + processed_last_submit = true; + // + toast.hideToast(); + }); + } + } {#if bulk_modal_open} @@ -75,14 +149,14 @@ class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">