From c8d639024a5f2f72d6e30d2ce990b08bd71a5471 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Mon, 29 Mar 2021 17:44:30 +0200 Subject: [PATCH] Added function for generating cards with pdf ref #116 --- src/components/cards/AddCardBulkModal.svelte | 79 +++++++++++++++++++- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/src/components/cards/AddCardBulkModal.svelte b/src/components/cards/AddCardBulkModal.svelte index 81d68633..f032ea5f 100644 --- a/src/components/cards/AddCardBulkModal.svelte +++ b/src/components/cards/AddCardBulkModal.svelte @@ -22,12 +22,12 @@ 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({ @@ -54,6 +54,79 @@ }); } } + + 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) + .then((result) => { + bulk_modal_open = false; + // + Toastify({ + text: $_("created-blanco-cards"), + duration: 500, + backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)", + }).showToast(); + 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} @@ -138,7 +211,7 @@