Moved pdf generation to function instead of onclick for all components

ref #48
This commit is contained in:
Nicolai Ort 2021-02-27 20:09:50 +01:00
parent 6870e31a81
commit 22e9f53c42
5 changed files with 269 additions and 248 deletions

View File

@ -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) => {});
}
</script>
<ImportRunnerModal
@ -120,52 +169,7 @@
<span data-id="org_actions_${editable.id}">
<button
on:click={async () => {
const 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) => {});
generateSponsoringContract('de');
}}
type="button"
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-gray-600 text-base font-medium text-white hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 sm:ml-3 sm:w-auto sm:text-sm">{$_('generate-sponsoring-contracts')}</button>

View File

@ -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) => {});
}
}
</script>
<ConfirmOrgDeletion
@ -47,59 +104,7 @@
{#if current_organizations.some((r) => r.is_selected === true)}
<button
on:click={async () => {
const 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) => {});
}
generateSponsoringContract('de');
}}
type="button"
class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-gray-600 text-base font-medium text-white hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 sm:w-auto sm:text-sm">

View File

@ -42,6 +42,56 @@
}
return id.toString() === searchvalue;
}
function generateSponsoringContract(locale) {
locale = getLocaleFromNavigator();
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(
current_runners.filter((r) => r.is_selected === true)
),
}
)
.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 = "Sponsoring.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);
});
}
</script>
{#if store.state.jwtinfo.userdetails.permissions.includes('RUNNER:GET')}
@ -80,55 +130,7 @@
{#if current_runners.some((r) => r.is_selected === true)}
<button
on:click={() => {
const locale = getLocaleFromNavigator();
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(
current_runners.filter((r) => r.is_selected === true)
),
}
)
.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 = 'Sponsoring.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);
});
generateSponsoringContract('de');
}}
type="button"
class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-gray-600 text-base font-medium text-white hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 sm:w-auto sm:text-sm">

View File

@ -82,6 +82,55 @@
.catch((err) => {});
}
}
async function generateSponsoringContract(locale) {
locale = getLocaleFromNavigator();
const runners = await RunnerTeamService.runnerTeamControllerGetRunners(
teamdata.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_" + teamdata.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) => {});
}
</script>
<ImportRunnerModal
@ -102,52 +151,7 @@
<span data-id="org_actions_${teamdata.id}">
<button
on:click={async () => {
const locale = getLocaleFromNavigator();
const runners = await RunnerTeamService.runnerTeamControllerGetRunners(teamdata.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_' + teamdata.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) => {});
generateSponsoringContract('de');
}}
type="button"
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-gray-600 text-base font-medium text-white hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 sm:ml-3 sm:w-auto sm:text-sm">{$_('generate-sponsoring-contracts')}</button>
@ -293,7 +297,9 @@
</select>
</div>
<div class="text-sm w-full">
<label for="org" class="font-medium text-gray-700">{$_('organization')}</label>
<label
for="org"
class="font-medium text-gray-700">{$_('organization')}</label>
<select
name="org"
bind:value={teamdata.parentGroup}

View File

@ -17,6 +17,62 @@
teams_promise.then((data) => {
usersstore.set(data);
});
async function generateSponsoringContract(locale) {
locale = getLocaleFromNavigator();
const teams = current_teams.filter((r) => r.is_selected === true);
const toast = Toastify({
text: $_("generating-pdfs"),
duration: -1,
}).showToast();
let count = 0;
for await (const t of teams) {
count++;
const runners = await RunnerTeamService.runnerTeamControllerGetRunners(
t.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) => {
const url = window.URL.createObjectURL(blob);
let a = document.createElement("a");
a.href = url;
a.download = "Sponsorings_" + t.name + ".pdf";
document.body.appendChild(a);
a.click();
a.remove();
if (count === teams.length) {
toast.hideToast();
Toastify({
text: $_("pdfs-successfully-generated"),
duration: 3500,
backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
}).showToast();
}
})
.catch((err) => {});
}
}
</script>
<ConfirmTeamDeletion
@ -48,59 +104,7 @@
{#if current_teams.some((r) => r.is_selected === true)}
<button
on:click={async () => {
const locale = getLocaleFromNavigator();
const teams = current_teams.filter((r) => r.is_selected === true);
const toast = Toastify({
text: $_('generating-pdfs'),
duration: -1,
}).showToast();
let count = 0;
for await (const t of teams) {
count++;
const runners = await RunnerTeamService.runnerTeamControllerGetRunners(t.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) => {
const url = window.URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
a.download = 'Sponsorings_' + t.name + '.pdf';
document.body.appendChild(a);
a.click();
a.remove();
if (count === teams.length) {
toast.hideToast();
Toastify({
text: $_('pdfs-successfully-generated'),
duration: 3500,
backgroundColor:
'linear-gradient(to right, #00b09b, #96c93d)',
}).showToast();
}
})
.catch((err) => {});
}
generateSponsoringContract('de');
}}
type="button"
class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-gray-600 text-base font-medium text-white hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 sm:w-auto sm:text-sm">