From 8bef30a7885ab69ed9c016e3d99070a5c44b37fb Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Tue, 28 Jan 2025 08:49:11 -0500 Subject: [PATCH] LEAF 4634 make wyswyg default, update base files for compat, better change tracking --- .../admin/templates/mod_templates_email.tpl | 74 ++++++++++++------- .../email/LEAF_automated_reminder_body.tpl | 14 ++-- .../email/LEAF_cancel_notification_body.tpl | 18 ++--- .../email/LEAF_mass_action_remind_body.tpl | 14 ++-- .../email/LEAF_notify_complete_body.tpl | 18 ++--- .../templates/email/LEAF_notify_next_body.tpl | 26 +++---- .../templates/email/LEAF_send_back_body.tpl | 22 +++--- .../base_templates/LEAF_template_body.tpl | 26 +++---- 8 files changed, 117 insertions(+), 95 deletions(-) diff --git a/LEAF_Request_Portal/admin/templates/mod_templates_email.tpl b/LEAF_Request_Portal/admin/templates/mod_templates_email.tpl index b6a13b50d..7a866ed0f 100644 --- a/LEAF_Request_Portal/admin/templates/mod_templates_email.tpl +++ b/LEAF_Request_Portal/admin/templates/mod_templates_email.tpl @@ -243,6 +243,7 @@ let currentEmailCcFile; let currentFileContent; + let currentTrumbowygFileContent; let currentSubjectContent; let currentEmailToContent; let currentEmailCcContent; @@ -335,12 +336,17 @@ /** * compare content for expected fields to determine if unsaved changes exist */ - function hasContentChanged(emailToData, emailCcData, subjectData, bodyData) { + function hasContentChanged(emailToData, emailCcData, subjectData, bodyData, trumbowValue = null) { + let currentBody = currentFileContent; + if(trumbowValue !== null) { + bodyData = trumbowValue; + currentBody = currentTrumbowygFileContent; + } return ( emailToData !== currentEmailToContent || emailCcData !== currentEmailCcContent || subjectData !== currentSubjectContent || - bodyData !== currentFileContent + bodyData !== currentBody ); } @@ -349,10 +355,12 @@ * Displays last save time, updates current*Content values, and calls saveFileHistory at success. */ function save() { - let reloadTrumbow = false; - if(trumbowygIsActive()) { + const trumbowValue = document.querySelector( + '#emailBodyCode + div textarea.trumbowyg-textarea' + )?.value || null; + + if(trumbowValue !== null) { useCodeEmailEditor(); - reloadTrumbow = true; $('#editor_trumbowyg_saving').show(); toggleEditorElements(true); } @@ -362,10 +370,10 @@ const subject = getCodeEditorValue(subjectEditor); const data = getCodeEditorValue(codeEditor); - const hasAnyChanges = hasContentChanged(emailToData, emailCcData, subject, data); + const hasAnyChanges = hasContentChanged(emailToData, emailCcData, subject, data, trumbowValue); if (!hasAnyChanges) { alert('There are no changes to save.'); - if(reloadTrumbow === true) { + if(trumbowValue !== null) { useTrumbowygEmailEditor(); $('#editor_trumbowyg_saving').hide(); } @@ -396,14 +404,19 @@ saveFileHistory(); $('#restore_original, #btn_compare').addClass('modifiedTemplate'); $(`.template_files a[data-file="${currentFile}"] + span`).addClass('custom_file'); - if(reloadTrumbow === true) { + //switch to Trumbowyg if it had been used + if(trumbowValue !== null) { $('#editor_trumbowyg_saving').hide(); useTrumbowygEmailEditor(); + currentTrumbowygFileContent = trumbowValue; + //use (body) data to sync current value regardless. + } else { + currentTrumbowygFileContent = data; } } }, error: function(jqXHR, textStatus, errorThrown) { - if(reloadTrumbow === true) { + if(trumbowValue !== null) { $('#editor_trumbowyg_saving').hide(); useTrumbowygEmailEditor(); } @@ -674,7 +687,9 @@ const emailCcData = document.getElementById('emailCcCode').value; const subject = getCodeEditorValue(subjectEditor); const data = getCodeEditorValue(codeEditor); - const hasChanges = hasContentChanged(emailToData, emailCcData, subject, data); + const trumbowValue = document.querySelector('#emailBodyCode + div textarea.trumbowyg-textarea')?.value || null; + + const hasChanges = hasContentChanged(emailToData, emailCcData, subject, data, trumbowValue); if (!ignoreUnsavedChanges && !ignorePrompt && hasChanges) { e.preventDefault(); return true; @@ -817,11 +832,13 @@ * @param {string} emailCcFile - eg LEAF_send_back_emailCc.tpl */ function loadContent(name, file, subjectFile, emailToFile, emailCcFile) { - let reloadTrumbow = false; - if(trumbowygIsActive()) { - useCodeEmailEditor(); - reloadTrumbow = true; - } + //current T editor val if it exists + const trumbowValue = document.querySelector( + '#emailBodyCode + div textarea.trumbowyg-textarea' + )?.value || null; + + useCodeEmailEditor(); + if (!file) { if(file === null && currentFile && codeEditor) { //from compare view const mergeViewBodyValue = getCodeEditorValue(codeEditor); @@ -850,9 +867,13 @@ const emailCcData = document.getElementById('emailCcCode').value; const subject = getCodeEditorValue(subjectEditor); const data = getCodeEditorValue(codeEditor); - const hasChanges = hasContentChanged(emailToData, emailCcData, subject, data); + + const hasChanges = hasContentChanged(emailToData, emailCcData, subject, data, trumbowValue); if (!ignoreUnsavedChanges && hasChanges && !confirm('You have unsaved changes. Are you sure you want to leave this page?')) { + if(trumbowValue !== null) { + useTrumbowygEmailEditor(); + } return; } } @@ -883,7 +904,7 @@ success: function(res) { $('#codeContainer').fadeIn(); // Check if codeEditor is defined, has a setValue method and file property exists - if (codeEditor && typeof codeEditor.setValue === 'function' && res?.file !== undefined) { + if (codeEditor && typeof codeEditor.setValue === 'function' && res?.file !== undefined && res?.file !== false) { codeEditor.setValue(res.file); currentFileContent = codeEditor.getValue(); if (subjectEditor && res.subjectFile !== null) { //subject is null for default email template @@ -898,11 +919,16 @@ currentEmailCcContent = res.emailCcFile; $("#emailToCode").val(currentEmailToContent); $("#emailCcCode").val(currentEmailCcContent); - if(reloadTrumbow === true) { - useTrumbowygEmailEditor(); + + useTrumbowygEmailEditor(); + //update current content from new T editor set up after file load + const elTrumbow = document.querySelector('#emailBodyCode + div textarea.trumbowyg-textarea'); + if(elTrumbow !== null) { + currentTrumbowygFileContent = elTrumbow.value; } + } else { - res?.file === undefined ? + res?.file === undefined || res?.file === false ? console.error('file not found') : console.error('codeEditor is not properly initialized.'); } @@ -1334,10 +1360,6 @@ document.getElementById('btn_useCodeMirror').focus(); } - function trumbowygIsActive() { - return document.querySelector('#emailBodyCode + div textarea.trumbowyg-textarea') !== null; - } - function useCodeEmailEditor(refreshCodeMirror = true) { //if element associated with Trumbowyg exists, update codemirror element before proceeding. const elTrumbow = document.querySelector('#emailBodyCode + div textarea.trumbowyg-textarea'); @@ -1360,11 +1382,11 @@ let btnUseCodeMirror = document.getElementById('btn_useCodeMirror'); if(btnUseTrumbow !== null && btnUseCodeMirror !== null) { if (showTrumbow === true) { - $('#emailLists, #subject, #divSubject, #emailBodyCode').hide(); + $('#emailBodyCode').hide(); btnUseCodeMirror.classList.add('show_button'); btnUseTrumbow.classList.remove('show_button'); } else { - $('#emailLists, #subject, #divSubject, #emailBodyCode').show(); + $('#emailBodyCode').show(); btnUseCodeMirror.classList.remove('show_button'); btnUseTrumbow.classList.add('show_button'); } diff --git a/LEAF_Request_Portal/templates/email/LEAF_automated_reminder_body.tpl b/LEAF_Request_Portal/templates/email/LEAF_automated_reminder_body.tpl index 5dc127315..60c1d3486 100644 --- a/LEAF_Request_Portal/templates/email/LEAF_automated_reminder_body.tpl +++ b/LEAF_Request_Portal/templates/email/LEAF_automated_reminder_body.tpl @@ -1,9 +1,9 @@ -Please review this request at your earliest convenience.

+Please review this request at your earliest convenience.

-Request title: - {{$fullTitle}}
-Request status: {{$lastStatus}}

-Request Link: - {{$siteRoot}}?a=printview&recordID={{$recordID}}

+Request title: + {{$fullTitle}}
+Request status: {{$lastStatus}}

+Request Link: + {{$siteRoot}}?a=printview&recordID={{$recordID}}

{{$reminderBodyText}} -
\ No newline at end of file +
\ No newline at end of file diff --git a/LEAF_Request_Portal/templates/email/LEAF_cancel_notification_body.tpl b/LEAF_Request_Portal/templates/email/LEAF_cancel_notification_body.tpl index 12304d47f..3e59829a2 100644 --- a/LEAF_Request_Portal/templates/email/LEAF_cancel_notification_body.tpl +++ b/LEAF_Request_Portal/templates/email/LEAF_cancel_notification_body.tpl @@ -1,12 +1,12 @@ -A request that you were a part of has been cancelled.
-Request #{{$recordID}} - {{$fullTitle}}.

-This is a notification only and no action is required on your part.

+A request that you were a part of has been cancelled.
+Request #{{$recordID}} - {{$fullTitle}}.

+This is a notification only and no action is required on your part.

{{$comment}} -Request title: - {{$fullTitle}}
-Request status: {{$lastStatus}}

-Request Link: - {{$siteRoot}}?a=printview&recordID={{$recordID}}

-
\ No newline at end of file +Request title: + {{$fullTitle}}
+Request status: {{$lastStatus}}

+Request Link: + {{$siteRoot}}?a=printview&recordID={{$recordID}}

+
\ No newline at end of file diff --git a/LEAF_Request_Portal/templates/email/LEAF_mass_action_remind_body.tpl b/LEAF_Request_Portal/templates/email/LEAF_mass_action_remind_body.tpl index 82795377d..858370358 100644 --- a/LEAF_Request_Portal/templates/email/LEAF_mass_action_remind_body.tpl +++ b/LEAF_Request_Portal/templates/email/LEAF_mass_action_remind_body.tpl @@ -1,9 +1,9 @@ The last action on Request #{{$recordID}} is older than {{$daysSince}} days. -Please review this request at your earliest convenience.

+Please review this request at your earliest convenience.

-Request title: - {{$fullTitle}}
-Request status: {{$lastStatus}}

-Request Link: - {{$siteRoot}}?a=printview&recordID={{$recordID}}

-
\ No newline at end of file +Request title: + {{$fullTitle}}
+Request status: {{$lastStatus}}

+Request Link: + {{$siteRoot}}?a=printview&recordID={{$recordID}}

+
\ No newline at end of file diff --git a/LEAF_Request_Portal/templates/email/LEAF_notify_complete_body.tpl b/LEAF_Request_Portal/templates/email/LEAF_notify_complete_body.tpl index 72a9b6e72..645cdf563 100644 --- a/LEAF_Request_Portal/templates/email/LEAF_notify_complete_body.tpl +++ b/LEAF_Request_Portal/templates/email/LEAF_notify_complete_body.tpl @@ -1,9 +1,9 @@ -Request ID#: {{$recordID}}
-Request title: {{$fullTitle}}
-Request status: {{$lastStatus}}
-
-Comments: {{$comment}}
-
-------------------------
-View Request: {{$siteRoot}}?a=printview&recordID={{$recordID}}
-
\ No newline at end of file +Request ID#: {{$recordID}}
+Request title: {{$fullTitle}}
+Request status: {{$lastStatus}}
+
+Comments: {{$comment}}
+
+------------------------
+View Request: {{$siteRoot}}?a=printview&recordID={{$recordID}}
+
\ No newline at end of file diff --git a/LEAF_Request_Portal/templates/email/LEAF_notify_next_body.tpl b/LEAF_Request_Portal/templates/email/LEAF_notify_next_body.tpl index 9e21ed8b3..dc4c9be1b 100644 --- a/LEAF_Request_Portal/templates/email/LEAF_notify_next_body.tpl +++ b/LEAF_Request_Portal/templates/email/LEAF_notify_next_body.tpl @@ -1,13 +1,13 @@ -The following request requires your review.
-
-Please review your inbox at: {{$siteRoot}}report.php?a=LEAF_Inbox
-
-Request ID#: {{$recordID}}
-Request title: {{$fullTitle}}
-Request status: {{$lastStatus}}
-
-Comments: {{$comment}}
-
-------------------------
-View Request: {{$siteRoot}}?a=printview&recordID={{$recordID}}
-
\ No newline at end of file +The following request requires your review.
+
+Please review your inbox at: {{$siteRoot}}report.php?a=LEAF_Inbox
+
+Request ID#: {{$recordID}}
+Request title: {{$fullTitle}}
+Request status: {{$lastStatus}}
+
+Comments: {{$comment}}
+
+------------------------
+View Request: {{$siteRoot}}?a=printview&recordID={{$recordID}}
+
\ No newline at end of file diff --git a/LEAF_Request_Portal/templates/email/LEAF_send_back_body.tpl b/LEAF_Request_Portal/templates/email/LEAF_send_back_body.tpl index 79d85cd3c..063a217c4 100644 --- a/LEAF_Request_Portal/templates/email/LEAF_send_back_body.tpl +++ b/LEAF_Request_Portal/templates/email/LEAF_send_back_body.tpl @@ -1,11 +1,11 @@ -Request ID#: {{$recordID}}
-
-Request status: Sent Back by {{$stepTitle}}
-
-Comments: {{$comment}}
-
-------------------------
-{{$siteRoot}}?a=printview&recordID={{$recordID}}
-
-{{$fullTitle}}
-
\ No newline at end of file +Request ID#: {{$recordID}}
+
+Request status: Sent Back by {{$stepTitle}}
+
+Comments: {{$comment}}
+
+------------------------
+{{$siteRoot}}?a=printview&recordID={{$recordID}}
+
+{{$fullTitle}}
+
\ No newline at end of file diff --git a/LEAF_Request_Portal/templates/email/base_templates/LEAF_template_body.tpl b/LEAF_Request_Portal/templates/email/base_templates/LEAF_template_body.tpl index 292f6f6e5..9000db9e3 100644 --- a/LEAF_Request_Portal/templates/email/base_templates/LEAF_template_body.tpl +++ b/LEAF_Request_Portal/templates/email/base_templates/LEAF_template_body.tpl @@ -1,13 +1,13 @@ -The following request requires your review.
-
-Please review your inbox at: {{$siteRoot}}?a=inbox
-
-Request ID#: {{$recordID}}
-Request title: {{$fullTitle}}
-Request status: {{$lastStatus}}
-
-Comments: {{$comment}}
-
-------------------------
-View Request: {{$siteRoot}}?a=printview&recordID={{$recordID}}
-
\ No newline at end of file +The following request requires your review.
+
+Please review your inbox at: {{$siteRoot}}?a=inbox
+
+Request ID#: {{$recordID}}
+Request title: {{$fullTitle}}
+Request status: {{$lastStatus}}
+
+Comments: {{$comment}}
+
+------------------------
+View Request: {{$siteRoot}}?a=printview&recordID={{$recordID}}
+
\ No newline at end of file