diff --git a/src/routes/sponsorships/10_edit__sponsorship_obj.svelte b/backups/src/routes/sponsorships/10_edit__sponsorship_obj.svelte similarity index 97% rename from src/routes/sponsorships/10_edit__sponsorship_obj.svelte rename to backups/src/routes/sponsorships/10_edit__sponsorship_obj.svelte index 112a9132..2dbbcf16 100644 --- a/src/routes/sponsorships/10_edit__sponsorship_obj.svelte +++ b/backups/src/routes/sponsorships/10_edit__sponsorship_obj.svelte @@ -1043,9 +1043,32 @@ async function handle_delete_sponsorship_obj({sponsorship_id, method='disable'})
{#if $slct.sponsorship_id} - + {:else} - + {/if} {#if $slct.sponsorship_id} diff --git a/src/routes/sponsorships/[slug]/hold +page.ts b/backups/src/routes/sponsorships/[slug]/hold +page.ts similarity index 100% rename from src/routes/sponsorships/[slug]/hold +page.ts rename to backups/src/routes/sponsorships/[slug]/hold +page.ts diff --git a/src/lib/ae_stores.ts b/src/lib/ae_stores.ts index 30422117..da5aaee2 100644 --- a/src/lib/ae_stores.ts +++ b/src/lib/ae_stores.ts @@ -45,9 +45,13 @@ export let ae_app_local_data_struct: key_val = { 'mod': { // module 'events': {}, 'sponsorships': { + for_type: null, + for_id: null, + show_edit__sponsorship_obj: false, show_list__sponsorship_obj_li: true, show_view__sponsorship_obj: false, + disable_submit__sponsorship_obj: false, }, 'testing': {}, }, diff --git a/src/lib/ae_utils.ts b/src/lib/ae_utils.ts index 8ab9c29e..513bbd27 100644 --- a/src/lib/ae_utils.ts +++ b/src/lib/ae_utils.ts @@ -126,7 +126,118 @@ export let iso_datetime_formatter = function iso_datetime_formatter(raw_datetime } + +/* This utility function looks for any form data with the prefixed name passed and returns a new object. + * This function is used heavily! Be very careful making changes!!! + * If rm_empty_id then it will remove/ignore fields matching. This helps with the API and new records/objects + * If rm_empty then it will remove/ignore fields matching. Sometimes this is needed. + * If trim_values then it will trim string values. + * If bool_tf_str then it will convert string values of true/false (case insensitive) to boolean values. + * Updated 2023-12-22 + */ +export let extract_prefixed_form_data = function extract_prefixed_form_data({prefix=null, form_data={}, rm_empty_id=true, rm_empty=false, trim_values=false, bool_tf_str=false, log_lvl=0}) { + if (log_lvl) { + console.log('*** extract_prefixed_form_data() ***'); + if (prefix) { + console.log(`Looking for prefixed fields: ${prefix}; Removing emptry ID fields: ${rm_empty_id}; Removing empty fields: ${rm_empty}; Trim string values: ${trim_values}; Convert true/false string values to boolean: ${bool_tf_str}`); + } else { + console.log(`No prefix set. Looking at all fields. Removing emptry ID fields: ${rm_empty_id}; Removing empty fields: ${rm_empty}; Trim string values: ${trim_values}; Convert true/false string values to boolean: ${bool_tf_str}`); + } + } + if (log_lvl > 1) { + console.log('Form Data:'); + console.log(form_data); + } + + // const data_obj: any = {}; // future TS + let data_obj = {}; + for (let field of form_data) { + let [obj_prop_name, obj_prop_value] = field; + if (log_lvl > 1) { + console.log(`${obj_prop_name}: ${obj_prop_value} type=${typeof obj_prop_value}`); + } + + // Trim string values if needed + if (trim_values && typeof obj_prop_value === 'string') { + if (log_lvl && obj_prop_value.trim() != obj_prop_value) { + console.log('Trimming string value!'); + obj_prop_value = obj_prop_value.trim(); + } + } + + // Convert string to boolean if needed + if (bool_tf_str && typeof obj_prop_value === 'string') { + // console.log('Flag set for converting true/false string values to boolean!'); + + if (obj_prop_value.toLowerCase() === 'true') { + if (log_lvl) { + console.log('Converting string to boolean value: true'); + } + obj_prop_value = true; + } else if (obj_prop_value.toLowerCase() === 'false') { + if (log_lvl) { + console.log('Converting string to boolean value: false'); + } + obj_prop_value = false; + } + } + + if (prefix && obj_prop_name.startsWith(prefix)) { // Prefix set + // if (obj_prop_name.startsWith(prefix)) { + obj_prop_name = obj_prop_name.replace(prefix, ''); + if (log_lvl) { + console.log(`Checking: (${prefix})${obj_prop_name} value=${obj_prop_value}`); + } + if (rm_empty_id && obj_prop_name.endsWith('id_random') && !obj_prop_value) { + if (log_lvl) { + console.log(`Match but empty *_id_random. Ignoring/removing: ${obj_prop_name}`); + } + } else if (rm_empty && !obj_prop_value) { + if (log_lvl) { + console.log(`Match but empty. Ignoring/removing: ${obj_prop_name}`); + } + } else { + if (log_lvl) { + console.log(`Match: ${prefix})${obj_prop_name} value=${obj_prop_value}`); + } + data_obj[obj_prop_name] = obj_prop_value; + } + } else if (prefix && !obj_prop_name.startsWith(prefix)) { // Prefix set + if (log_lvl > 1) { + console.log('Did not start with prefix. Ignoring'); + } + } else { // No prefix set + if (log_lvl) { + console.log(`Checking: ${obj_prop_name} value=${obj_prop_value}`); + } + if (rm_empty_id && obj_prop_name.endsWith('id_random') && !obj_prop_value) { + if (log_lvl > 1) { + console.log(`Match but empty *_id_random. Ignoring/removing: ${obj_prop_name}`); + } + } else if (rm_empty && !obj_prop_value) { + if (log_lvl > 1) { + console.log(`Match but empty. Ignoring/removing: ${obj_prop_name}`); + } + } else { + if (log_lvl > 1) { + console.log(`Match: ${obj_prop_name} value=${obj_prop_value}`); + } + data_obj[obj_prop_name] = obj_prop_value; + } + + } + } + if (log_lvl > 1) { + console.log(data_obj); + } + return data_obj; +} + + + + export let ae_util = { iso_datetime_formatter: iso_datetime_formatter, + extract_prefixed_form_data: extract_prefixed_form_data, }; // export default ae_util; \ No newline at end of file diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index dd7b7cd7..66ca74a9 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -53,12 +53,10 @@ type key_val = { import { api } from '$lib/api'; import { ae_loc, ae_sess, ae_api, slct, slct_trigger } from '$lib/ae_stores'; -console.log(api); +// console.log(api); console.log($ae_loc, $ae_sess, $ae_api); -import Edit_sponsorship_obj from './sponsorships/10_edit__sponsorship_obj.svelte'; - // const ae_loc_test_store: Writable = localStorageStore('ae_loc_test', {'test': 'This is a test'}); // // Subscribe to the store // ae_loc_test_store.subscribe(() => {}); @@ -81,7 +79,7 @@ let get_ds_hub_site_footer_promise = handle_get_data_store_obj_w_code({code: 'hu async function handle_get_data_store_obj_w_code({code, data_type='text'}) { - console.log('*** handle_get_data_store_obj_w_code() ***'); + console.log(`*** handle_get_data_store_obj_w_code() *** code=${code}`); // let get_item_result = window.localStorage.getItem(code); // localStorage.getItem(code); diff --git a/src/routes/sponsorships/+layout.ts b/src/routes/sponsorships/+layout.ts index d0ea0362..e3afca21 100644 --- a/src/routes/sponsorships/+layout.ts +++ b/src/routes/sponsorships/+layout.ts @@ -1,8 +1,8 @@ /** @type {import('./$types').LayoutLoad} */ export function load({ params, url }) { // route - console.log(`page data - params:`, params); - // console.log(`page data - route:`, route); - console.log(`page data - url:`, url); + console.log(`Svelte Sponsorships layout.ts data = params:`, params); + // console.log(`Svelte Sponsorships layout.ts data = route:`, route); + console.log(`Svelte Sponsorships layout.ts data = url:`, url); let data_struct = { params: params, diff --git a/src/routes/sponsorships/+page.svelte b/src/routes/sponsorships/+page.svelte index d3bae34c..f3fe1e9c 100644 --- a/src/routes/sponsorships/+page.svelte +++ b/src/routes/sponsorships/+page.svelte @@ -20,9 +20,6 @@ import { ae_loc, ae_sess, ae_api, slct, slct_trigger } from '$lib/ae_stores'; // import Edit_sponsorship_obj from './10_edit__sponsorship_obj.svelte'; import Edit_modal_sponsorship_obj from './10_edit_modal__sponsorship_obj.svelte'; import List_sponsorship_obj from './10_list__sponsorship_obj.svelte'; -import View_sponsorship_obj from './10_view__sponsorship_obj.svelte'; - - import View_modal_sponsorship_obj from './10_view_modal__sponsorship_obj.svelte'; const modalComponentViewSponsorshipObj: ModalComponent = { ref: View_modal_sponsorship_obj }; @@ -43,7 +40,7 @@ type key_val = { }; export let data; -console.log(`page data:`, data); +// console.log(`Svelte Sponsorships page data:`, data); let ae_account_obj_get_promise; let ae_sponsorship_obj_li_get_promise; @@ -59,51 +56,51 @@ onMount(() => { if ($ae_loc.account_id) { $slct.account_id = $ae_loc.account_id; - // handle_load_ae_account_id_obj({account_id: $slct.account_id, try_cache: false}); - handle_load_ae_sponsorship_obj_li({account_id: $slct.account_id, try_cache: false}); + // handle_load_ae_obj_id__account({account_id: $slct.account_id, try_cache: false}); + handle_load_ae_obj_li__sponsorship({account_id: $slct.account_id, try_cache: false}); } -async function handle_load_ae_account_id_obj({account_id, try_cache=false}) { - console.log('*** handle_load_account_id_obj() ***'); +// async function handle_load_ae_obj_id__account({account_id, try_cache=false}) { +// console.log('*** handle_load_ae_obj_id__account() ***'); - let params = {}; +// let params = {}; - $ae_loc.hub.account_id_qry_status = 'loading'; - ae_account_obj_get_promise = api.get_ae_obj_id_crud({ - api_cfg: $ae_api, - obj_type: 'account', - obj_id: account_id, - use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. - use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. - params: params, - log_lvl: 0 - }) - .then(function (account_obj_get_result) { - if (account_obj_get_result) { - $slct.account_obj = account_obj_get_result; - console.log(`account object:`, $slct.account_obj); - } +// $ae_loc.hub.account_id_qry_status = 'loading'; +// ae_account_obj_get_promise = api.get_ae_obj_id_crud({ +// api_cfg: $ae_api, +// obj_type: 'account', +// obj_id: account_id, +// use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. +// use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. +// params: params, +// log_lvl: 0 +// }) +// .then(function (account_obj_get_result) { +// if (account_obj_get_result) { +// $slct.account_obj = account_obj_get_result; +// console.log(`account object:`, $slct.account_obj); +// } - // Auto show the selected account ID - // Is this pushState needed here? - // Set the URL param "account_id" to the current account ID. - const url = new URL(location); - url.searchParams.set('account_id', $slct.account_id); - history.pushState({}, '', url); +// // Auto show the selected account ID +// // Is this pushState needed here? +// // Set the URL param "account_id" to the current account ID. +// const url = new URL(location); +// url.searchParams.set('account_id', $slct.account_id); +// history.pushState({}, '', url); - // Is this postMessage needed here? - let message = {'account_id': $slct.account_id}; - window.parent.postMessage(message, "*"); - }) - .catch(function (error) { - console.log('No results returned or failed.', error); - }); +// // Is this postMessage needed here? +// let message = {'account_id': $slct.account_id}; +// window.parent.postMessage(message, "*"); +// }) +// .catch(function (error) { +// console.log('No results returned or failed.', error); +// }); - return ae_account_obj_get_promise; -} +// return ae_account_obj_get_promise; +// } -async function handle_load_ae_sponsorship_obj_li({account_id, try_cache=true}) { - console.log('*** handle_load_ae_sponsorship_obj_li() ***'); +async function handle_load_ae_obj_li__sponsorship({account_id, try_cache=true}) { + console.log('*** handle_load_ae_obj_li__sponsorship() ***'); // console.log($ae_loc.mod.sponsorships); // let fulltext_search_qry_str = ($ae_loc.mod.sponsorships && $ae_loc.mod.sponsorships.fulltext_search_qry_str ? $ae_loc.mod.sponsorships.fulltext_search_qry_str : ''); @@ -182,18 +179,76 @@ async function handle_load_ae_sponsorship_obj_li({account_id, try_cache=true}) { return ae_sponsorship_obj_li_get_promise; } -$: if ($slct_trigger == 'load__sponsorship_obj' && $slct.sponsorship_id) { - console.log('Selected Sponsorship ID:', $slct.sponsorship_id); - console.log('Selected Sponsorship Object:', $slct.sponsorship_obj); + +// Load the Sponsorship Cfg Obj with ID based on the URL param. +$slct.sponsorship_cfg_id = data.url.searchParams.get('sponsorship_cfg_id'); +$slct_trigger = 'load__sponsorship_cfg_obj'; + +$: if ($slct_trigger == 'load__sponsorship_cfg_obj' && $slct.sponsorship_cfg_id) { + console.log('Selected Sponsorship Cfg ID:', $slct.sponsorship_cfg_id); $slct_trigger = null; - handle_load_ae_sponsorship_id_obj({sponsorship_id: $slct.sponsorship_id, try_cache: false}); + handle_load_ae_obj_id__sponsorship_cfg({sponsorship_cfg_id: $slct.sponsorship_cfg_id, try_cache: false}); +} + +let ae_sponsorship_cfg_obj_get_promise; + +async function handle_load_ae_obj_id__sponsorship_cfg({sponsorship_cfg_id, try_cache=false}) { + console.log(`*** handle_load_ae_obj_id__sponsorship_cfg() *** sponsorship_cfg_id=${sponsorship_cfg_id}`); + + let params = {}; + + // $ae_loc.hub.sponsorship_cfg_id_qry_status = 'loading'; + ae_sponsorship_cfg_obj_get_promise = api.get_ae_obj_id_crud({ + api_cfg: $ae_api, + obj_type: 'sponsorship_cfg', + obj_id: sponsorship_cfg_id, + use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. + use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. + params: params, + log_lvl: 1 + }) + .then(function (sponsorship_cfg_obj_get_result) { + if (sponsorship_cfg_obj_get_result) { + $slct.sponsorship_cfg_obj = sponsorship_cfg_obj_get_result; + console.log(`sponsorship object:`, $slct.sponsorship_cfg_obj); + } + + // Auto show the selected sponsorship ID + // Is this pushState needed here? + // Set the URL param "sponsorship_cfg_id" to the current sponsorship ID. + // const url = new URL(location); + // url.searchParams.set('sponsorship_cfg_id', $slct.sponsorship_cfg_id); + // history.pushState({}, '', url); + + // Is this postMessage needed here? + // let message = {'sponsorship_cfg_id': $slct.sponsorship_cfg_id}; + // window.parent.postMessage(message, "*"); + + // modalStore.trigger(modal_view__sponsorship_cfg_obj); + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }); + + return ae_sponsorship_cfg_obj_get_promise; +} + + +// Load the Sponsorship Obj with ID based on the URL param. +$: if ($slct_trigger == 'load__sponsorship_obj' && $slct.sponsorship_id) { + console.log('Selected Sponsorship ID:', $slct.sponsorship_id); + + $slct_trigger = null; + + handle_load_ae_obj_id__sponsorship({sponsorship_id: $slct.sponsorship_id, try_cache: false}); } let ae_sponsorship_obj_get_promise; -async function handle_load_ae_sponsorship_id_obj({sponsorship_id, try_cache=false}) { - console.log('*** handle_load_sponsorship_id_obj() ***'); + +async function handle_load_ae_obj_id__sponsorship({sponsorship_id, try_cache=false}) { + console.log(`*** handle_load_ae_obj_id__sponsorship() *** sponsorship_id=${sponsorship_id}`); let params = {}; @@ -205,7 +260,7 @@ async function handle_load_ae_sponsorship_id_obj({sponsorship_id, try_cache=fals use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. params: params, - log_lvl: 2 + log_lvl: 1 }) .then(function (sponsorship_obj_get_result) { if (sponsorship_obj_get_result) { diff --git a/src/routes/sponsorships/10_edit_modal__sponsorship_obj.svelte b/src/routes/sponsorships/10_edit_modal__sponsorship_obj.svelte index 6186e036..da1e1286 100644 --- a/src/routes/sponsorships/10_edit_modal__sponsorship_obj.svelte +++ b/src/routes/sponsorships/10_edit_modal__sponsorship_obj.svelte @@ -1,6 +1,8 @@ @@ -57,7 +365,6 @@ let tab_set = $store_current_tab;
+ + + + + + + {/if} - + {/if} diff --git a/src/routes/sponsorships/[slug]/+page.svelte b/src/routes/sponsorships/[slug]/+page.svelte index 7a5133e9..ffc1522d 100644 --- a/src/routes/sponsorships/[slug]/+page.svelte +++ b/src/routes/sponsorships/[slug]/+page.svelte @@ -1,6 +1,6 @@ diff --git a/src/routes/testing/+page.svelte b/src/routes/testing/+page.svelte index 922b16cc..e77bed58 100644 --- a/src/routes/testing/+page.svelte +++ b/src/routes/testing/+page.svelte @@ -26,12 +26,12 @@ onMount(() => { if ($ae_loc.account_id) { $slct.account_id = $ae_loc.account_id; - // handle_load_ae_account_id_obj({account_id: $slct.account_id, try_cache: false}); + // handle_load_ae_account_obj_id({account_id: $slct.account_id, try_cache: false}); handle_load_ae_sponsorship_obj_li({account_id: $slct.account_id, try_cache: false}); } -async function handle_load_ae_account_id_obj({account_id, try_cache=false}) { - console.log('*** handle_load_account_id_obj() ***'); +async function handle_load_ae_account_obj_id({account_id, try_cache=false}) { + console.log('*** handle_load_account_obj_id() ***'); let params = {};