Work on updating the custom CRUD element.
This commit is contained in:
@@ -35,6 +35,7 @@ let {
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||
import Element_ae_crud from '$lib/element_ae_crud.svelte';
|
||||
import Element_ae_crud_v2 from '$lib/element_ae_crud_v2.svelte';
|
||||
// import Element_data_store from '$lib/element_data_store_v2.svelte';
|
||||
import Comp_event_presenter_obj_li from '../events/[event_id]/presenter/ae_comp__event_presenter_obj_li_wrapper.svelte';
|
||||
import Element_manage_event_file_li from '$lib/element_manage_event_file_li_direct.svelte';
|
||||
@@ -265,6 +266,150 @@ let ae_triggers: key_val = $state({});
|
||||
<!-- {@html session_obj?.event_location_name ? session_obj?.event_location_name : ae_snip.html__not_set} -->
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
{#if $ae_loc.edit_mode}
|
||||
<Element_ae_crud_v2
|
||||
api_cfg={$ae_api}
|
||||
|
||||
trigger_patch={ae_triggers.update_location}
|
||||
|
||||
object_type={'event_session'}
|
||||
object_id={session_obj?.event_session_id_random}
|
||||
field_name={'event_location_id_random'}
|
||||
field_type={'button'}
|
||||
|
||||
current_field_value={session_obj?.event_location_id_random}
|
||||
|
||||
allow_null={true}
|
||||
|
||||
hide_element={!$ae_loc.edit_mode}
|
||||
hide_edit_btn={false}
|
||||
hide_edit_form={true}
|
||||
|
||||
outline_element={false}
|
||||
display_inline={true}
|
||||
class_li={'m-1'}
|
||||
>
|
||||
{#await $slct.location_obj_li}
|
||||
<span class="fas fa-spinner fa-spin mx-1"></span>
|
||||
{:then location_obj_li}
|
||||
{#if location_obj_li && location_obj_li.length > 0}
|
||||
<label class="text-sm">Location:
|
||||
<select
|
||||
bind:value={ae_tmp[session_obj.event_session_id_random].event_location_id_random}
|
||||
class="select min-w-fit max-w-md text-sm"
|
||||
>
|
||||
<option value="">-- No location --</option>
|
||||
{#each location_obj_li as location_obj}
|
||||
<option
|
||||
value={location_obj.event_location_id_random}
|
||||
selected={location_obj.event_location_id_random == session_obj?.event_location_id_random}
|
||||
>
|
||||
{location_obj.name}
|
||||
({location_obj.event_location_id_random})
|
||||
</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
disabled={ae_tmp[session_obj.event_session_id_random].event_location_id_random == session_obj?.event_location_id_random}
|
||||
onclick={() => {
|
||||
console.log('Save the location for the session.');
|
||||
let location_id = ae_tmp[session_obj.event_session_id_random].event_location_id_random;
|
||||
console.log('Selected location ID:', location_id);
|
||||
ae_triggers.update_location = true;
|
||||
}}
|
||||
class="btn btn-sm preset-tonal-warning hover:preset-tonal-warning border border-warning
|
||||
"
|
||||
>
|
||||
<span class="fas fa-save mx-1"></span>
|
||||
Save
|
||||
</button>
|
||||
{/if}
|
||||
{/await}
|
||||
</Element_ae_crud_v2>
|
||||
{/if}
|
||||
|
||||
|
||||
{#if ae_tmp?.show__edit_location}
|
||||
|
||||
{#await $slct.event_location_obj_li}
|
||||
<span class="fas fa-spinner fa-spin mx-1"></span>
|
||||
{:then event_location_obj_li}
|
||||
<!-- {#if event_location_obj_li && event_location_obj_li.length > 0}
|
||||
|
||||
{/if} -->
|
||||
{/await}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
console.log('Cancel editing the location for the session.');
|
||||
|
||||
ae_tmp.event_location_id = null;
|
||||
ae_tmp.show__edit_event_location = false;
|
||||
}}
|
||||
class="btn btn-sm preset-tonal-warning hover:preset-tonal-warning border border-warning-500"
|
||||
>
|
||||
<span class="fas fa-times mx-1"></span>
|
||||
Cancel
|
||||
</button>
|
||||
|
||||
{:else}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
console.log('Edit the location for the session.');
|
||||
|
||||
let params = {
|
||||
qry__limit: 50,
|
||||
}
|
||||
|
||||
// $slct.event_location_obj_li = await core_func.load_ae_obj_li__event_location({api_cfg: $ae_api, account_id: $slct.account_id, params: params});
|
||||
|
||||
$slct.event_location_obj_li = events_func.load_ae_obj_li__event_location({
|
||||
api_cfg: $ae_api,
|
||||
for_obj_type: 'event',
|
||||
for_obj_id: session_obj?.event_id_random,
|
||||
params: params,
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(function (load_results) {
|
||||
console.log(`Loaded event_location_obj_li:`, load_results);
|
||||
|
||||
// We need to make this ready for the select option list. Convert the list to a key value pair with the event_location_id_random as the key. We also need to set the option text value to: name (room)
|
||||
if (load_results) {
|
||||
let event_location_obj_li = load_results;
|
||||
let event_location_obj_kv = {}; //: key_val = {};
|
||||
event_location_obj_kv[''] = '-- Select a location --';
|
||||
event_location_obj_li.forEach((event_location_obj) => {
|
||||
let option_text = `${event_location_obj.name} (${event_location_obj.code})`;
|
||||
event_location_obj_kv[event_location_obj.event_location_id_random] = option_text;
|
||||
});
|
||||
$slct.event_location_obj_kv = event_location_obj_kv;
|
||||
}
|
||||
// $slct.event_location_obj_kv = $slct.event_location_obj_kv;
|
||||
console.log(`$slct.event_location_obj_kv = `, $slct.event_location_obj_kv);
|
||||
|
||||
return load_results;
|
||||
})
|
||||
.finally(function () {
|
||||
console.log(`Finally...`);
|
||||
ae_tmp.event_location_id = session_obj?.event_location_id_random;
|
||||
ae_tmp.show__edit_event_location = true;
|
||||
});
|
||||
}}
|
||||
class="btn btn-sm preset-tonal-warning group"
|
||||
>
|
||||
<span class="fas fa-edit m-0.75"></span>
|
||||
<span class="hidden group-hover:inline">Edit</span>
|
||||
</button>
|
||||
|
||||
{/if}
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
<td
|
||||
|
||||
Reference in New Issue
Block a user