parent
8b451b3c67
commit
c87321f804
@ -6,7 +6,7 @@
|
|||||||
export let generate_runners = [];
|
export let generate_runners = [];
|
||||||
export let generate_orgs = [];
|
export let generate_orgs = [];
|
||||||
export let generate_teams = [];
|
export let generate_teams = [];
|
||||||
$: sponsoring_contracts_download_open=false;
|
$: sponsoring_contracts_download_open = false;
|
||||||
document.addEventListener("click", function (e) {
|
document.addEventListener("click", function (e) {
|
||||||
if (
|
if (
|
||||||
e.target.parentNode?.parentNode?.id != "sponsoring:dropdown" &&
|
e.target.parentNode?.parentNode?.id != "sponsoring:dropdown" &&
|
||||||
@ -15,81 +15,84 @@
|
|||||||
sponsoring_contracts_download_open = false;
|
sponsoring_contracts_download_open = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function generateSponsoringContract(locale) {
|
function generateSponsoringContract(locale) {
|
||||||
sponsoring_contracts_download_open = false;
|
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({
|
const toast = Toastify({
|
||||||
text: $_("generating-pdf"),
|
text: $_("generating-pdf"),
|
||||||
duration: -1,
|
duration: -1,
|
||||||
}).showToast();
|
}).showToast();
|
||||||
|
let count = 0;
|
||||||
if(generate_orgs.length>0){
|
for await (const o of generate_orgs) {
|
||||||
generateOrgContracts(toast, locale);
|
const runners = await RunnerOrganizationService.runnerOrganizationControllerGetRunners(
|
||||||
}
|
o.id
|
||||||
else if(generate_teams.length>0){
|
);
|
||||||
generateTeamContracts(toast, locale);
|
fetch(
|
||||||
}
|
`${config.baseurl}/documents/contracts?locale=${locale}&download=true&key=${config.documentserver_key}`,
|
||||||
else{
|
{
|
||||||
generateRunnerContracts(toast, locale);
|
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) {
|
function generateRunnerContracts(locale) {
|
||||||
//TODO:
|
const toast = Toastify({
|
||||||
}
|
text: $_("generating-pdf"),
|
||||||
|
duration: -1,
|
||||||
async function generateOrgContracts(toast, locale) {
|
}).showToast();
|
||||||
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) {
|
|
||||||
fetch(
|
fetch(
|
||||||
`${config.baseurl}/documents/contracts?locale=${locale}&download=true&key=${config.documentserver_key}`,
|
`${config.baseurl}/documents/contracts?locale=${locale}&download=true&key=${config.documentserver_key}`,
|
||||||
{
|
{
|
||||||
@ -97,9 +100,7 @@
|
|||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(
|
body: JSON.stringify(generate_runners),
|
||||||
generate_runners
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user