FIX_UNLAYER_SUBMIT,FEAT_ATTACHMENTS_FOR_ECARD,FEAT_PLACEHOLDERS_IN_UNLAYER

This commit is contained in:
Srinivas-Saravanan 2025-01-27 09:03:22 +05:30
parent c0d5d49a93
commit a1bebbbbf2
2 changed files with 141 additions and 15 deletions

View File

@ -1226,6 +1226,20 @@ class sendMailNotification
$notification = $params['notification_data'];
$client_data = $params['client_data'];
$mail = $params['test_mail'];
$mailAttachmentModel = new MailAttachmentModel();
$attachment_data = $mailAttachmentModel
->select('file_path, file_name')
->where('notification_id', $notification['id'])
->where('is_active', 1)
->findAll();
$attachments = [];
foreach ($attachment_data as $data) {
$attachments[] = [
"filePath" => WRITEPATH . $data['file_path'],
"fileName" => $data['file_name']
];
}
$mail_content = $notification['mail_content'];
$subject = $notification['subject'];
@ -1252,7 +1266,7 @@ class sendMailNotification
$mail_content = str_replace("[[ecard_download_link]]", "<a href='$link/1'>Download Insurance Card</a>", $mail_content);
$mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content);
$wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']];
$wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'],'attachments' => $attachments, 'reply_to' => $client_data['reply_to']];
return $wholeData;

View File

