Work on "delete" functions for recovery meetings.

This commit is contained in:
Scott Idem
2024-11-15 11:26:47 -05:00
parent 40081c2804
commit 6a390762d3
2 changed files with 40 additions and 29 deletions

View File

@@ -225,7 +225,7 @@ $: if ($idaa_slct.event_obj) {
}
if ($idaa_slct.event_obj == null) {
// $idaa_slct.event_obj = {code: null, name: null, description: null, start_datetime: null, end_datetime: null, notes: null};
$idaa_slct.event_obj = {contact_li_json: []};
} else {
disable_submit_btn = false;
}
@@ -481,32 +481,35 @@ async function handle_submit_form(event: any) {
}
}
async function handle_delete_event_obj({event_id, method='disable'}) {
console.log('*** handle_delete_event_obj() ***');
async function handle_delete_event_obj(
{
event_id,
method = 'disable'
}: {
event_id: string,
method?: string
}
) {
if (log_lvl) {
console.log('*** handle_delete_event_obj() ***');
}
prom_api__event_obj = api.delete_ae_obj_id_crud({
prom_api__event_obj = events_func.delete_ae_obj_id__event({
api_cfg: $ae_api,
obj_type: 'event',
obj_id: event_id,
event_id: event_id,
method: method,
// params: params,
key: $ae_api.api_crud_super_key,
log_lvl: 0
log_lvl: log_lvl
})
.then(function (event_obj_delete_result) {
if (event_obj_delete_result) {
// console.log(`Result:`, event_obj_delete_result);
dispatch(
'deleted__event_obj',
{
event_id: event_id,
}
);
}
$idaa_sess.recovery_meetings.show__modal_edit = false;
})
.catch(function (error) {
console.log('The result was null or false when trying to delete.', error);
})
.finally(() => {
// $idaa_sess.recovery_meetings.show__modal_edit = false;
$idaa_slct.event_id = null;
$idaa_slct.event_obj = null;
});
return prom_api__event_obj;
@@ -1009,7 +1012,7 @@ async function handle_delete_event_obj({event_id, method='disable'}) {
<span class="ae_group">
{#if !($ae_loc.administrator_access || $idaa_slct.event_obj?.contact_li_json[0]?.unlock)}
{#if !($ae_loc.administrator_access || ($idaa_slct.event_obj?.contact_li_json?.length && $idaa_slct.event_obj?.contact_li_json[0]?.unlock))}
<button type="button" class="ae_btn ae_smaller ae_btn_info"
on:click|preventDefault={() => {
if (confirm('Are you sure you want to lock these fields? The primary contact name and email address are required.')) {
@@ -1228,42 +1231,45 @@ async function handle_delete_event_obj({event_id, method='disable'}) {
{#if $idaa_slct.event_id}
{#if $ae_loc.administrator_access}
<button
type="button"
on:click={() => {
if (!confirm('Are you sure you want to delete this event?')) {return false;}
handle_delete_event_obj({event_id: $idaa_slct.event_id, method: 'delete'});
$idaa_slct.event_id = null;
$lq__event_obj = {};
// $idaa_slct.event_id = null;
// $lq__event_obj = {};
}}
class="btn btn-sm variant-soft-warning" type="button"
class="btn btn-sm variant-soft-warning"
title="Delete record permanently"
>
<span class="fas fa-minus m-1"></span> Delete
</button>
{:else if $ae_loc.trusted_access}
<button
type="button"
on:click={() => {
if (!confirm('Are you sure you want to disable this event?')) {return false;}
handle_delete_event_obj({event_id: $idaa_slct.event_id, method: 'disable'});
$idaa_slct.event_id = null;
$lq__event_obj = {};
// $idaa_slct.event_id = null;
// $lq__event_obj = {};
}}
class="btn btn-sm variant-soft-warning" type="button"
class="btn btn-sm variant-soft-warning"
title="Disable record to delete"
>
<span class="fas fa-minus m-1"></span> Delete
</button>
{:else}
<button
type="button"
on:click={() => {
if (!confirm('Are you sure you want to hide this event?')) {return false;}
handle_delete_event_obj({event_id: $idaa_slct.event_id, method: 'hide'});
$idaa_slct.event_id = null;
$lq__event_obj = {};
// $idaa_slct.event_id = null;
// $lq__event_obj = {};
}}
class="btn btn-sm variant-soft-warning" type="button"
class="btn btn-sm variant-soft-warning"
title="Hide record to delete"
>
<span class="fas fa-comment-slash m-1"></span> Delete

View File

@@ -37,6 +37,8 @@ onMount(() => {
</h2>
{#each $lq__event_obj_li as idaa_event_obj, index}
{#if idaa_event_obj}
<div
class="container recovery_meeting event_obj border border-1 rounded p-2 mb-2"
class:hidden={(idaa_event_obj?.hide || !idaa_event_obj?.enable) && !$ae_loc.trusted_access}
@@ -292,7 +294,10 @@ onMount(() => {
</div>
</section>
{/if}
</div>
{/if}
{/each}
</div>