refactor: Rename CodeMirror wrapper and fix editor buttons

Renamed Tiptap_editor to CodeMirror_wrapper and updated all usages. Renamed the wrapper file to element_codemirror_editor_wrapper.svelte. Fixed a TypeError in the CodeMirror editor buttons by using EditorSelection.range() to correctly create selection ranges.
This commit is contained in:
Scott Idem
2025-11-18 14:14:24 -05:00
parent 95412dd0ad
commit 691b20fd54
8 changed files with 862 additions and 861 deletions

View File

@@ -131,6 +131,7 @@ export async function ensureCodeMirrorModules(): Promise<CMCache> {
placeholderExt: viewMod.placeholder,
EditorState: stateMod.EditorState,
EditorSelection: stateMod.EditorSelection,
EditorState_allowMultipleSelections: stateMod.EditorState.allowMultipleSelections,
EditorState_readOnly: stateMod.EditorState.readOnly,

View File

@@ -1,130 +1,131 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import { browser } from '$app/environment';
import { ensureCodeMirrorModules } from './codemirror_modules';
import { onMount, onDestroy } from 'svelte';
import { browser } from '$app/environment';
import { ensureCodeMirrorModules } from './codemirror_modules';
export let content: string = '';
export let placeholder: string = 'Start typing...';
export let content: string = '';
export let placeholder: string = 'Start typing...';
let editor_container: HTMLDivElement;
let editor_view: any;
let editor_container: HTMLDivElement;
let editor_view: any;
let cm: any; // Declare cm at the top level
async function createEditor() {
if (!browser) return;
const cm = await ensureCodeMirrorModules();
if (!cm) return;
async function createEditor() {
if (!browser) return;
cm = await ensureCodeMirrorModules(); // Assign to the top-level cm
if (!cm) return;
// If an existing instance exists (HMR / remount), destroy it first
if (editor_view && typeof editor_view.destroy === 'function') {
try { editor_view.destroy(); } catch (e) { /* ignore */ }
editor_view = null;
}
// If an existing instance exists (HMR / remount), destroy it first
if (editor_view && typeof editor_view.destroy === 'function') {
try { editor_view.destroy(); } catch (e) { /* ignore */ }
editor_view = null;
}
// Build extensions defensively
const extensions = [
cm.lineNumbers(),
cm.highlightSpecialChars(),
cm.history(),
cm.foldGutter(),
cm.drawSelection(),
cm.dropCursor(),
cm.EditorState_allowMultipleSelections.of(true),
cm.indentOnInput(),
cm.bracketMatching(),
cm.closeBrackets(),
cm.autocompletion(),
cm.rectangularSelection(),
cm.crosshairCursor(),
cm.highlightActiveLine(),
cm.highlightActiveLineGutter(),
cm.EditorView_lineWrapping,
cm.keymap.of([
...cm.defaultKeymap,
...cm.searchKeymap,
...cm.historyKeymap,
...cm.foldKeymap,
...cm.completionKeymap,
...cm.lintKeymap
]),
cm.markdown ? cm.markdown({ base: cm.markdownLanguage }) : null,
cm.EditorView && cm.EditorView.updateListener ? cm.EditorView.updateListener.of((update: any) => {
if (update.docChanged) content = update.state.doc.toString();
}) : null
].filter(Boolean);
// Build extensions defensively
const extensions = [
cm.lineNumbers(),
cm.highlightSpecialChars(),
cm.history(),
cm.foldGutter(),
cm.drawSelection(),
cm.dropCursor(),
cm.EditorState_allowMultipleSelections.of(true),
cm.indentOnInput(),
cm.bracketMatching(),
cm.closeBrackets(),
cm.autocompletion(),
cm.rectangularSelection(),
cm.crosshairCursor(),
cm.highlightActiveLine(),
cm.highlightActiveLineGutter(),
cm.EditorView_lineWrapping,
cm.keymap.of([
...cm.defaultKeymap,
...cm.searchKeymap,
...cm.historyKeymap,
...cm.foldKeymap,
...cm.completionKeymap,
...cm.lintKeymap
]),
cm.markdown ? cm.markdown({ base: cm.markdownLanguage }) : null,
cm.EditorView && cm.EditorView.updateListener ? cm.EditorView.updateListener.of((update: any) => {
if (update.docChanged) content = update.state.doc.toString();
}) : null
].filter(Boolean);
// Create editor
editor_view = new cm.EditorView({
state: cm.EditorState.create({
doc: content ?? '',
extensions
}),
parent: editor_container
});
}
// Create editor
editor_view = new cm.EditorView({
state: cm.EditorState.create({
doc: content ?? '',
extensions
}),
parent: editor_container
});
}
onMount(async () => {
// ensure it's created only in browser and after modules resolved
await createEditor();
});
onMount(async () => {
// ensure it's created only in browser and after modules resolved
await createEditor();
});
onDestroy(() => {
if (editor_view && typeof editor_view.destroy === 'function') {
try { editor_view.destroy(); } catch (e) { /* ignore */ }
editor_view = null;
}
});
onDestroy(() => {
if (editor_view && typeof editor_view.destroy === 'function') {
try { editor_view.destroy(); } catch (e) { /* ignore */ }
editor_view = null;
}
});
// Helper functions using the live editor_view (unchanged)
const wrapSelection = (before: string, after: string = before) => {
if (!editor_view) return;
const state = editor_view.state;
const changes = state.changeByRange((range: any) => {
const isAlreadyWrapped =
state.sliceDoc(range.from - before.length, range.from) === before &&
state.sliceDoc(range.to, range.to + after.length) === after;
// Helper functions using the live editor_view (unchanged)
const wrapSelection = (before: string, after: string = before) => {
if (!editor_view) return;
const state = editor_view.state;
const changes = state.changeByRange((range: any) => {
const isAlreadyWrapped =
state.sliceDoc(range.from - before.length, range.from) === before &&
state.sliceDoc(range.to, range.to + after.length) === after;
if (isAlreadyWrapped) {
return {
changes: [
{ from: range.from - before.length, to: range.from, insert: '' },
{ from: range.to, to: range.to + after.length, insert: '' }
],
range: (state as any).constructor.range(range.from - before.length, range.to - before.length)
};
}
if (isAlreadyWrapped) {
return {
changes: [
{ from: range.from - before.length, to: range.from, insert: '' },
{ from: range.to, to: range.to + after.length, insert: '' }
],
range: cm.EditorSelection.range(range.from - before.length, range.to - before.length)
};
}
return {
changes: [
{ from: range.from, insert: before },
{ from: range.to, insert: after }
],
range: (state as any).constructor.range(range.from + before.length, range.to + before.length)
};
});
editor_view.dispatch(changes);
editor_view.focus();
};
return {
changes: [
{ from: range.from, insert: before },
{ from: range.to, insert: after }
],
range: cm.EditorSelection.range(range.from + before.length, range.to + before.length)
};
});
editor_view.dispatch(changes);
editor_view.focus();
};
const insertList = () => {
if (!editor_view) return;
const state = editor_view.state;
const changes = state.changeByRange((range: any) => {
const line = state.doc.lineAt(range.from);
return {
changes: [{ from: line.from, insert: '- ' }],
range: (state as any).constructor.range(range.from + 2, range.to + 2)
};
});
editor_view.dispatch(changes);
editor_view.focus();
};
const insertList = () => {
if (!editor_view) return;
const state = editor_view.state;
const changes = state.changeByRange((range: any) => {
const line = state.doc.lineAt(range.from);
return {
changes: [{ from: line.from, insert: '- ' }],
range: cm.EditorSelection.range(range.from + 2, range.to + 2)
};
});
editor_view.dispatch(changes);
editor_view.focus();
};
</script>
<div class="codemirror-wrapper border rounded">
<div class="toolbar p-1 bg-gray-100 border-b">
<button on:click={() => wrapSelection('**')} class="px-2 py-1 rounded hover:bg-gray-200"><b>B</b></button>
<button on:click={() => wrapSelection('*')} class="px-2 py-1 rounded hover:bg-gray-200"><i>I</i></button>
<button on:click={insertList} class="px-2 py-1 rounded hover:bg-gray-200">List</button>
<button type="button" on:click={() => wrapSelection('**')} class="px-2 py-1 rounded hover:bg-gray-200"><b>B</b></button>
<button type="button" on:click={() => wrapSelection('*')} class="px-2 py-1 rounded hover:bg-gray-200"><i>I</i></button>
<button type="button" on:click={insertList} class="px-2 py-1 rounded hover:bg-gray-200">List</button>
</div>
<div bind:this={editor_container} class="h-full min-h-[150px] overflow-auto"></div>
</div>

View File

@@ -18,7 +18,7 @@
import { idaa_loc, idaa_sess, idaa_slct } from '$lib/stores/ae_idaa_stores';
import { archives_func } from '$lib/ae_archives/ae_archives_functions';
import Tiptap_editor from '$lib/elements/element_codemirror_wrapper.svelte';
import CodeMirror_wrapper from '$lib/elements/element_codemirror_editor_wrapper.svelte';
import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte';
import Element_manage_hosted_file_li_wrap from '$lib/elements/element_manage_hosted_file_li_all.svelte';
@@ -421,12 +421,11 @@
<label for="description" class="ae_label w-full">
<span class="legend text-sm font-semibold"> Description </span>
<Tiptap_editor
bind:html_text={description_new_html}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="Your content description here..."
/>
</label>
<CodeMirror_wrapper
bind:html_text={description_new_html}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="Your content description here..."
/> </label>
</div>
<!-- <label for="content_html">Content (HTML)
@@ -909,7 +908,7 @@
<span class="legend text-sm font-semibold text-surface-600-400"
>Internal Staff Notes</span
>
<Tiptap_editor
<CodeMirror_wrapper
bind:html_text={notes_new_html}
classes="preset-tonal-surface preset-filled-surface-100-900"
placeholder="Internal notes for staff only. Not shown to the public."

View File

@@ -19,7 +19,7 @@
import { idaa_loc, idaa_sess, idaa_slct } from '$lib/stores/ae_idaa_stores';
import { archives_func } from '$lib/ae_archives/ae_archives_functions';
import Tiptap_editor from '$lib/elements/element_codemirror_wrapper.svelte';
import CodeMirror_wrapper from '$lib/elements/element_codemirror_editor_wrapper.svelte';
interface Props {
log_lvl?: number;
@@ -338,7 +338,7 @@
<label for="description" class="ae_label w-full">
<span class="legend text-sm font-semibold"> Description </span>
<Tiptap_editor
<CodeMirror_wrapper
bind:html_text={description_new_html}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="Your archive description here..."
@@ -677,7 +677,7 @@
<span class="legend text-sm font-semibold text-surface-600-400"
>Internal Staff Notes</span
>
<Tiptap_editor
<CodeMirror_wrapper
bind:html_text={notes_new_html}
classes="preset-tonal-surface preset-filled-surface-100-900"
placeholder="Internal notes for staff only. Not shown to the public."

View File

@@ -1,432 +1,432 @@
<script lang="ts">
interface Props {
log_lvl?: number;
lq__post_obj: any;
// lq__post_comment_obj: any;
// lq__post_comment_obj_li?: any;
interface Props {
log_lvl?: number;
lq__post_obj: any;
// lq__post_comment_obj: any;
// lq__post_comment_obj_li?: any;
}
let {
log_lvl = $bindable(1),
lq__post_obj
// lq__post_comment_obj,
// lq__post_comment_obj_li
}: Props = $props();
// *** Import Svelte specific
import { fade } from 'svelte/transition';
// *** Import other supporting libraries
// *** Import Aether specific variables and functions
import type { key_val } from '$lib/stores/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
// import { core_func } from '$lib/ae_core/ae_core_functions';
import { api } from '$lib/api/api';
import {
ae_snip,
ae_loc,
ae_sess,
ae_api,
ae_trig,
slct,
slct_trigger
} from '$lib/stores/ae_stores';
import { idaa_loc, idaa_sess, idaa_slct } from '$lib/stores/ae_idaa_stores';
import { posts_func } from '$lib/ae_posts/ae_posts_functions';
import CodeMirror_wrapper from '$lib/elements/element_codemirror_editor_wrapper.svelte';
let prom_api__post_comment_obj: any = $state();
let content_new_html = $state($idaa_slct.post_comment_obj?.content ?? '');
let content_changed = $state(false);
// let notes_new_html = $state('');
// let notes_changed = $state(false);
let disable_submit_btn = $state(false);
function preventDefault<T extends Event>(fn: (event: T) => void) {
return function (event: T) {
event.preventDefault();
fn(event);
};
}
async function handle_submit_form(event: any) {
if (log_lvl > 1) {
console.log('*** handle_submit_form() ***', event.target);
}
let {
log_lvl = $bindable(1),
lq__post_obj
// lq__post_comment_obj,
// lq__post_comment_obj_li
}: Props = $props();
disable_submit_btn = true;
// *** Import Svelte specific
import { fade } from 'svelte/transition';
// *** Import other supporting libraries
// *** Import Aether specific variables and functions
import type { key_val } from '$lib/stores/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
// import { core_func } from '$lib/ae_core/ae_core_functions';
import { api } from '$lib/api/api';
import {
ae_snip,
ae_loc,
ae_sess,
ae_api,
ae_trig,
slct,
slct_trigger
} from '$lib/stores/ae_stores';
import { idaa_loc, idaa_sess, idaa_slct } from '$lib/stores/ae_idaa_stores';
import { posts_func } from '$lib/ae_posts/ae_posts_functions';
import Tiptap_editor from '$lib/elements/element_codemirror_wrapper.svelte';
let prom_api__post_comment_obj: any = $state();
let content_new_html = $state($idaa_slct.post_comment_obj?.content ?? '');
let content_changed = $state(false);
// let notes_new_html = $state('');
// let notes_changed = $state(false);
let disable_submit_btn = $state(false);
function preventDefault<T extends Event>(fn: (event: T) => void) {
return function (event: T) {
event.preventDefault();
fn(event);
};
let form_data = new FormData(event.target);
if (log_lvl > 1) {
console.log(form_data);
}
async function handle_submit_form(event: any) {
if (log_lvl > 1) {
console.log('*** handle_submit_form() ***', event.target);
}
// Form Post object data incoming
let post_comment_di = ae_util.extract_prefixed_form_data({
prefix: null,
form_data: form_data,
trim_values: true,
bool_tf_str: true,
log_lvl: log_lvl
});
// console.log(post_comment_di);
disable_submit_btn = true;
// Form Post object data outgoing
let post_comment_do: key_val = {};
let form_data = new FormData(event.target);
if (log_lvl > 1) {
console.log(form_data);
}
if (!$idaa_slct.post_comment_id) {
post_comment_do['post_id_random'] = $idaa_slct.post_id;
post_comment_do['enable'] = true;
}
// Form Post object data incoming
let post_comment_di = ae_util.extract_prefixed_form_data({
prefix: null,
form_data: form_data,
trim_values: true,
bool_tf_str: true,
log_lvl: log_lvl
});
// console.log(post_comment_di);
// post_comment_do['title'] = post_comment_di.title;
// Form Post object data outgoing
let post_comment_do: key_val = {};
// Check if the content_new_html exists and is a string
if (typeof content_new_html === 'string') {
console.log('New content is a string');
post_comment_do['content'] = content_new_html;
} else {
console.log('New content is not a string. Do nothing.');
// post_comment_do['content'] = event_meeting_fd.content;
}
if (!$idaa_slct.post_comment_id) {
post_comment_do['post_id_random'] = $idaa_slct.post_id;
post_comment_do['enable'] = true;
}
post_comment_do['anonymous'] = post_comment_di.anonymous;
// post_comment_do['title'] = post_comment_di.title;
post_comment_do['external_person_id'] = post_comment_di.external_person_id;
post_comment_do['full_name'] = post_comment_di.full_name;
post_comment_do['email'] = post_comment_di.email;
post_comment_do['notify'] = post_comment_do.notify;
// Check if the content_new_html exists and is a string
if (typeof content_new_html === 'string') {
console.log('New content is a string');
post_comment_do['content'] = content_new_html;
} else {
console.log('New content is not a string. Do nothing.');
// post_comment_do['content'] = event_meeting_fd.content;
}
post_comment_do['hide'] = post_comment_di.hide;
post_comment_do['priority'] = post_comment_di.priority;
if (post_comment_di.sort) {
post_comment_do['sort'] = Number(post_comment_di.sort);
} else {
post_comment_do['sort'] = null;
}
if (post_comment_di.group) {
post_comment_do['group'] = post_comment_di.group;
} else {
post_comment_do['group'] = null;
}
post_comment_do['anonymous'] = post_comment_di.anonymous;
// NOTE: We only want to set enable value if the input is defined.
if (typeof post_comment_di.enable !== 'undefined') {
post_comment_do.enable = post_comment_di.enable;
}
// NOTE: We want to always default to false if the input is not defined.
// post_comment_do.enable = post_comment_di.enable ?? false;
post_comment_do['external_person_id'] = post_comment_di.external_person_id;
post_comment_do['full_name'] = post_comment_di.full_name;
post_comment_do['email'] = post_comment_di.email;
post_comment_do['notify'] = post_comment_do.notify;
// // Check if the notes_new_html exists and is a string
// if (typeof $idaa_slct.post_comment_obj.notes_new_html === 'string') {
// console.log('New notes is a string');
// post_comment_do['notes'] = $idaa_slct.post_comment_obj.notes_new_html;
// } else {
// console.log('New notes is not a string. Do nothing.');
// // post_comment_do['notes'] = event_meeting_fd.notes;
// }
post_comment_do['hide'] = post_comment_di.hide;
post_comment_do['priority'] = post_comment_di.priority;
if (post_comment_di.sort) {
post_comment_do['sort'] = Number(post_comment_di.sort);
} else {
post_comment_do['sort'] = null;
}
if (post_comment_di.group) {
post_comment_do['group'] = post_comment_di.group;
} else {
post_comment_do['group'] = null;
}
log_lvl = 1;
if (log_lvl) {
console.log(post_comment_do);
}
// NOTE: We only want to set enable value if the input is defined.
if (typeof post_comment_di.enable !== 'undefined') {
post_comment_do.enable = post_comment_di.enable;
}
// NOTE: We want to always default to false if the input is not defined.
// post_comment_do.enable = post_comment_di.enable ?? false;
// // Check if the notes_new_html exists and is a string
// if (typeof $idaa_slct.post_comment_obj.notes_new_html === 'string') {
// console.log('New notes is a string');
// post_comment_do['notes'] = $idaa_slct.post_comment_obj.notes_new_html;
// } else {
// console.log('New notes is not a string. Do nothing.');
// // post_comment_do['notes'] = event_meeting_fd.notes;
// }
log_lvl = 1;
if (!$idaa_slct.post_comment_id) {
if (log_lvl) {
console.log(post_comment_do);
console.log(
`Current Post Comment Object List Length: ${$idaa_slct.post_comment_obj_li.length}`,
$idaa_slct.post_comment_obj_li
);
}
if (!$idaa_slct.post_comment_id) {
if (log_lvl) {
console.log(
`Current Post Comment Object List Length: ${$idaa_slct.post_comment_obj_li.length}`,
$idaa_slct.post_comment_obj_li
);
}
prom_api__post_comment_obj = await posts_func
.create_ae_obj__post_comment({
api_cfg: $ae_api,
post_id: $idaa_slct.post_id,
data_kv: post_comment_do,
log_lvl: log_lvl
})
// .then(function (post_comment_obj_create_result) {
// if (!post_comment_obj_create_result) {
// console.log('The result was null or false.');
// return false;
// }
prom_api__post_comment_obj = await posts_func
.create_ae_obj__post_comment({
api_cfg: $ae_api,
post_id: $idaa_slct.post_id,
data_kv: post_comment_do,
log_lvl: log_lvl
})
// .then(function (post_comment_obj_create_result) {
// if (!post_comment_obj_create_result) {
// console.log('The result was null or false.');
// return false;
// }
// $idaa_slct.post_comment_id = post_comment_obj_create_result.post_comment_id_random;
// $idaa_slct.post_comment_obj = post_comment_obj_create_result;
// $idaa_slct.post_comment_id = post_comment_obj_create_result.post_comment_id_random;
// $idaa_slct.post_comment_obj = post_comment_obj_create_result;
// return post_comment_obj_create_result;
// return post_comment_obj_create_result;
// })
.catch(function (error: any) {
console.log('Something went wrong.');
console.log(error);
return false;
// })
.catch(function (error: any) {
console.log('Something went wrong.');
console.log(error);
return false;
// })
// .finally(async () => {
});
// .finally(async () => {
});
$idaa_slct.post_comment_id = prom_api__post_comment_obj.post_comment_id_random;
$idaa_slct.post_comment_obj = prom_api__post_comment_obj;
$idaa_slct.post_comment_id = prom_api__post_comment_obj.post_comment_id_random;
$idaa_slct.post_comment_obj = prom_api__post_comment_obj;
disable_submit_btn = false;
$idaa_sess.bb.show__inline_edit__post_comment_id = false;
disable_submit_btn = false;
$idaa_sess.bb.show__inline_edit__post_comment_id = false;
// Send notification to staff
// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) {
if ($ae_loc.site_cfg_json?.bb_send_staff_new_email) {
send_staff_notification_email();
}
// Send notification to staff
// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) {
if ($ae_loc.site_cfg_json?.bb_send_staff_new_email) {
send_staff_notification_email();
}
// Send notification to the original poster
if (
!$ae_loc.administrator_access &&
$ae_loc.site_cfg_json?.bb_send_poster_email &&
$idaa_slct.post_obj.notify
) {
// if ($ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) {
send_poster_notification_email();
}
// Send notification to the original poster
if (
!$ae_loc.administrator_access &&
$ae_loc.site_cfg_json?.bb_send_poster_email &&
$idaa_slct.post_obj.notify
) {
// if ($ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) {
send_poster_notification_email();
}
// Send a notification to any other post commenters
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_commenter_email) {
console.log(
`Sending notification email to post commenters...: ${$idaa_slct.post_comment_obj_li?.length}`
);
if ($idaa_slct.post_comment_obj_li && $idaa_slct.post_comment_obj_li.length > 0) {
for (const post_comment of $idaa_slct.post_comment_obj_li) {
console.log('Post Comment ID:', post_comment.post_comment_id);
if (
post_comment?.email &&
post_comment.post_comment_id !== $idaa_slct.post_comment_id &&
post_comment?.email !== $idaa_slct.post_comment_obj?.email
) {
console.log(
`Sending notification email to post commenter: ${post_comment.full_name}`,
post_comment
);
send_poster_commenters_notification_email({
post_comment_obj: post_comment
});
}
// Send a notification to any other post commenters
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_commenter_email) {
console.log(
`Sending notification email to post commenters...: ${$idaa_slct.post_comment_obj_li?.length}`
);
if ($idaa_slct.post_comment_obj_li && $idaa_slct.post_comment_obj_li.length > 0) {
for (const post_comment of $idaa_slct.post_comment_obj_li) {
console.log('Post Comment ID:', post_comment.post_comment_id);
if (
post_comment?.email &&
post_comment.post_comment_id !== $idaa_slct.post_comment_id &&
post_comment?.email !== $idaa_slct.post_comment_obj?.email
) {
console.log(
`Sending notification email to post commenter: ${post_comment.full_name}`,
post_comment
);
send_poster_commenters_notification_email({
post_comment_obj: post_comment
});
}
}
}
return prom_api__post_comment_obj;
} else {
prom_api__post_comment_obj = posts_func
.update_ae_obj__post_comment({
api_cfg: $ae_api,
post_comment_id: $idaa_slct.post_comment_id,
data_kv: post_comment_do,
log_lvl: log_lvl
})
.then(function (post_comment_obj_update_result) {
if (!post_comment_obj_update_result) {
console.log('The result was null or false.');
return false;
}
$idaa_slct.post_comment_obj = post_comment_obj_update_result;
return post_comment_obj_update_result;
})
.catch(function (error: any) {
console.log('Something went wrong.');
console.log(error);
return false;
})
.finally(() => {
// We need to do this since the comment has changed and the idaa_slct object does automatically update (yet...???).
// $idaa_slct.post_comment_obj = $lq__post_comment_obj;
disable_submit_btn = false;
$idaa_sess.bb.show__inline_edit__post_comment_id = false;
// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_update_email) {
if ($ae_loc.site_cfg_json?.bb_send_staff_update_email) {
send_staff_notification_email();
}
// For now we are not going to send a notification to the poster when a post comment has been updated.
// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) {
// send_poster_notification_email();
// }
});
return prom_api__post_comment_obj;
}
}
// Updated 2024-11-15
async function handle_delete_post_comment_obj({
post_comment_id,
method = 'disable'
}: {
post_comment_id: string;
method?: string;
}) {
if (log_lvl) {
console.log('*** handle_delete_post_comment_obj() ***');
}
return prom_api__post_comment_obj;
} else {
prom_api__post_comment_obj = posts_func
.delete_ae_obj_id__post_comment({
.update_ae_obj__post_comment({
api_cfg: $ae_api,
post_comment_id: post_comment_id,
method: method,
post_comment_id: $idaa_slct.post_comment_id,
data_kv: post_comment_do,
log_lvl: log_lvl
})
.then(function (post_comment_obj_delete_result) {
$idaa_sess.bb.show__inline_edit__post_comment_id = false;
.then(function (post_comment_obj_update_result) {
if (!post_comment_obj_update_result) {
console.log('The result was null or false.');
return false;
}
$idaa_slct.post_comment_obj = post_comment_obj_update_result;
return post_comment_obj_update_result;
})
.catch(function (error: any) {
console.log('The result was null or false when trying to delete.', error);
console.log('Something went wrong.');
console.log(error);
return false;
})
.finally(() => {
// $idaa_sess.recovery_meetings.show__modal_edit = false;
$idaa_slct.post_comment_id = null;
$idaa_slct.post_comment_obj = null;
// We need to do this since the comment has changed and the idaa_slct object does automatically update (yet...???).
// $idaa_slct.post_comment_obj = $lq__post_comment_obj;
disable_submit_btn = false;
$idaa_sess.bb.show__inline_edit__post_comment_id = false;
// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_update_email) {
if ($ae_loc.site_cfg_json?.bb_send_staff_update_email) {
send_staff_notification_email();
}
// For now we are not going to send a notification to the poster when a post comment has been updated.
// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) {
// send_poster_notification_email();
// }
});
return prom_api__post_comment_obj;
}
}
function send_staff_notification_email() {
log_lvl = 1;
if (log_lvl) {
console.log(
`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id} Post Title: ${$idaa_slct?.post_obj?.title}`
);
}
if (log_lvl > 1) {
console.log(`Selected Post Object:`, $idaa_slct.post_obj);
console.log(`Selected Post Comment Object:`, $idaa_slct.post_comment_obj);
// console.log($lq__post_obj);
// console.log($lq__post_obj?.title);
// console.log($lq__post_obj?.content);
}
let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;
let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title ?? '-- not set --'} (ID: ${$idaa_slct.post_id})`;
let body_html = `
<div>${$idaa_slct.post_obj.full_name},
<p>A BB post comment has been created or updated on the post named "${$idaa_slct.post_obj.title ?? '-- not set --'}".</p>
</div>
<div>
Commenter's Novi ID: ${$idaa_slct.post_comment_obj.external_person_id ?? '-- not set --'}<br>
Commenter's Name: ${$idaa_slct.post_comment_obj.full_name ?? '-- not set --'}<br>
Commenter's Email: ${$idaa_slct.post_comment_obj.email ?? '-- not set --'}
</div>
<div>
Original Poster's Novi ID: ${$idaa_slct.post_obj.external_person_id ?? '-- not set --'}<br>
Original Poster's Name: ${$idaa_slct.post_obj.full_name ?? '-- not set --'}<br>
Original Poster's Email: ${$idaa_slct.post_obj.email ?? '-- not set --'}
</div>
<br>
<div>
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
<p>Use this link to view the post.<br>
Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
</div>`;
api.send_email({
api_cfg: $ae_api,
from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com',
from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbcomment@oneskyit.com', // 'scott+idaabb@oneskyit.com', // $idaa_slct.post_comment_obj.email,
// to_email: 'scott+idaabbstaff@oneskyit.com',
to_name: $ae_loc.site_cfg_json?.admin_name ?? 'IDAA BB Admin',
subject: subject,
body_html: body_html
});
// Updated 2024-11-15
async function handle_delete_post_comment_obj({
post_comment_id,
method = 'disable'
}: {
post_comment_id: string;
method?: string;
}) {
if (log_lvl) {
console.log('*** handle_delete_post_comment_obj() ***');
}
function send_poster_notification_email() {
log_lvl = 1;
if (log_lvl) {
console.log(`*** send_poster_notification_email() *** Post ID: ${$idaa_slct.post_id}`);
}
let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;
let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title ?? '-- not set --'} (ID: ${$idaa_slct.post_id})`;
let body_html = `
<div>${$idaa_slct.post_obj.full_name ?? '-- not set --'},
<p>Your BB post named "${$idaa_slct.post_obj.title ?? '-- not set --'}" has been commented on.</p>
</div>
<br>
<div>
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
<p>Use this link to view the post.<br>
Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
</div>`;
api.send_email({
prom_api__post_comment_obj = posts_func
.delete_ae_obj_id__post_comment({
api_cfg: $ae_api,
from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com',
from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
// to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbpost@oneskyit.com', // 'scott+idaabb@oneskyit.com',
to_email: $idaa_slct.post_obj.email,
// to_email: 'scott+idaabb@oneskyit.com',
to_name: $idaa_slct.post_obj.full_name ?? 'IDAA BB Poster',
subject: subject,
body_html: body_html
post_comment_id: post_comment_id,
method: method,
log_lvl: log_lvl
})
.then(function (post_comment_obj_delete_result) {
$idaa_sess.bb.show__inline_edit__post_comment_id = false;
})
.catch(function (error: any) {
console.log('The result was null or false when trying to delete.', error);
})
.finally(() => {
// $idaa_sess.recovery_meetings.show__modal_edit = false;
$idaa_slct.post_comment_id = null;
$idaa_slct.post_comment_obj = null;
});
return prom_api__post_comment_obj;
}
function send_staff_notification_email() {
log_lvl = 1;
if (log_lvl) {
console.log(
`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id} Post Title: ${$idaa_slct?.post_obj?.title}`
);
}
if (log_lvl > 1) {
console.log(`Selected Post Object:`, $idaa_slct.post_obj);
console.log(`Selected Post Comment Object:`, $idaa_slct.post_comment_obj);
// console.log($lq__post_obj);
// console.log($lq__post_obj?.title);
// console.log($lq__post_obj?.content);
}
function send_poster_commenters_notification_email({
post_comment_obj = $idaa_slct.post_comment_obj
}: {
post_comment_obj?: any;
} = {}) {
log_lvl = 1;
if (log_lvl) {
console.log(
`*** send_poster_commenters_notification_email() *** Post ID: ${$idaa_slct.post_id}`
);
}
let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;
let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;
let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title ?? '-- not set --'} (ID: ${$idaa_slct.post_id})`;
let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title ?? '-- not set --'} (ID: ${$idaa_slct.post_id})`;
let body_html = `
<div>${$idaa_slct.post_obj.full_name},
<p>A BB post comment has been created or updated on the post named "${$idaa_slct.post_obj.title ?? '-- not set --'}".</p>
</div>
let body_html = `
<div>${post_comment_obj.full_name ?? '-- not set --'},
<p>The BB post named "${$idaa_slct.post_obj.title ?? '-- not set --'}" has been commented on.</p>
</div>
<div>
Commenter's Novi ID: ${$idaa_slct.post_comment_obj.external_person_id ?? '-- not set --'}<br>
Commenter's Name: ${$idaa_slct.post_comment_obj.full_name ?? '-- not set --'}<br>
Commenter's Email: ${$idaa_slct.post_comment_obj.email ?? '-- not set --'}
</div>
<br>
<div>
Original Poster's Novi ID: ${$idaa_slct.post_obj.external_person_id ?? '-- not set --'}<br>
Original Poster's Name: ${$idaa_slct.post_obj.full_name ?? '-- not set --'}<br>
Original Poster's Email: ${$idaa_slct.post_obj.email ?? '-- not set --'}
</div>
<div>
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
<p>Use this link to view the post.<br>
Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
</div>`;
<br>
api.send_email({
api_cfg: $ae_api,
from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com',
from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
// to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbpost@oneskyit.com', // 'scott+idaabb@oneskyit.com',
to_email: $idaa_slct.post_obj.email,
// to_email: 'scott+idaabb@oneskyit.com',
to_name: $idaa_slct.post_obj.full_name ?? 'IDAA BB Post Commenter',
subject: subject,
body_html: body_html
});
<div>
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
<p>Use this link to view the post.<br>
Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
</div>`;
api.send_email({
api_cfg: $ae_api,
from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com',
from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbcomment@oneskyit.com', // 'scott+idaabb@oneskyit.com', // $idaa_slct.post_comment_obj.email,
// to_email: 'scott+idaabbstaff@oneskyit.com',
to_name: $ae_loc.site_cfg_json?.admin_name ?? 'IDAA BB Admin',
subject: subject,
body_html: body_html
});
}
function send_poster_notification_email() {
log_lvl = 1;
if (log_lvl) {
console.log(`*** send_poster_notification_email() *** Post ID: ${$idaa_slct.post_id}`);
}
let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;
let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title ?? '-- not set --'} (ID: ${$idaa_slct.post_id})`;
let body_html = `
<div>${$idaa_slct.post_obj.full_name ?? '-- not set --'},
<p>Your BB post named "${$idaa_slct.post_obj.title ?? '-- not set --'}" has been commented on.</p>
</div>
<br>
<div>
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
<p>Use this link to view the post.<br>
Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
</div>`;
api.send_email({
api_cfg: $ae_api,
from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com',
from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
// to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbpost@oneskyit.com', // 'scott+idaabb@oneskyit.com',
to_email: $idaa_slct.post_obj.email,
// to_email: 'scott+idaabb@oneskyit.com',
to_name: $idaa_slct.post_obj.full_name ?? 'IDAA BB Poster',
subject: subject,
body_html: body_html
});
}
function send_poster_commenters_notification_email({
post_comment_obj = $idaa_slct.post_comment_obj
}: {
post_comment_obj?: any;
} = {}) {
log_lvl = 1;
if (log_lvl) {
console.log(
`*** send_poster_commenters_notification_email() *** Post ID: ${$idaa_slct.post_id}`
);
}
let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;
let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title ?? '-- not set --'} (ID: ${$idaa_slct.post_id})`;
let body_html = `
<div>${post_comment_obj.full_name ?? '-- not set --'},
<p>The BB post named "${$idaa_slct.post_obj.title ?? '-- not set --'}" has been commented on.</p>
</div>
<br>
<div>
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
<p>Use this link to view the post.<br>
Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
</div>`;
api.send_email({
api_cfg: $ae_api,
from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com',
from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
// to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbpost@oneskyit.com', // 'scott+idaabb@oneskyit.com',
to_email: $idaa_slct.post_obj.email,
// to_email: 'scott+idaabb@oneskyit.com',
to_name: $idaa_slct.post_obj.full_name ?? 'IDAA BB Post Commenter',
subject: subject,
body_html: body_html
});
}
</script>
<section
@@ -486,7 +486,7 @@
Content (comment body):
</span>
<Tiptap_editor
<CodeMirror_wrapper
bind:html_text={content_new_html}
classes="bg-gray-100 dark:bg-gray-800"
placeholder="Your post content here..."

View File

@@ -1,399 +1,399 @@
<script lang="ts">
interface Props {
log_lvl?: number;
lq__post_obj: any;
obj_changed: boolean;
interface Props {
log_lvl?: number;
lq__post_obj: any;
obj_changed: boolean;
}
let { log_lvl = $bindable(0), lq__post_obj, obj_changed = $bindable(false) }: Props = $props();
// *** Import Svelte specific
// import { onDestroy, onMount } from 'svelte';
import { fade } from 'svelte/transition';
import { browser } from '$app/environment';
import { goto } from '$app/navigation';
// *** Import other supporting libraries
// *** Import Aether specific variables and functions
import type { key_val } from '$lib/stores/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
import { core_func } from '$lib/ae_core/ae_core_functions';
import { api } from '$lib/api/api';
import {
ae_snip,
ae_loc,
ae_sess,
ae_api,
ae_trig,
slct,
slct_trigger
} from '$lib/stores/ae_stores';
import { idaa_loc, idaa_sess, idaa_slct } from '$lib/stores/ae_idaa_stores';
import { posts_func } from '$lib/ae_posts/ae_posts_functions';
import CodeMirror_wrapper from '$lib/elements/element_codemirror_editor_wrapper.svelte';
import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte';
// let obj_changed = $state(false);
// let orig_post_obj: any = $state(null);
// let orig_post_obj: any = $state({ ...$idaa_slct.post_obj }); // Create a copy of the post object
if (!$idaa_slct.post_obj) {
$idaa_slct.post_obj = {};
}
// Create a copy of the post object
let orig_post_obj: any = { ...$idaa_slct.post_obj };
if (browser) {
// console.log(`$lq__post_obj = `, $lq__post_obj);
console.log(`$idaa_slct.post_obj = `, $idaa_slct.post_obj);
// orig_post_obj = { ...$idaa_slct.post_obj }; // Create a copy of the post object
console.log(`orig_post_obj = `, orig_post_obj);
// JSON.stringify($idaa_slct.post_obj) !== JSON.stringify(orig_post_obj)
}
if ($idaa_loc.bb.edit__post_obj) {
obj_changed = true; // This is an odd workaround to make new posts saveable.
$idaa_sess.bb.edit__post_obj = $idaa_loc.bb.edit__post_obj;
$idaa_loc.bb.edit__post_obj = false;
}
let ae_promises: key_val = $state({});
let prom_api__post_obj: any = $state();
// let prom_api__post_obj__hosted_file: any;
let content_new_html = $state($idaa_slct.post_obj?.content ?? '');
let notes_new_html = $state($idaa_slct.post_obj?.notes ?? '');
let hosted_file_id_li = $state<string[]>([]); // Array of hosted file IDs
let hosted_file_obj_li = $state<any[]>([]); // Array of hosted file objects
let upload_complete = $state(false);
let disable_submit_btn = $state(false);
function preventDefault<T extends Event>(fn: (event: T) => void) {
return function (event: T) {
event.preventDefault();
fn(event);
};
}
async function handle_submit_form(event: any) {
if (log_lvl > 1) {
console.log('*** handle_submit_form() ***', event.target);
}
let { log_lvl = $bindable(0), lq__post_obj, obj_changed = $bindable(false) }: Props = $props();
disable_submit_btn = true;
// *** Import Svelte specific
// import { onDestroy, onMount } from 'svelte';
import { fade } from 'svelte/transition';
import { browser } from '$app/environment';
import { goto } from '$app/navigation';
// *** Import other supporting libraries
// *** Import Aether specific variables and functions
import type { key_val } from '$lib/stores/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
import { core_func } from '$lib/ae_core/ae_core_functions';
import { api } from '$lib/api/api';
import {
ae_snip,
ae_loc,
ae_sess,
ae_api,
ae_trig,
slct,
slct_trigger
} from '$lib/stores/ae_stores';
import { idaa_loc, idaa_sess, idaa_slct } from '$lib/stores/ae_idaa_stores';
import { posts_func } from '$lib/ae_posts/ae_posts_functions';
import Tiptap_editor from '$lib/elements/element_codemirror_wrapper.svelte';
import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte';
// let obj_changed = $state(false);
// let orig_post_obj: any = $state(null);
// let orig_post_obj: any = $state({ ...$idaa_slct.post_obj }); // Create a copy of the post object
if (!$idaa_slct.post_obj) {
$idaa_slct.post_obj = {};
}
// Create a copy of the post object
let orig_post_obj: any = { ...$idaa_slct.post_obj };
if (browser) {
// console.log(`$lq__post_obj = `, $lq__post_obj);
console.log(`$idaa_slct.post_obj = `, $idaa_slct.post_obj);
// orig_post_obj = { ...$idaa_slct.post_obj }; // Create a copy of the post object
console.log(`orig_post_obj = `, orig_post_obj);
// JSON.stringify($idaa_slct.post_obj) !== JSON.stringify(orig_post_obj)
let form_data = new FormData(event.target);
if (log_lvl) {
console.log(form_data);
}
if ($idaa_loc.bb.edit__post_obj) {
obj_changed = true; // This is an odd workaround to make new posts saveable.
$idaa_sess.bb.edit__post_obj = $idaa_loc.bb.edit__post_obj;
$idaa_loc.bb.edit__post_obj = 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: log_lvl
});
// console.log(post_di);
// 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;
}
let ae_promises: key_val = $state({});
let prom_api__post_obj: any = $state();
// let prom_api__post_obj__hosted_file: any;
post_do['title'] = post_di.title;
let content_new_html = $state($idaa_slct.post_obj?.content ?? '');
let notes_new_html = $state($idaa_slct.post_obj?.notes ?? '');
let hosted_file_id_li = $state<string[]>([]); // Array of hosted file IDs
let hosted_file_obj_li = $state<any[]>([]); // Array of hosted file objects
let upload_complete = $state(false);
let disable_submit_btn = $state(false);
function preventDefault<T extends Event>(fn: (event: T) => void) {
return function (event: T) {
event.preventDefault();
fn(event);
};
// Check if the content_new_html exists and is a string
if (typeof content_new_html === 'string') {
console.log('New content is a string');
post_do['content'] = content_new_html;
} else {
console.log('New content is not a string. Do nothing.');
// post_do['content'] = event_meeting_fd.content;
}
async function handle_submit_form(event: any) {
if (log_lvl > 1) {
console.log('*** handle_submit_form() ***', event.target);
}
disable_submit_btn = true;
let form_data = new FormData(event.target);
if (log_lvl) {
console.log(form_data);
}
// 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: log_lvl
});
// console.log(post_di);
// 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 content_new_html === 'string') {
console.log('New content is a string');
post_do['content'] = 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['notify'] = post_di.notify;
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;
}
// NOTE: We only want to set enable value if the input is defined.
if (typeof post_di.enable !== 'undefined') {
post_do.enable = post_di.enable;
}
// NOTE: We want to always default to false if the input is not defined.
// post_do['enable'] = !!post_di.enable;
console.log(`post_di.enable = ${post_di.enable}`);
console.log(`post_do.enable = ${post_do.enable}`);
// Check if the notes_new_html exists and is a string
if (typeof notes_new_html === 'string') {
console.log('New notes is a string');
post_do['notes'] = notes_new_html;
} else {
console.log('New notes is not a string. Do nothing.');
// post_do['notes'] = event_meeting_fd.notes;
}
log_lvl = 1;
if (log_lvl) {
console.log(post_do);
}
if (!$idaa_slct.post_id) {
prom_api__post_obj = 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;
}
if (log_lvl) {
console.log('post_obj_create_result:', post_obj_create_result);
}
$idaa_slct.post_id = post_obj_create_result.post_id_random;
$idaa_slct.post_obj = post_obj_create_result;
return post_obj_create_result;
})
.catch(function (error: any) {
console.log('Something went wrong.');
console.log(error);
return false;
})
.finally(() => {
disable_submit_btn = false;
$idaa_sess.bb.edit__post_obj = false;
// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) {
if ($ae_loc.site_cfg_json?.bb_send_staff_new_email) {
send_staff_notification_email();
}
});
return prom_api__post_obj;
} else {
prom_api__post_obj = 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;
}
$idaa_slct.post_obj = post_obj_update_result;
return post_obj_update_result;
})
.catch(function (error: any) {
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.edit__post_obj = false;
// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_update_email) {
if ($ae_loc.site_cfg_json?.bb_send_staff_update_email) {
send_staff_notification_email();
}
});
return prom_api__post_obj;
}
// 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;
}
// Updated 2024-11-15
async function handle_delete_post_obj({
post_id,
method = 'disable'
}: {
post_id: string;
method?: string;
}) {
if (log_lvl) {
console.log('*** handle_delete_post_obj() ***');
}
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['notify'] = post_di.notify;
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;
}
// NOTE: We only want to set enable value if the input is defined.
if (typeof post_di.enable !== 'undefined') {
post_do.enable = post_di.enable;
}
// NOTE: We want to always default to false if the input is not defined.
// post_do['enable'] = !!post_di.enable;
console.log(`post_di.enable = ${post_di.enable}`);
console.log(`post_do.enable = ${post_do.enable}`);
// Check if the notes_new_html exists and is a string
if (typeof notes_new_html === 'string') {
console.log('New notes is a string');
post_do['notes'] = notes_new_html;
} else {
console.log('New notes is not a string. Do nothing.');
// post_do['notes'] = event_meeting_fd.notes;
}
log_lvl = 1;
if (log_lvl) {
console.log(post_do);
}
if (!$idaa_slct.post_id) {
prom_api__post_obj = posts_func
.delete_ae_obj_id__post({
.create_ae_obj__post({
api_cfg: $ae_api,
post_id: post_id,
method: method,
account_id: $ae_loc.account_id,
data_kv: post_do,
log_lvl: log_lvl
})
.then(function (post_obj_delete_result) {
// $idaa_sess.bb.show__modal_view__post_id = false;
$idaa_sess.bb.edit__post_obj = false;
// $idaa_sess.bb.show__inline_edit__post_comment_id = false;
})
.catch(function (error: any) {
console.log('The result was null or false when trying to delete.', error);
})
.finally(() => {
// $idaa_sess.recovery_meetings.show__modal_edit = false;
$idaa_slct.post_id = null;
$idaa_slct.post_obj = null;
$idaa_slct.post_comment_id = null;
$idaa_slct.post_comment_obj = null;
goto('/idaa/bb'); // Redirect to the BB page
});
.then(function (post_obj_create_result) {
if (!post_obj_create_result) {
console.log('The result was null or false.');
return false;
}
return prom_api__post_obj;
}
if (log_lvl) {
console.log('post_obj_create_result:', post_obj_create_result);
}
$idaa_slct.post_id = post_obj_create_result.post_id_random;
$idaa_slct.post_obj = post_obj_create_result;
async function handle_hosted_files_uploaded(
hosted_file_id_li: string[],
hosted_file_obj_li: any[]
) {
console.log(`*** handle_hosted_files_uploaded() *** ${hosted_file_id_li}`);
// NOTE: No longer directly updating the $idaa_slct.post_obj.hosted_file_obj_li. This will be updated when the PATCH API for Post update finishes.
// We need to add the record to the $idaa_slct.post_obj.hosted_file_obj_li and then update the post_obj.linked_li_json with the new value.
// let new_linked_li_json = [...$idaa_slct.post_obj.linked_li_json ?? {}]; // Initialize with existing linked_li_json or an empty array
let new_linked_li_json = $idaa_slct.post_obj.linked_li_json ?? []; // Initialize with existing linked_li_json or an empty array
if (!$idaa_slct.post_obj.linked_li_json) {
// $idaa_slct.post_obj.linked_li_json = hosted_file_obj_li;
new_linked_li_json = hosted_file_obj_li;
} else {
$idaa_slct.post_obj.linked_li_json.push(...hosted_file_obj_li);
new_linked_li_json = [...new_linked_li_json];
// new_linked_li_json.push(...hosted_file_obj_li);
// new_linked_li_json = [...new_linked_li_json];
}
prom_api__post_obj = posts_func
.update_ae_obj__post({
api_cfg: $ae_api,
post_id: $idaa_slct.post_id,
data_kv: {
// linked_li_json: JSON.stringify($idaa_slct.post_obj.linked_li_json),
linked_li_json: JSON.stringify(new_linked_li_json)
},
log_lvl: log_lvl
})
.then(function (post_obj_update_result) {
// $idaa_slct.post_obj = $lq__post_obj;
return post_obj_create_result;
})
.catch(function (error: any) {
console.log('Something went wrong.');
console.log(error);
return false;
})
.finally(() => {
disable_submit_btn = false;
$idaa_sess.bb.edit__post_obj = false;
// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) {
if ($ae_loc.site_cfg_json?.bb_send_staff_new_email) {
send_staff_notification_email();
}
});
return prom_api__post_obj;
} else {
prom_api__post_obj = 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;
}
$idaa_slct.post_obj = post_obj_update_result;
return post_obj_update_result;
})
.catch(function (error: any) {
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.edit__post_obj = false;
// if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_update_email) {
if ($ae_loc.site_cfg_json?.bb_send_staff_update_email) {
send_staff_notification_email();
}
});
return prom_api__post_obj;
}
}
// Updated 2024-11-15
async function handle_delete_post_obj({
post_id,
method = 'disable'
}: {
post_id: string;
method?: string;
}) {
if (log_lvl) {
console.log('*** handle_delete_post_obj() ***');
}
function send_staff_notification_email() {
if (log_lvl) {
console.log(`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id}`);
}
let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;
let subject = `IDAA BB Post: ${$idaa_slct.post_obj.title} (ID: ${$idaa_slct.post_id})`;
let body_html = `
<div>${$idaa_slct.post_obj.full_name ?? '-- not set --'},
<p>A BB post has been created or updated named "${$idaa_slct.post_obj.title}".</p>
</div>
<div>
Poster's Novi ID: ${$idaa_slct.post_obj.external_person_id ?? '-- not set --'}<br>
Poster's Name: ${$idaa_slct.post_obj.full_name ?? '-- not set --'}<br>
Poster's Email: ${$idaa_slct.post_obj.email ?? '-- not set --'}
</div>
<br>
<div>
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
<p>Use this link to view the post.<br>
Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
</div>`;
api.send_email({
prom_api__post_obj = posts_func
.delete_ae_obj_id__post({
api_cfg: $ae_api,
from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com',
// from_email: 'noreply+idaabb@oneskyit.com',
from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbpost@oneskyit.com',
// to_email: 'test+idaabb@oneskyit.com', // 'scott+idaabb@oneskyit.com'
to_name: $ae_loc.site_cfg_json?.admin_name ?? 'IDAA BB Admin',
subject: subject,
body_html: body_html
post_id: post_id,
method: method,
log_lvl: log_lvl
})
.then(function (post_obj_delete_result) {
// $idaa_sess.bb.show__modal_view__post_id = false;
$idaa_sess.bb.edit__post_obj = false;
// $idaa_sess.bb.show__inline_edit__post_comment_id = false;
})
.catch(function (error: any) {
console.log('The result was null or false when trying to delete.', error);
})
.finally(() => {
// $idaa_sess.recovery_meetings.show__modal_edit = false;
$idaa_slct.post_id = null;
$idaa_slct.post_obj = null;
$idaa_slct.post_comment_id = null;
$idaa_slct.post_comment_obj = null;
goto('/idaa/bb'); // Redirect to the BB page
});
return prom_api__post_obj;
}
async function handle_hosted_files_uploaded(
hosted_file_id_li: string[],
hosted_file_obj_li: any[]
) {
console.log(`*** handle_hosted_files_uploaded() *** ${hosted_file_id_li}`);
// NOTE: No longer directly updating the $idaa_slct.post_obj.hosted_file_obj_li. This will be updated when the PATCH API for Post update finishes.
// We need to add the record to the $idaa_slct.post_obj.hosted_file_obj_li and then update the post_obj.linked_li_json with the new value.
// let new_linked_li_json = [...$idaa_slct.post_obj.linked_li_json ?? {}]; // Initialize with existing linked_li_json or an empty array
let new_linked_li_json = $idaa_slct.post_obj.linked_li_json ?? []; // Initialize with existing linked_li_json or an empty array
if (!$idaa_slct.post_obj.linked_li_json) {
// $idaa_slct.post_obj.linked_li_json = hosted_file_obj_li;
new_linked_li_json = hosted_file_obj_li;
} else {
$idaa_slct.post_obj.linked_li_json.push(...hosted_file_obj_li);
new_linked_li_json = [...new_linked_li_json];
// new_linked_li_json.push(...hosted_file_obj_li);
// new_linked_li_json = [...new_linked_li_json];
}
$effect(() => {
if (orig_post_obj === null || orig_post_obj === undefined || orig_post_obj === 'undefined') {
obj_changed = false;
} else if (
!obj_changed &&
orig_post_obj?.id &&
(JSON.stringify($idaa_slct.post_obj) !== JSON.stringify(orig_post_obj) ||
content_new_html !== (orig_post_obj.content ?? '') ||
notes_new_html !== (orig_post_obj.notes ?? ''))
) {
// console.log('Post object has changed from original.', $inspect(orig_post_obj));
console.log('Post object has changed from original.', orig_post_obj);
console.log('Post object has changed.', $idaa_slct.post_obj);
obj_changed = true;
} else if (
obj_changed &&
orig_post_obj?.id &&
JSON.stringify($idaa_slct.post_obj) === JSON.stringify(orig_post_obj) &&
content_new_html === (orig_post_obj.content ?? '') &&
notes_new_html === (orig_post_obj.notes ?? '')
) {
obj_changed = false;
}
});
prom_api__post_obj = posts_func
.update_ae_obj__post({
api_cfg: $ae_api,
post_id: $idaa_slct.post_id,
data_kv: {
// linked_li_json: JSON.stringify($idaa_slct.post_obj.linked_li_json),
linked_li_json: JSON.stringify(new_linked_li_json)
},
log_lvl: log_lvl
})
.then(function (post_obj_update_result) {
// $idaa_slct.post_obj = $lq__post_obj;
})
.catch(function (error: any) {
console.log('Something went wrong.');
console.log(error);
return false;
});
}
$effect(() => {
if (upload_complete && hosted_file_id_li?.length && hosted_file_obj_li?.length) {
handle_hosted_files_uploaded(hosted_file_id_li, hosted_file_obj_li);
upload_complete = false; // Reset the upload complete flag
}
function send_staff_notification_email() {
if (log_lvl) {
console.log(`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id}`);
}
let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`;
let subject = `IDAA BB Post: ${$idaa_slct.post_obj.title} (ID: ${$idaa_slct.post_id})`;
let body_html = `
<div>${$idaa_slct.post_obj.full_name ?? '-- not set --'},
<p>A BB post has been created or updated named "${$idaa_slct.post_obj.title}".</p>
</div>
<div>
Poster's Novi ID: ${$idaa_slct.post_obj.external_person_id ?? '-- not set --'}<br>
Poster's Name: ${$idaa_slct.post_obj.full_name ?? '-- not set --'}<br>
Poster's Email: ${$idaa_slct.post_obj.email ?? '-- not set --'}
</div>
<br>
<div>
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
<p>Use this link to view the post.<br>
Copy and paste link: <a href="${link_base_url}?post_id=${$idaa_slct.post_id}">${link_base_url}?post_id=${$idaa_slct.post_id}</a></p>
</div>`;
api.send_email({
api_cfg: $ae_api,
from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com',
// from_email: 'noreply+idaabb@oneskyit.com',
from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply',
to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbpost@oneskyit.com',
// to_email: 'test+idaabb@oneskyit.com', // 'scott+idaabb@oneskyit.com'
to_name: $ae_loc.site_cfg_json?.admin_name ?? 'IDAA BB Admin',
subject: subject,
body_html: body_html
});
}
$effect(() => {
if (orig_post_obj === null || orig_post_obj === undefined || orig_post_obj === 'undefined') {
obj_changed = false;
} else if (
!obj_changed &&
orig_post_obj?.id &&
(JSON.stringify($idaa_slct.post_obj) !== JSON.stringify(orig_post_obj) ||
content_new_html !== (orig_post_obj.content ?? '') ||
notes_new_html !== (orig_post_obj.notes ?? ''))
) {
// console.log('Post object has changed from original.', $inspect(orig_post_obj));
console.log('Post object has changed from original.', orig_post_obj);
console.log('Post object has changed.', $idaa_slct.post_obj);
obj_changed = true;
} else if (
obj_changed &&
orig_post_obj?.id &&
JSON.stringify($idaa_slct.post_obj) === JSON.stringify(orig_post_obj) &&
content_new_html === (orig_post_obj.content ?? '') &&
notes_new_html === (orig_post_obj.notes ?? '')
) {
obj_changed = false;
}
});
$effect(() => {
if (upload_complete && hosted_file_id_li?.length && hosted_file_obj_li?.length) {
handle_hosted_files_uploaded(hosted_file_id_li, hosted_file_obj_li);
upload_complete = false; // Reset the upload complete flag
}
});
</script>
<section
@@ -480,13 +480,13 @@
<!-- <textarea name="content" id="content" class="ae_value post__content tinymce_editor editor_basic textarea" rows="5" cols="70" bind:value={$idaa_slct.post_obj.content} ></textarea> -->
{#if $ae_loc.administrator_access}
<Tiptap_editor
<CodeMirror_wrapper
bind:html_text={content_new_html}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="Your post content here..."
/>
{:else}
<Tiptap_editor
<CodeMirror_wrapper
default_minimal={true}
bind:html_text={content_new_html}
show_button_kv={{
@@ -1038,7 +1038,7 @@
<span class="legend text-sm font-semibold text-surface-600-400"
>Internal Staff Notes</span
>
<Tiptap_editor
<CodeMirror_wrapper
bind:html_text={notes_new_html}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="Internal notes for staff only. Not shown to the public."

View File

@@ -32,7 +32,7 @@
} from '$lib/stores/ae_stores';
import { idaa_loc, idaa_sess, idaa_slct, idaa_trig } from '$lib/stores/ae_idaa_stores';
import { events_func } from '$lib/ae_events_functions';
import Tiptap_editor from '$lib/elements/element_codemirror_wrapper.svelte';
import CodeMirror_wrapper from '$lib/elements/element_codemirror_editor_wrapper.svelte';
// export let container_class_li = [];
@@ -932,7 +932,7 @@
<span class="text-lg text-neutral-500 font-semibold"> Short description </span>
<!-- <textarea name="description" id="description" class="ae_value event__description tinymce_editor editor_basic textarea" rows="5" cols="70" bind:value={$idaa_slct.event_obj.description} ></textarea> -->
<Tiptap_editor
<CodeMirror_wrapper
bind:html_text={description_new_html}
classes="preset-tonal-surface hover:preset-filled-surface-100-900 font-mono font-normal"
placeholder="A short description or overview of this recovery meeting"
@@ -1310,7 +1310,7 @@
Additional information about the meeting location
</span>
<!-- <textarea class="ae_value event__location_text tinymce_editor editor_less_100 textarea" id="location_text" name="location_text" placeholder="Additional information about the meeting location" rows="2" cols="70" bind:value={$idaa_slct.event_obj.location_text}></textarea> -->
<Tiptap_editor
<CodeMirror_wrapper
bind:html_text={location_text_new_html}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="Additional information about the meeting location"
@@ -1779,7 +1779,7 @@
Additional information on how to attend
</span>
<!-- <textarea class="ae_value event__attend_text tinymce_editor editor_less_100 textarea" id="attend_text" name="attend_text" placeholder="Additional information on how to attend or join the meeting" rows="2" cols="70" value={$lq__event_obj?.attend_text ?? ''}></textarea> -->
<Tiptap_editor
<CodeMirror_wrapper
bind:html_text={attend_text_new_html}
classes="preset-tonal-surface hover:preset-filled-surface-100-900"
placeholder="Additional information on how to attend or join the meeting"