Fixed org generation not hiding the generation toast

ref #94
This commit is contained in:
Nicolai Ort 2021-03-25 20:12:32 +01:00
parent 8b451b3c67
commit c87321f804

View File

@ -6,7 +6,7 @@
export let generate_runners = [];
export let generate_orgs = [];
export let generate_teams = [];
$: sponsoring_contracts_download_open=false;
$: sponsoring_contracts_download_open = false;
document.addEventListener("click", function (e) {
if (
e.target.parentNode?.parentNode?.id != "sponsoring:dropdown" &&
@ -18,27 +18,25 @@
function generateSponsoringContract(locale) {
sponsoring_contracts_download_open = false;
if (generate_orgs.length > 0) {
generateOrgContracts(locale);
} else if (generate_teams.length > 0) {
generateTeamContracts(locale);
} else {
generateRunnerContracts(locale);
}
}
function generateTeamContracts(locale) {
//TODO:
}
async function generateOrgContracts(locale) {
const toast = Toastify({
text: $_("generating-pdf"),
duration: -1,
}).showToast();
if(generate_orgs.length>0){
generateOrgContracts(toast, locale);
}
else if(generate_teams.length>0){
generateTeamContracts(toast, locale);
}
else{
generateRunnerContracts(toast, locale);
}
}
function generateTeamContracts(toast, locale) {
//TODO:
}
async function generateOrgContracts(toast, locale) {
let count = 0;
for await (const o of generate_orgs) {
const runners = await RunnerOrganizationService.runnerOrganizationControllerGetRunners(
@ -76,12 +74,13 @@
document.body.appendChild(a);
a.click();
a.remove();
if (count === orgs.length) {
if (count === generate_orgs.length) {
toast.hideToast();
Toastify({
text: $_("pdfs-successfully-generated"),
duration: 3500,
backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
backgroundColor:
"linear-gradient(to right, #00b09b, #96c93d)",
}).showToast();
}
})
@ -89,7 +88,11 @@
}
}
function generateRunnerContracts(toast, locale) {
function generateRunnerContracts(locale) {
const toast = Toastify({
text: $_("generating-pdf"),
duration: -1,
}).showToast();
fetch(
`${config.baseurl}/documents/contracts?locale=${locale}&download=true&key=${config.documentserver_key}`,
{
@ -97,9 +100,7 @@
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(
generate_runners
),
body: JSON.stringify(generate_runners),
}
)
.then((response) => {