From 2d047f5a10cb3f61248fe16b91aee04ccb45419d Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Fri, 1 Nov 2024 17:52:39 -0400 Subject: [PATCH] Now able to save the HTML text from tip tap element. --- src/lib/element_tiptap_editor.svelte | 25 ++- .../(idaa)/recovery_meetings/+page.svelte | 17 ++ .../ae_idaa_comp__event_obj_id_edit.svelte | 165 +++++++----------- 3 files changed, 104 insertions(+), 103 deletions(-) diff --git a/src/lib/element_tiptap_editor.svelte b/src/lib/element_tiptap_editor.svelte index b4765428..8436e574 100644 --- a/src/lib/element_tiptap_editor.svelte +++ b/src/lib/element_tiptap_editor.svelte @@ -81,7 +81,7 @@ if (show_button_kv) { show_button_kv = show_button_kv_defaults; } -export let new_json = editor?.getJSON(); +// export let new_json = editor?.getJSON(); export let new_html: string = ''; onMount(() => { @@ -96,8 +96,22 @@ onMount(() => { onTransaction: () => { // force re-render so `editor.isActive` works as expected editor = editor; - new_html = editor.getHTML(); + + let updated_html = editor.getHTML(); + if (updated_html == '

') { + new_html = ''; + } else { + new_html = updated_html; + } }, + onUpdate: ({ editor }) => { + let updated_html = editor.getHTML(); + if (updated_html == '

