basic functionality in OrgDetail

ref #16
This commit is contained in:
Philipp Dormann 2021-01-15 19:25:30 +01:00
parent 0b9f3de47c
commit 0e2a10fe94

View File

@ -4,27 +4,40 @@
import store from "../store";
import PromiseError from "./PromiseError.svelte";
$: delete_triggered = false;
$: save_enabled = false;
$: save_enabled = !data_changed;
export let params;
console.log(params);
let data_original = {};
let orgdata = {};
let original = {};
$: data_loaded = false;
$: data_changed = JSON.stringify(orgdata) === JSON.stringify(original);
const promise = RunnerOrganisationService.runnerOrganisationControllerGetOne(
params.orgid
).then((value) => {
data_loaded = true;
data_original = Object.assign(data_original, value);
orgdata = Object.assign(orgdata, value);
original = Object.assign(original, value);
});
function deleteOrganisation() {
RunnerOrganisationService.runnerOrganisationControllerRemove(
original.id,
true
)
.then((resp) => {
location.replace("./");
})
.catch((err) => {});
}
</script>
{#if data_loaded}
<section class="container p-5">
<div class="mb-8 text-3xl font-extrabold leading-tight">
{data_original.name}
<span data-id="org_actions_${data_original.id}">
{original.name}
<span data-id="org_actions_${orgdata.id}">
{#if store.state.jwtinfo.userdetails.permissions.includes('USER:DELETE')}
{#if delete_triggered}
<button
on:click={deleteOrganisation}
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-600 text-base font-medium text-white hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:ml-3 sm:w-auto sm:text-sm">{$_('confirm-delete')}</button>
<button
on:click={() => {
@ -38,7 +51,7 @@
delete_triggered = true;
}}
type="button"
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-600 text-base font-medium text-white hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:ml-3 sm:w-auto sm:text-sm">{$_('delete-user')}</button>
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-600 text-base font-medium text-white hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:ml-3 sm:w-auto sm:text-sm">{$_('delete-organization')}</button>
{/if}
{/if}
{#if !delete_triggered}
@ -127,7 +140,7 @@
autocomplete="off"
placeholder="Name"
type="text"
bind:value={data_original.name}
bind:value={orgdata.name}
name="name"
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 dark:bg-gray-900 dark:text-gray-100 rounded-md p-2" />
</div>
@ -139,7 +152,7 @@
autocomplete="off"
placeholder={$_('contact')}
type="text"
bind:value={data_original.contact}
bind:value={orgdata.contact}
name="contact"
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 dark:bg-gray-900 dark:text-gray-100 rounded-md p-2" />
</div>
@ -151,7 +164,7 @@
autocomplete="off"
placeholder={$_('address')}
type="text"
bind:value={data_original.address}
bind:value={orgdata.address}
name="address"
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 dark:bg-gray-900 dark:text-gray-100 rounded-md p-2" />
</div>