diff --git a/src/components/orgs/OrgDetail.svelte b/src/components/orgs/OrgDetail.svelte index 3934110b..ce547d0e 100644 --- a/src/components/orgs/OrgDetail.svelte +++ b/src/components/orgs/OrgDetail.svelte @@ -100,6 +100,55 @@ } } export let import_modal_open = false; + async function generateSponsoringContract(locale) { + locale = getLocaleFromNavigator(); + const runners = await RunnerOrganizationService.runnerOrganizationControllerGetRunners( + original_object.id + ); + const toast = Toastify({ + text: $_("generating-pdf"), + duration: -1, + }).showToast(); + fetch( + `https://dev.lauf-fuer-kaya.de/documents/contracts?locale=${locale}&download=true&key=${config.documentserver_key}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(runners), + } + ) + .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 = "Sponsorings_" + original_object.name + ".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) => {}); + } diff --git a/src/components/orgs/OrgOverview.svelte b/src/components/orgs/OrgOverview.svelte index 45d86f80..07b78da1 100644 --- a/src/components/orgs/OrgOverview.svelte +++ b/src/components/orgs/OrgOverview.svelte @@ -16,6 +16,63 @@ current_organizations = val; } ); + + async function generateSponsoringContract(locale) { + locale = getLocaleFromNavigator(); + const orgs = current_organizations.filter((r) => r.is_selected === true); + const toast = Toastify({ + text: $_("generating-pdfs"), + duration: -1, + }).showToast(); + let count = 0; + for await (const o of orgs) { + const runners = await RunnerOrganizationService.runnerOrganizationControllerGetRunners( + o.id + ); + fetch( + `https://dev.lauf-fuer-kaya.de/documents/contracts?locale=${locale}&download=true&key=${config.documentserver_key}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(runners), + } + ) + .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) => { + count++; + const url = window.URL.createObjectURL(blob); + let a = document.createElement("a"); + a.href = url; + a.download = "Sponsorings_" + o.name + ".pdf"; + document.body.appendChild(a); + a.click(); + a.remove(); + if (count === orgs.length) { + toast.hideToast(); + Toastify({ + text: $_("pdfs-successfully-generated"), + duration: 3500, + backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)", + }).showToast(); + } + }) + .catch((err) => {}); + } + } r.is_selected === true)} @@ -293,7 +297,9 @@
- +