263 lines
11 KiB
Svelte
263 lines
11 KiB
Svelte
<script>
|
|
import { getLocaleFromNavigator, _ } from "svelte-i18n";
|
|
let modal_open = false;
|
|
let delete_org = {};
|
|
import { RunnerOrganizationService } from "@odit/lfk-client-js";
|
|
import store from "../../store";
|
|
import OrgsEmptyState from "./OrgsEmptyState.svelte";
|
|
import Toastify from "toastify-js";
|
|
import ConfirmOrgDeletion from "./ConfirmOrgDeletion.svelte";
|
|
$: searchvalue = "";
|
|
$: active_deletes = [];
|
|
export let current_organizations = [];
|
|
|
|
const promise = RunnerOrganizationService.runnerOrganizationControllerGetAll().then(
|
|
(val) => {
|
|
current_organizations = val;
|
|
}
|
|
);
|
|
</script>
|
|
|
|
<ConfirmOrgDeletion
|
|
on:cancelDelete={(event) => {
|
|
modal_open = false;
|
|
active_deletes[event.detail.id] = false;
|
|
}}
|
|
bind:modal_open
|
|
bind:delete_org />
|
|
{#if store.state.jwtinfo.userdetails.permissions.includes('ORGANIZATION:GET')}
|
|
{#await promise}
|
|
<div
|
|
class="bg-teal-lightest border-t-4 border-teal rounded-b text-teal-darkest px-4 py-3 shadow-md my-2"
|
|
role="alert">
|
|
<p class="font-bold">{$_('organizations-are-being-loaded')}</p>
|
|
<p class="text-sm">{$_('this-might-take-a-moment')}</p>
|
|
</div>
|
|
{:then}
|
|
{#if current_organizations.length === 0}
|
|
<OrgsEmptyState />
|
|
{:else}
|
|
<input
|
|
type="search"
|
|
bind:value={searchvalue}
|
|
placeholder={$_('datatable.search')}
|
|
aria-label={$_('datatable.search')}
|
|
class="gridjs-input gridjs-search-input mb-4" />
|
|
<div class="h-12">
|
|
{#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') {
|
|
const toast = Toastify({
|
|
text: $_('pdf-generation-failed'),
|
|
duration: 1000,
|
|
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) => {});
|
|
}
|
|
}}
|
|
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">
|
|
{$_('generate-sponsoring-contracts')}
|
|
</button>
|
|
{/if}
|
|
</div>
|
|
<div
|
|
class="shadow border-b border-gray-200 sm:rounded-lg overflow-x-scroll">
|
|
<table class="divide-y divide-gray-200 w-full">
|
|
<thead class="bg-gray-50">
|
|
<tr>
|
|
<th
|
|
scope="col"
|
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
<span
|
|
on:click={() => {
|
|
const newstate = !current_organizations.some((r) => r.is_selected === true);
|
|
current_organizations = current_organizations.map((r) => {
|
|
r.is_selected = newstate;
|
|
return r;
|
|
});
|
|
}}
|
|
class="underline cursor-pointer select-none">{#if current_organizations.some((r) => r.is_selected === true)}
|
|
{$_('deselect-all')}
|
|
{:else}{$_('select-all')}{/if}
|
|
</span>
|
|
</th>
|
|
<th
|
|
scope="col"
|
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
{$_('name')}
|
|
</th>
|
|
<th
|
|
scope="col"
|
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
{$_('address')}
|
|
</th>
|
|
<th
|
|
scope="col"
|
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
{$_('contact')}
|
|
</th>
|
|
<th scope="col" class="relative px-6 py-3">
|
|
<span class="sr-only">{$_('action')}</span>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-gray-200">
|
|
{#each current_organizations as o}
|
|
{#if Object.values(o)
|
|
.toString()
|
|
.toLowerCase()
|
|
.includes(searchvalue)}
|
|
<tr data-rowid="org_{o.id}">
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<input
|
|
bind:checked={o.is_selected}
|
|
type="checkbox"
|
|
class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded" />
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<div class="flex items-center">
|
|
<div class="ml-4">
|
|
<div class="text-sm font-medium text-gray-900">
|
|
{o.name}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<div class="flex items-center">
|
|
<div class="ml-4">
|
|
<div class="text-sm font-medium text-gray-900">
|
|
{#if o.address.address1 !== null}
|
|
{o.address.address1}<br />
|
|
{o.address.address2 || ''}<br />
|
|
{o.address.postalcode}
|
|
{o.address.city}
|
|
{o.address.country}
|
|
{/if}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<div class="flex items-center">
|
|
<div class="ml-4">
|
|
<div class="text-sm font-medium text-gray-900">
|
|
{#if o.contact}
|
|
<a
|
|
href="../contacts/{o.contact.id}"
|
|
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">{o.contact.firstname}
|
|
{o.contact.middlename || ''}
|
|
{o.contact.lastname}</a>
|
|
{:else}{$_('no-contact-specified')}{/if}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
{#if active_deletes[o.id] === true}
|
|
<td
|
|
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
|
<button
|
|
on:click={() => {
|
|
active_deletes[o.id] = false;
|
|
}}
|
|
tabindex="0"
|
|
class="ml-4 text-indigo-600 hover:text-indigo-900 cursor-pointer">{$_('cancel-delete')}</button>
|
|
<button
|
|
on:click={() => {
|
|
RunnerOrganizationService.runnerOrganizationControllerRemove(o.id, false)
|
|
.then((resp) => {
|
|
current_organizations = current_organizations.filter((obj) => obj.id !== o.id);
|
|
Toastify({
|
|
text: 'Organization deleted',
|
|
duration: 500,
|
|
backgroundColor:
|
|
'linear-gradient(to right, #00b09b, #96c93d)',
|
|
}).showToast();
|
|
})
|
|
.catch((err) => {
|
|
modal_open = true;
|
|
delete_org = o;
|
|
});
|
|
}}
|
|
tabindex="0"
|
|
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer">{$_('confirm-delete')}</button>
|
|
</td>
|
|
{:else}
|
|
<td
|
|
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
|
<a
|
|
href="./{o.id}"
|
|
class="text-indigo-600 hover:text-indigo-900">{$_('details')}</a>
|
|
{#if store.state.jwtinfo.userdetails.permissions.includes('ORGANIZATION:DELETE')}
|
|
<button
|
|
on:click={() => {
|
|
active_deletes[o.id] = true;
|
|
}}
|
|
tabindex="0"
|
|
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer">{$_('delete')}</button>
|
|
{/if}
|
|
</td>
|
|
{/if}
|
|
</tr>
|
|
{/if}
|
|
{/each}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{/if}
|
|
{:catch error}
|
|
<div class="text-white px-6 py-4 border-0 rounded relative mb-4 bg-red-500">
|
|
<span class="inline-block align-middle mr-8">
|
|
<b class="capitalize">{$_('general_promise_error')}</b>
|
|
{error}
|
|
</span>
|
|
</div>
|
|
{/await}
|
|
{/if}
|