parent
8b451b3c67
commit
c87321f804
@ -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" &&
|
||||
@ -15,81 +15,84 @@
|
||||
sponsoring_contracts_download_open = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
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);
|
||||
let count = 0;
|
||||
for await (const o of generate_orgs) {
|
||||
const runners = await RunnerOrganizationService.runnerOrganizationControllerGetRunners(
|
||||
o.id
|
||||
);
|
||||
fetch(
|
||||
`${config.baseurl}/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 === generate_orgs.length) {
|
||||
toast.hideToast();
|
||||
Toastify({
|
||||
text: $_("pdfs-successfully-generated"),
|
||||
duration: 3500,
|
||||
backgroundColor:
|
||||
"linear-gradient(to right, #00b09b, #96c93d)",
|
||||
}).showToast();
|
||||
}
|
||||
})
|
||||
.catch((err) => {});
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
o.id
|
||||
);
|
||||
fetch(
|
||||
`${config.baseurl}/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) => {});
|
||||
}
|
||||
}
|
||||
|
||||
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) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user