@ -175,7 +175,7 @@
<span class="slider round" style="height: 27px;"></span>
</label>
&nbsp; &nbsp;
<a href="" data-toggle="modal" id="account_maneger_summary_mail" onclick="getMailTemplateData(this)" data-target="#account_maneger_summary_mail_modal">Edit</a>
<a href="" data-toggle="modal" id="account_maneger_summary_mail" onclick="getMailTemplateData2(this)" data-target="#account_maneger_summary_mail_modal">Edit</a>
</div>
<div class="form-group col-md-5">
<textarea style="display:none;" name="" id="" class="form-control "></textarea>
@ -446,6 +446,16 @@
<input type="file" id="Question_title_fileInput" style="display: none;">
<table id="attachment_table_ecard" class="table table-sm mb-0" style="margin-top: 30px;">
<thead>
<tr>
<th>Attachments</th>
<th>Action</th>
</tr>
</thead>
<tbody id="attachment_tbody_ecard">
</tbody>
</table>
</div>
@ -664,7 +674,24 @@
<div class="form-group col-md-2 testmail" style="display: none;">
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="testMailSend(this)">Test Mail</a>
</div>
</div><hr>
</div>
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
<select id="account_maneger_summary_mail_modal_customButton" class="form-control" style="border:none;right: 6px;width: auto;position: absolute;z-index: 1;top: 17px;height: 32px;float: right;" onchange="copyToClipboard(this)">
<option value="">PlaceHolders</option>
<?php foreach ($placeHolders as $value): ?>
<?php if($value == 'member_name' || $value == 'nhance_logo' || $value == 'client_logo' || $value == 'app_link' || $value == 'client_name' || $value == 'member_summary'){ ?>
<?php $valueChange = str_replace('_', ' ', $value); $valueChange = ucwords($valueChange); ?>
<option value="{{<?php echo $value; ?>}}"><?php echo $valueChange; ?></option>
<?php } ?>
<?php endforeach; ?>
</select>
<span id="copy-feedback" style="display: none; position: absolute; top: 50px; right: 10px; color: green; font-size: 12px;">
Copied to clipboard!
</span>
</div>
</div>
<hr>
<!-- Unlayer editor -->
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
@ -897,7 +924,7 @@
}
else if (target.matches('#account_maneger_summary_mail_modal_customButton'))
{
editor4.selection.insertHTML($(target).val());
// editor4.selection.insertHTML($(target).val());
$(target).val('');
}
else if (target.matches('#client_hr_summary_mail_modal_customButton'))
@ -913,7 +940,7 @@
editor.setEditorValue('');
editor2.setEditorValue('');
editor3.setEditorValue('');
editor4.setEditorValue('');
// editor4.setEditorValue('');
editor5.setEditorValue('');
editor6.setEditorValue('');
@ -1275,10 +1302,10 @@
return word.charAt(0).toUpperCase() + word.slice(1);
}).join(' ');
}
template_name = '';
function getMailTemplateData(element)
{
var template_name = $(element).attr('id');
template_name = $(element).attr('id');
if (template_name == "member_welcome_mail" || template_name == "member_reminder_mail" || template_name == "member_ecard_mail" || template_name == "member_review_and_summary_mail" || template_name == "client_hr_summary_mail")
{
@ -1311,16 +1338,19 @@
if(res.id){
$('.testmail').show();
$('#attachment_table').show();
$('#attachment_table_ecard')
$('.setid').attr('data-id', res.id);
}else{
$('.testmail').hide();
$('#attachment_table').hide();
$('#attachment_table_ecard').hide();
$('.setid').attr('data-id', '');
}
}else{
$('.testmail').hide();
$('#attachment_table').hide();
$('#attachment_table_ecard').hide();
$('.setid').attr('data-id', '');
}
@ -1448,8 +1478,13 @@
function addHTMLInput(data = null) {
console.log('addHTMLInput function called');
const container = document.getElementById('attachment_tbody');
console.log(template_name);
var container = '';
if (template_name == 'member_welcome_mail'){
container = document.getElementById('attachment_tbody');
}else{
container = document.getElementById('attachment_tbody_ecard');
}
if (data) {
@ -1512,7 +1547,11 @@
}
function removeHTMLInput(element) {
const container = document.getElementById('attachment_tbody');
if (template_name == 'member_welcome_mail'){
const container = document.getElementById('attachment_tbody');
}else{
const container = document.getElementById('attachment_tbody_ecard');
}
const rows = container.querySelectorAll('.dynamic-form-row');
if (rows.length > 1) {
@ -1525,13 +1564,14 @@
event.preventDefault(); // Prevent the default form submission
var template_name = $('#member_welcome_mail_template_name').val();
// var template_name = template_name;
var client_id = $('#general_PrimaryKey').val();
// console.log(client_id);
const formData = new FormData(form);
formData.append('template_name', template_name);
formData.append('client_id', client_id);
console.log(formData.template_name);
const fileInput = form.querySelector('input[type="file"]');
// Check if a file is selected
@ -1597,7 +1637,7 @@
function removeAttachment(id){
var template_name = $('#member_welcome_mail_template_name').val();
// var template_name = template_name
var client_id = $('#general_PrimaryKey').val();
$('.loader').fadeIn();
@ -1751,10 +1791,10 @@ function initializeEditor(callback) {
}
// Modified template data function with better error handling
function getMailTemplateData(element) {
function getMailTemplateData2(element) {
const template_name = element.id;
const validTemplates = [
"account_maneger_summary_mail",
"account_maneger_summary_mail","member_reminder_mail","member_ecard_mail"
];
if (!validTemplates.includes(template_name)) {
@ -1824,6 +1864,7 @@ function getMailTemplateData(element) {
// Update UI elements
$('.testmail').toggle(!!res.id);
$('#attachment_table').toggle(!!res.id);
$('#attachment_table_ecard').toggle(!!res.id);
$('.setid').attr('data-id', res.id || '');
}else{
console.log("Inside else");
@ -1949,5 +1990,76 @@ function hideBranding(){
console.log('Overlay added to hide branding.');
});
}
function copyToClipboard(selectElement) {
const value = selectElement.value; // Get the selected value
if (value) {
// Use the Clipboard API to copy the value
navigator.clipboard.writeText(value)
.then(() => {
const feedback = document.getElementById('copy-feedback');
feedback.style.display = 'inline'; // Show the feedback message
setTimeout(() => {
feedback.style.display = 'none'; // Hide the feedback message after 2 seconds
}, 2000);
})
.catch(err => {
console.error('Failed to copy text: ', err);
});
}
}
</script>
<!-- <script src="https://editor.unlayer.com/embed.js"></script> -->
<!-- <script>
// Initialize Unlayer editor
unlayer.init({
id: 'editor-container', // Make sure to target your correct editor container ID
projectId: 1234, // Replace with your actual Unlayer project ID
tools: {
text: {
label: 'Text',
icon: 'fa fa-font'
}
},
paste: { // Enable the paste tool
label: 'Paste',
icon: 'fa fa-clipboard', // You can customize the icon here
action: function() {
// You can handle any custom behavior for paste here
console.log('Paste icon clicked!');
}
}
})
// Function to handle pasting clipboard content into a text block
async function pasteFromClipboard() {
try {
// Use the Clipboard API to get the clipboard text
const text = await navigator.clipboard.readText();
if (text) {
// Get the current selected block or create one if none exists
const editor = unlayer.getEditor();
const currentBlock = editor.getSelectedElement();
if (currentBlock && currentBlock.type === 'text') {
// If the selected block is a text block, insert the text there
editor.insertText(text);
} else {
// If there's no text block, create one and insert the text
editor.addTextBlock({
"type": "text",
"text": text
});
}
}
} catch (err) {
console.error('Failed to read clipboard contents: ', err);
}
}
// Listen for the click event inside the editor container
document.getElementById('editor-container').addEventListener('click', function() {
pasteFromClipboard(); // Paste clipboard content when clicked inside editor
});
</script> -->