') { + new_html = ''; + } else { + new_html = updated_html; + } + } }); }); @@ -106,6 +120,13 @@ onDestroy(() => { editor.destroy(); } }); + +function getContent() { + if (editor) { + return editor.getHTML(); + } + return ''; +} diff --git a/src/routes/idaa/(idaa)/recovery_meetings/+page.svelte b/src/routes/idaa/(idaa)/recovery_meetings/+page.svelte index dc62dc50..a788eba4 100644 --- a/src/routes/idaa/(idaa)/recovery_meetings/+page.svelte +++ b/src/routes/idaa/(idaa)/recovery_meetings/+page.svelte @@ -142,6 +142,23 @@ $: lq_new__event_obj_li = liveQuery(async () => { lq__event_obj={lq__event_obj} /> + + +
+ +
+
+ diff --git a/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte b/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte index ca988593..11377876 100644 --- a/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte @@ -226,69 +226,19 @@ if ($ae_loc.lu_country_subdivision_list && $ae_loc.lu_country_subdivision_list.l } -onMount(() => { - console.log('** Component Mounted: ** Edit - Event Obj'); - tinymce_remove(); // This seems to fix rendering issues - tinymce_init(); -}); +// onMount(() => { +// console.log('** Component Mounted: ** Edit - Event Obj'); +// }); -onDestroy(() => { - console.log('** Component Destroyed: ** Edit - Event Obj'); - tinymce_remove(); // This seems like the right thing to do -}); +// onDestroy(() => { +// console.log('** Component Destroyed: ** Edit - Event Obj'); +// }); // afterUpdate(() => { // console.log('** Component Updated: ** Edit - Event Obj'); -// tinymce_init(); // }); -function tinymce_init() { - // REFERENCE: https://www.tiny.cloud/docs/tinymce/6/basic-setup/ - // plugins: [ - // 'advlist', 'autolink', 'link', 'image', 'lists', 'charmap', 'preview', 'anchor', 'pagebreak', - // 'searchreplace', 'wordcount', 'visualblocks', 'visualchars', 'code', 'fullscreen', 'insertdatetime', - // 'media', 'table', 'emoticons', 'template', 'help' - // ], - // 'undo redo | styles | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent' - // // NOTE: Basic version of the TinyMCE editor - // tinymce.init({ - // selector: '.tinymce_editor.editor_basic', - // // width: 600, - // height: 400, - // plugins: [ 'lists', 'code', 'help' ], - // menubar: false, - // toolbar: 'undo redo | styles | bold italic | alignleft aligncenter | bullist numlist outdent indent | code | help', - // }); - - // // NOTE: Minimal version of the TinyMCE editor - // tinymce.init({ - // selector: '.tinymce_editor.editor_basic_200', - // // width: 600, - // height: 200, - // plugins: [ 'lists', 'code', 'help' ], - // menubar: false, - // toolbar: 'undo redo | styles | bold italic | alignleft aligncenter | bullist numlist outdent indent | code | help', - // }); - - // // NOTE: Less is more version of the TinyMCE editor - // tinymce.init({ - // selector: '.tinymce_editor.editor_less_100', - // // width: 600, - // height: 100, - // // plugins: [ 'lists', 'code', 'help' ], - // menubar: false, - // toolbar: false, - // statusbar: false, - // }); - -} - -function tinymce_remove() { - // tinymce.remove('.tinymce_editor.editor_basic'); - // tinymce.remove('.tinymce_editor.editor_basic_200'); - // tinymce.remove('.tinymce_editor.editor_less_100'); -} $: if ($idaa_slct.event_obj) { @@ -320,17 +270,15 @@ async function handle_submit_form(event: any) { event_data['name'] = event_meeting_data.name; - if (event_meeting_data.description) { - event_data['description'] = event_meeting_data.description; + // Check if the description_new_html exists and is a string + if (typeof $idaa_slct.event_obj.description_new_html === 'string') { + console.log('New description is a string'); + event_data['description'] = $idaa_slct.event_obj.description_new_html; } else { - event_data['description'] = null; + console.log('New description is not a string. Do nothing.'); + // event_data['description'] = event_meeting_data.description; } - // if (tinyMCE.get('description')) { - // event_data['description'] = tinyMCE.get('description').getContent(); - // } else { - // event_data['description'] = event_meeting_data.description; - // } event_data['type'] = event_meeting_data.type; event_data['physical'] = !!event_meeting_data.physical; event_data['virtual'] = !!event_meeting_data.virtual; @@ -360,22 +308,24 @@ async function handle_submit_form(event: any) { } // event_data['location_address_json'] = address; - // if (tinyMCE.get('location_text')) { - // event_data['location_text'] = tinyMCE.get('location_text').getContent(); - // } else { - // event_data['location_text'] = event_meeting_data.location_text; - // } + // Check if the location_text_new_html exists and is a string + if (typeof $idaa_slct.event_obj.location_text_new_html === 'string') { + event_data['location_text'] = $idaa_slct.event_obj.location_text_new_html; + } else { + console.log('New location text is not a string. Do nothing.'); + } event_data['attend_url'] = event_meeting_data.attend_url; event_data['attend_url_passcode'] = event_meeting_data.attend_url_passcode; event_data['attend_phone'] = event_meeting_data.attend_phone; event_data['attend_phone_passcode'] = event_meeting_data.attend_phone_passcode; - // if (tinyMCE.get('attend_text')) { - // event_data['attend_text'] = tinyMCE.get('attend_text').getContent(); - // } else { - // event_data['attend_text'] = event_meeting_data.attend_text; - // } + // Check if the attend_text_new_html exists and is a string + if (typeof $idaa_slct.event_obj.attend_text_new_html === 'string') { + event_data['attend_text'] = $idaa_slct.event_obj.attend_text_new_html; + } else { + console.log('New attend text is not a string. Do nothing.'); + } event_data['timezone'] = event_meeting_data.timezone; @@ -405,11 +355,12 @@ async function handle_submit_form(event: any) { event_data['recurring_end_time'] = event_meeting_data.recurring_end_time; } - // if (tinyMCE.get('recurring_text')) { - // event_data['recurring_text'] = tinyMCE.get('recurring_text').getContent(); - // } else { - // event_data['recurring_text'] = event_meeting_data.recurring_text; - // } + // Check if the recurring_text_new_html exists and is a string + if (typeof $idaa_slct.event_obj.recurring_text_new_html === 'string') { + event_data['recurring_text'] = $idaa_slct.event_obj.recurring_text_new_html; + } else { + console.log('New recurring text is not a string. Do nothing.'); + } console.log(event_data['recurring_text']); if (!event_data['recurring_text'] || event_data['recurring_text'].includes('*gen*')) { @@ -491,11 +442,12 @@ async function handle_submit_form(event: any) { event_data['enable'] = !!event_meeting_data.enable; } - // if (tinyMCE.get('notes')) { - // event_data['notes'] = tinyMCE.get('notes').getContent(); - // } else { - // event_data['notes'] = event_meeting_data.notes; - // } + // Check if the notes_new_html exists and is a string + if (typeof $idaa_slct.event_obj.notes_new_html === 'string') { + event_data['notes'] = $idaa_slct.event_obj.notes_new_html; + } else { + console.log('New notes is not a string. Do nothing.'); + } console.log(event_data); @@ -665,6 +617,18 @@ async function handle_delete_event_obj({event_id, method='disable'}) { {/if} {/await} +
+ {#if $idaa_slct.event_id} + + {/if} +
+ @@ -688,7 +652,7 @@ async function handle_delete_event_obj({event_id, method='disable'}) { - {#if + Save? - {/if} + {/if} --> @@ -843,7 +806,7 @@ async function handle_delete_event_obj({event_id, method='disable'}) { /> - {#if +
- {#if + @@ -985,7 +948,7 @@ async function handle_delete_event_obj({event_id, method='disable'}) {
- {#if ( $ae_loc.administrator_access || $lq__event_obj && ($lq__event_obj?.show_recurring_text || ($lq__event_obj?.recurring_text && !$lq__event_obj?.recurring_text.includes('*gen*'))) )} + {#if ( $ae_loc.administrator_access || $lq__event_obj && ($idaa_slct.event_obj?.show_recurring_text || ($lq__event_obj?.recurring_text && !$lq__event_obj?.recurring_text.includes('*gen*'))) )}

Please only use the text box for additional information if the options above do not cover your needs. This may affect how this meeting shows up in search results.

{/if} - {#if ( $ae_loc.administrator_access || $lq__event_obj && ($lq__event_obj?.show_recurring_text || ($lq__event_obj?.recurring_text && !$lq__event_obj?.recurring_text.includes('*gen*'))) )} + {#if ( $ae_loc.administrator_access || $lq__event_obj && ($idaa_slct.event_obj?.show_recurring_text || ($lq__event_obj?.recurring_text && !$lq__event_obj?.recurring_text.includes('*gen*'))) )}