diff --git a/src/lib/ae_posts/ae_posts__post.ts b/src/lib/ae_posts/ae_posts__post.ts index 4e1ade2f..50448abc 100644 --- a/src/lib/ae_posts/ae_posts__post.ts +++ b/src/lib/ae_posts/ae_posts__post.ts @@ -201,8 +201,8 @@ export async function create_ae_obj__post( api_cfg, account_id, data_kv, - params={}, - log_lvl=0 + params = {}, + log_lvl = 0 }: { api_cfg: any, account_id: string, @@ -589,6 +589,8 @@ export function db_save_ae_obj_li__post( account_id: obj.account_id_random, + external_person_id: obj.external_person_id, + topic_id: obj.topic_id, topic: obj.topic, topic_name: obj.topic_name, diff --git a/src/lib/ae_posts/ae_posts__post_comment.ts b/src/lib/ae_posts/ae_posts__post_comment.ts index 9033556a..f56976a8 100644 --- a/src/lib/ae_posts/ae_posts__post_comment.ts +++ b/src/lib/ae_posts/ae_posts__post_comment.ts @@ -269,6 +269,8 @@ export function db_save_ae_obj_li__post_comment( post_id: obj.post_id_random, + external_person_id: obj.external_person_id, + // name: obj.name, // summary: obj.summary, title: obj.title, diff --git a/src/lib/ae_utils/ae_utils__extract_prefixed_form_data.ts b/src/lib/ae_utils/ae_utils__extract_prefixed_form_data.ts index fa463cfd..0627b35e 100644 --- a/src/lib/ae_utils/ae_utils__extract_prefixed_form_data.ts +++ b/src/lib/ae_utils/ae_utils__extract_prefixed_form_data.ts @@ -8,6 +8,7 @@ type key_val = { * 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. + * REMINDER: An unchecked checkbox will not be sent in the form data. This is a browser thing. * Updated 2023-12-22 */ export let extract_prefixed_form_data = function extract_prefixed_form_data( diff --git a/src/lib/db_posts.ts b/src/lib/db_posts.ts index 0ad37bca..944e1790 100644 --- a/src/lib/db_posts.ts +++ b/src/lib/db_posts.ts @@ -62,6 +62,8 @@ export interface Post_Comment { post_id: string; // post_id_random: string; + external_person_id?: null|string; // For IDAA this is the Novi UUID + // name: null|string; // summary?: null|string; title: null|string; diff --git a/src/lib/element_tiptap_editor.svelte b/src/lib/element_tiptap_editor.svelte index fb79d30f..71f35862 100644 --- a/src/lib/element_tiptap_editor.svelte +++ b/src/lib/element_tiptap_editor.svelte @@ -132,6 +132,9 @@ function getContent() { } return ''; } + +let mouse_entered_timer: any; +let mouse_entered_wait: number = 2500; @@ -145,11 +148,19 @@ function getContent() { } }} on:mouseleave={() => { - if (default_minimal) { - show_menu = false; - } + mouse_entered_timer = setTimeout(() => { + if (default_minimal) { + show_menu = false; + } + }, mouse_entered_wait); + + // if (default_minimal) { + // show_menu = false; + // } }} on:mouseenter={() => { + clearTimeout(mouse_entered_timer); + if (default_minimal) { show_menu = true; } @@ -164,7 +175,7 @@ function getContent() { {#if editor && show_menu}
- {#await prom_api__post_comment_obj} + {#await prom_api__post_comment_obj_v2}
Saving...
{:then} - {#if prom_api__post_comment_obj} + {#if prom_api__post_comment_obj_v2} {:else} @@ -198,60 +318,117 @@ async function handle_delete_post_comment_obj({post_id, method}: key_val) { {$idaa_loc.bb.show__admin_options ? 'Hide' : 'Show'} Admin +
+ >

Admin Options

- + +
+ Hide +
+ + +
+
+ + +
+
- +
+ Priority +
+ + +
+
+ + +
+
+
- + + - + + {#if $ae_loc.administrator_access} - + +
+ Enable +
+ + +
+
+ + +
+
+
{/if}
- {#if $ae_loc.trusted_access} +
{/if} @@ -274,7 +451,7 @@ async function handle_delete_post_comment_obj({post_id, method}: key_val) { disabled={(disable_submit_btn)} class="ae_btn btn_primary btn btn-primary variant-ghost-primary hover:variant-filled-primary transition" > - {#await prom_api__post_comment_obj} + {#await prom_api__post_comment_obj_v2} Saving {:then} Save @@ -290,7 +467,7 @@ async function handle_delete_post_comment_obj({post_id, method}: key_val) { }} class="ae_btn btn_primary btn btn-primary variant-ghost-primary hover:variant-filled-primary transition" > - {#await prom_api__post_comment_obj} + {#await prom_api__post_comment_obj_v2} Saving {:then} Save New Event diff --git a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte index 48c12998..3aa19338 100644 --- a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte @@ -14,24 +14,151 @@ import Tiptap_editor from '$lib/element_tiptap_editor.svelte'; export let lq__post_obj: any; -let prom_api__post_obj: any; +let prom_api__post_obj_v2: any; -let disable_submit_btn = true; +let disable_submit_btn = false; async function handle_submit_form(event: any) { console.log('*** handle_submit_form() ***'); + if (log_lvl > 1) { + console.log(event.target); + } disable_submit_btn = true; let form_data = new FormData(event.target); - console.log(form_data); + if (log_lvl) { + console.log(form_data); + } - disable_submit_btn = false; + // Form Post object data incoming + let post_di = ae_util.extract_prefixed_form_data({prefix: null, form_data: form_data, trim_values: true, bool_tf_str: true, log_lvl: 2}); + // console.log(post_di); - return true; + // Form Post object data outgoing + let post_do: key_val = {}; + + if (!$idaa_slct.post_id) { + post_do['account_id_random'] = $ae_loc.account_id; + post_do['enable'] = true; + } + + post_do['title'] = post_di.title; + + // Check if the content_new_html exists and is a string + if (typeof $idaa_slct.post_obj.content_new_html === 'string') { + console.log('New content is a string'); + post_do['content'] = $idaa_slct.post_obj.content_new_html; + } else { + console.log('New content is not a string. Do nothing.'); + // post_do['content'] = event_meeting_fd.content; + } + + // Change this to a string later? Or use the group field instead? + if (post_di.topic_id) { + post_do['topic_id'] = Number(post_di.topic_id); + } else { + post_do['topic_id'] = null; + } + + post_do['anonymous'] = post_di.anonymous; + + post_do['external_person_id'] = post_di.external_person_id; + post_do['full_name'] = post_di.full_name; + post_do['email'] = post_di.email; + + post_do['hide'] = !!post_di.hide; + post_do['priority'] = !!post_di.priority; + if (post_di.sort) { + post_do['sort'] = Number(post_di.sort); + } else { + post_do['sort'] = null; + } + if (post_di.group) { + post_do['group'] = post_di.group; + } else { + post_do['group'] = null; + } + + // Check if the enable exists and is a string + console.log(`post_di.enable = ${post_di.enable}`); + // if (typeof post_di.enable !== 'undefined') { + post_do['enable'] = !!post_di.enable; + // } + + // Check if the notes_new_html exists and is a string + if (typeof $idaa_slct.post_obj.notes_new_html === 'string') { + console.log('New notes is a string'); + post_do['notes'] = $idaa_slct.post_obj.notes_new_html; + } else { + console.log('New notes is not a string. Do nothing.'); + // post_do['notes'] = event_meeting_fd.notes; + } + + console.log(post_do); + + if (!$idaa_slct.post_id) { + prom_api__post_obj_v2 = posts_func.create_ae_obj__post({ + api_cfg: $ae_api, + account_id: $ae_loc.account_id, + data_kv: post_do, + log_lvl: log_lvl + }) + .then(function (post_obj_create_result) { + if (!post_obj_create_result) { + console.log('The result was null or false.'); + return false; + } + + $idaa_slct.post_id = post_obj_create_result.obj_id_random; + + return post_obj_create_result; + }) + .catch(function (error) { + console.log('Something went wrong.'); + console.log(error); + return false; + }) + .finally(() => { + disable_submit_btn = false; + $idaa_sess.bb.show__inline_edit__post_obj = false; + }); + + return prom_api__post_obj_v2; + } else { + prom_api__post_obj_v2 = posts_func.update_ae_obj__post({ + api_cfg: $ae_api, + post_id: $idaa_slct.post_id, + data_kv: post_do, + log_lvl: log_lvl + }) + .then(function (post_obj_update_result) { + if (!post_obj_update_result) { + console.log('The result was null or false.'); + return false; + } + + return post_obj_update_result; + }) + .catch(function (error) { + console.log('Something went wrong.'); + console.log(error); + return false; + }) + .finally(() => { + // We need to do this since the post has changed and the idaa_slct object does automatically update (yet...???). + $idaa_slct.post_obj = $lq__post_obj; + disable_submit_btn = false; + $idaa_sess.bb.show__inline_edit__post_obj = false; + }); + + return prom_api__post_obj_v2; + } } + + async function handle_delete_post_obj({post_id, method}: key_val) { console.log('*** handle_delete_post_obj() ***'); @@ -43,17 +170,17 @@ async function handle_delete_post_obj({post_id, method}: key_val) {
- {#await prom_api__post_obj} + {#await prom_api__post_obj_v2}
Saving...
{:then} - {#if prom_api__post_obj} + {#if prom_api__post_obj_v2} {:else} @@ -74,12 +201,14 @@ async function handle_delete_post_obj({post_id, method}: key_val) { + [{$idaa_slct.post_id}] +