nhance/app/Views/notification.php
2026-02-09 12:57:17 +05:30

2722 lines
119 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<style>
#notification_table {
overflow-x: unset;
}
.preview_button {
display: none;
}
.scrollb {
overflow-y: auto !important;
}
#editor-container {
width: 100%;
min-height: 600px;
}
.modal-dialog {
max-width: 90% !important;
width: 90% !important;
}
/* Also ensure the modal body has proper height */
.modal-body {
min-height: 600px;
padding: 20px;
}
/* If you're using Bootstrap's modal, you might also want to ensure proper positioning */
.modal-dialog {
margin: 1.75rem auto;
}
.mail-section {
border: 1px solid #00999E;
border-radius: 10px;
padding: 5px !important;
}
</style>
<style>
/* Custom switch (responsive, no inline styles) */
#notification-tab .switch {
position: relative;
display: inline-block;
width: 2.5rem;
height: 1.2rem;
}
#notification-tab .switch input {
opacity: 0;
width: 0;
height: 0;
}
#notification-tab .slider {
position: absolute;
cursor: pointer;
inset: 0;
background-color: #ccc;
transition: 0.3s;
border-radius: 34px;
}
#notification-tab .slider:before {
position: absolute;
content: "";
height: 1rem;
width: 1rem;
left: 0.2rem;
bottom: 0.1rem;
background-color: #fff;
transition: 0.3s;
border-radius: 50%;
}
#notification-tab input:checked+.slider {
background-color: #2196F3;
}
#notification-tab input:checked+.slider:before {
transform: translateX(1.2rem);
}
/* Reusable row styling */
#notification-tab .mail-row {
display: flex;
justify-content: space-between;
align-items: center;
padding-left: .5rem;
padding-right: .5rem;
}
#notification-tab .mail-row .mail-section {
display: flex;
width: 100%;
align-items: center;
}
#notification-tab .mail-row .mail-section .left {
display: flex;
align-items: center;
margin-top: .3rem;
flex: 0 0 70%;
}
#notification-tab .mail-row .mail-section .right {
flex: 0 0 30%;
text-align: right;
}
</style>
<div class="tab-pane fade" id="notification-tab">
<input type="hidden" id="client_id_for_client_branch" value="<?= isset($notification['id']) ? $notification['id'] : '' ?>" />
<div class="row float-right" style="padding-bottom: 10px;position: relative;right: 13px;">
</div>
<div class="table-responsive" id="notification_table">
<!-- <form id="notification_enable_form"> -->
<div>
<p><?php
// print_r($notification);
$member_welcome_mail = 0;
$member_common_mail = 0 ;
$member_reminder_mail = 0;
$member_ecard_mail = 0;
$member_review_and_summary_mail = 0;
$account_maneger_summary_mail = 0;
$client_hr_summary_mail = 0;
$hr_cd_insufficient_balance_mail = 0;
if (isset($notification)) {
foreach ($notification as $value) {
if ($value['template_name'] == 'member_welcome_mail') {
$member_welcome_mail = $value['enabled'];
}
if ($value['template_name'] == 'member_common_mail') {
$member_common_mail = $value['enabled'];
}
if ($value['template_name'] == 'member_reminder_mail') {
$member_reminder_mail = $value['enabled'];
}
if ($value['template_name'] == 'member_ecard_mail') {
$member_ecard_mail = $value['enabled'];
}
if ($value['template_name'] == 'member_review_and_summary_mail') {
$member_review_and_summary_mail = $value['enabled'];
}
if ($value['template_name'] == 'account_maneger_summary_mail') {
$account_maneger_summary_mail = $value['enabled'];
}
if ($value['template_name'] == 'client_hr_summary_mail') {
$client_hr_summary_mail = $value['enabled'];
}
if ($value['template_name'] == 'hr_cd_insufficient_balance_mail') {
$hr_cd_insufficient_balance_mail = $value['enabled'];
}
}
}
?></p>
</div>
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-6">
<label for="branch_name">Team mail ID<span class="text-danger"></span></label>
<textarea name="" id="nhance_team_mail_ids" class="form-control" placeholder="Example: jhon@gmail.com, dave@gmail.com"><?php echo isset($client['common_mails']) ? $client['common_mails'] : ''; ?></textarea>
</div>
<div class="form-group col-md-6">
<label for="branch_name">HR mail ID<span class="text-danger"></span></label>
<textarea name="" id="hr_mail_id" class="form-control" placeholder="Example: jhon@gmail.com, dave@gmail.com"><?php echo isset($client['hr_mails']) ? $client['hr_mails'] : ''; ?></textarea>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="mail_domain">Mail Domain<span class="text-danger"></span></label>
<input type="text" name="" id="mail_domain" class="form-control" placeholder="Only one Domain Name. Example: nhance.com" value="<?php echo isset($client['mail_domain']) ? $client['mail_domain'] : ''; ?>">
</div>
<div class="form-group col-md-6">
<label for="reply_to">Reply To Mail<span class="text-danger"></span></label>
<input type="text" name="" id="reply_to" class="form-control" placeholder="Only one Reply-to mail. Example: jhon@gmail.com" value="<?php echo isset($client['reply_to']) ? $client['reply_to'] : ''; ?>">
</div>
</div>
<!-- mail section -->
<div class="form-row">
<!-- Example: Member welcome mail -->
<div class="form-group col-md-6 mail-row">
<div class="mail-section">
<div class="left">
<label class="switch">
<input id="member_welcome_mail_btn" type="checkbox" name="member_welcome_mail_btn" <?= ($member_welcome_mail == 1) ? 'checked' : '' ?>>
<span class="slider"></span>
</label>
<span class="ml-2">Member welcome mail</span>
</div>
<div class="right">
<a href="#" id="member_welcome_mail" onclick="getMailTemplateData(this)" data-toggle="modal" data-target="#member_welcome_mail_modal">
<i class="mdi mdi-pencil"></i>
</a>
</div>
</div>
</div>
<!-- Example: Member reminder mail -->
<div class="form-group col-md-6 mail-row">
<div class="mail-section">
<div class="left">
<label class="switch">
<input id="member_reminder_mail_btn" type="checkbox" name="member_reminder_mail_btn" <?= ($member_reminder_mail == 1) ? 'checked' : '' ?>>
<span class="slider"></span>
</label>
<span class="ml-2">Member reminder mail</span>
</div>
<div class="right">
<a href="#" id="member_reminder_mail" onclick="getMailTemplateData(this)" data-toggle="modal" data-target="#member_reminder_mail_modal">
<i class="mdi mdi-pencil"></i>
</a>
</div>
</div>
</div>
</div>
<div class="form-row">
<!-- Member Ecard mail row-->
<div class="form-group col-md-6 mail-row">
<div class="mail-section">
<div class="left">
<label class="switch">
<input id="member_ecard_mail_btn" type="checkbox" name="member_ecard_mail_btn" <?= $member_ecard_mail == 1 ? 'checked' : '' ?>>
<span class="slider round"></span>
</label>
<span class="ml-2"> Member ECard mail</span>
</div>
<div class="right">
<a href="" data-toggle="modal" id="member_ecard_mail" onclick="getMailTemplateData(this)" data-target="#member_ecard_mail_modal">
<i class="mdi mdi-pencil"></i>
</a>
</div>
</div>
</div>
<div class="form-group col-md-6 mail-row">
<div class="mail-section">
<div class="left">
<label class="switch">
<input id="member_common_mail_btn" type="checkbox" name="member_common_mail_btn" <?= $member_common_mail == 1 ? 'checked' : '' ?>>
<span class="slider round"></span>
</label>
<span class="ml-2"> Common Mail </span>
</div>
<div class="right">
<a href="" data-toggle="modal" id="member_common_mail" onclick="getMailTemplateData(this)" data-target="#member_common_mail_modal">
<i class="mdi mdi-pencil"></i>
</a>
</div>
</div>
</div>
<!-- member review and summary mail -->
<div class="form-group col-md-6 mail-row">
<div class="mail-section">
<div class="left">
<label class="switch">
<input id="member_review_and_summary_mail_btn" type="checkbox" name="member_review_and_summary_mail_btn" <?= $member_review_and_summary_mail == 1 ? 'checked' : '' ?>>
<span class="slider round"></span>
</label>
<span class="ml-2"> Member Review And Summary Mail</span>
</div>
<div class="right">
<a href="" data-toggle="modal" id="member_review_and_summary_mail" onclick="getMailTemplateData(this)" data-target="#member_review_and_summary_mail_modal">
<i class="mdi mdi-pencil"></i>
</a>
</div>
</div>
</div>
<!-- Hr cd insifficient mail -->
<div class="form-group col-md-6 mail-row">
<div class="mail-section">
<div class="left">
<label class="switch">
<input id="hr_cd_insufficient_balance_mail_btn" type="checkbox" name="hr_cd_insufficient_balance_mail_btn" <?= $hr_cd_insufficient_balance_mail == 1 ? 'checked' : '' ?>>
<span class="slider round"></span>
</label>
<span class="ml-2"> HR CD Insufficient Balance Mail</span>
</div>
<div class="right">
<a href="" data-toggle="modal" id="hr_cd_insufficient_balance_mail" onclick="getMailTemplateData(this)" data-target="#hr_cd_insufficient_balance_mail_modal">
<i class="mdi mdi-pencil"></i>
</a>
</div>
</div>
</div>
</div>
<div class="form-row">
<!-- Account Manager Summary Mail row-->
<div class="form-group col-md-6 mail-row">
<div class="mail-section">
<div class="left">
<label class="switch">
<input id="account_maneger_summary_mail_btn" type="checkbox" name="account_maneger_summary_mail_btn" <?= $account_maneger_summary_mail ? 'checked' : '' ?>>
<span class="slider round"></span>
</label>
<span class="ml-2"> Account Manager summary mail</span>
</div>
<div class="right">
<a href="" data-toggle="modal" id="account_maneger_summary_mail" onclick="getMailTemplateData(this)" data-target="#account_maneger_summary_mail_modal">
<i class="mdi mdi-pencil"></i>
</a>
</div>
</div>
</div>
<!-- client hr summary mail -->
<div class="form-group col-md-6 mail-row">
<div class="mail-section">
<div class="left">
<label class="switch">
<input id="client_hr_summary_mail_btn" type="checkbox" name="client_hr_summary_mail_btn" <?= $client_hr_summary_mail == 1 ? 'checked' : '' ?>>
<span class="slider round"></span>
</label>
<span class="ml-2">Client HR summary mail</span>
</div>
<div class="right">
<a href="" data-toggle="modal" id="client_hr_summary_mail" onclick="getMailTemplateData(this)" data-target="#client_hr_summary_mail_modal">
<i class="mdi mdi-pencil"></i>
</a>
</div>
</div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
</div>
<div class="form-group col-md-6">
<a style="float:right;" id="notification_enable_form_submit" class="btn btn-primary waves-effect waves-light mr-1">Submit</a>
</div>
</div>
</div>
<!-- </form> -->
</div>
</div>
<!-- end -->
<!-- 1 Modal content for the Large example => Common mail -->
<div class="modal fade" id="member_common_mail_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
aria-hidden="true" aria-modal="true" data-backdrop="static">
<div class="modal-dialog modal-full-width scrollb">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Common mail <span id="nameOfThePolicy"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="text-center" id="no_data"></div>
<form role="form" class="parsley-examples" method="post" id="member_common_mail_form" enctype="multipart/form-data">
<input type="hidden" class="form-control" id="template_name" name="template_name" value="Common Mail" readonly>
<input type="hidden" id="member_common_mail_template_name" value="member_common_mail">
<input type="hidden" id="notification_temp_id" name="notification_temp_id">
<div class="form-group">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="emp_code">Template Name</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="template_name" name="template_name" class="form-control" value="Member Common Mail" readonly placeholder="Template Name">
</div>
</div>
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="emp_code">Email(s)</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="common_mail" name="common_mail" class="form-control" placeholder="Enter Emails">
<p style="color: black;font-size:12px;"> (* Multiple Emails Should Be Comma Seperated)</p>
</div>
</div>
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="emp_code">Subject</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject">
</div>
<div class="form-group col-md-5 testmail" >
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="testMailSend(this,'send')">Test Mail</a>
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="PreviewTheMail(this,'preview','member_common_mail')">Preview Mail</a>
</div>
</div>
<div class="member_common_mail_section">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
<select id="member_common_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">
<div id="member_common_mail_editor_container" style="height: 600px"></div>
</div>
</div>
<input type="file" id="Question_title_fileInput" style="display: none;">
<table data-custom-table-css="table" id="attachment_table_common" class="table table-sm mb-0" style="margin-top: 30px;">
<thead>
<tr>
<th>Attachments</th>
<th>Action</th>
</tr>
</thead>
<tbody id="attachment_tbody_common">
</tbody>
</table>
</div>
<div class="form-group text-right m-b-0 member_common_mail_action">
<button type="button" class="btn btn-primary waves-effect waves-light mr-1"
onclick="sendCommonMails()" > Send Common Mails </button>
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
id="btnGridSubmit_2">Submit</button>
</div>
</div>
<div class="member_common_mail_preview"></div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- 2 Modal content for the Large example => Welcome mail-->
<div class="modal fade" id="member_welcome_mail_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
aria-hidden="true" aria-modal="true" data-backdrop="static">
<div class="modal-dialog modal-full-width scrollb">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Template Name : Member welcome mail <span id="nameOfThePolicy"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="text-center" id="no_data"></div>
<form role="form" class="parsley-examples" method="post" id="member_welcome_mail_form" enctype="multipart/form-data">
<input type="hidden" class="form-control" id="template_name" name="template_name" value="Member Welcome Mail" readonly>
<input type="hidden" id="member_welcome_mail_template_name" value="member_welcome_mail">
<div class="form-group">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-1">
<label for="emp_code">Subject</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject">
</div>
<div class="form-group col-md-5 testmail" style="display: none;">
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="testMailSend(this,'send')">Test Mail</a>
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="PreviewTheMail(this,'preview','member_welcome_mail')">Preview Mail</a>
</div>
</div>
<div class="member_welcome_mail_section">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
<select id="member_welcome_mailmodal_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">
<div id="member_welcome_mail_editor_container" style="height: 600px"></div>
</div>
</div>
<input type="file" id="Question_title_fileInput" style="display: none;">
<table data-custom-table-css="table" id="attachment_table" class="table table-sm mb-0" style="margin-top: 30px;">
<thead>
<tr>
<th>Attachments</th>
<th>Action</th>
</tr>
</thead>
<tbody id="attachment_tbody">
</tbody>
</table>
</div>
</div>
<div class="member_welcome_mail_preview"></div>
<div class="form-group text-right m-b-0 member_welcome_mail_action">
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
id="btnGridSubmit_2">Submit</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- 3 Modal content for the Large example => Remainder mail -->
<div class="modal fade" id="member_reminder_mail_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false" aria-modal="true">
<div class="modal-dialog modal-full-width">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Member reminder mail <span id="nameOfThePolicy"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="text-center" id="no_data"></div>
<form role="form" class="parsley-examples" method="post" id="member_reminder_mail_form" enctype="multipart/form-data">
<div class="form-group">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="emp_code">Template Name</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="template_name" name="template_name" class="form-control" value="Member Reminder Mail" readonly placeholder="Template Name">
</div>
</div>
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="emp_code">Subject</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject">
</div>
<div class="form-group col-md-5 testmail" style="display: none;">
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="testMailSend(this,'send')">Test Mail</a>
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="PreviewTheMail(this,'preview','member_reminder_mail')">Preview Mail</a>
</div>
</div>
<!-- <div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
<select name="" id="" class="form-control" style="z-index: 1;float: right;position: absolute;margin-top: 18px;right: 53px;width: 100px;height: 30px;">
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
<option value="">4</option>
<option value="">6</option>
</select>
</div>
</div> -->
<div class="member_reminder_mail_section">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
<select id="member_reminder_mail_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">
<div id="member_reminder_mail_editor_container" style="height: 600px"></div>
</div>
</div>
<div id="editor" name="content"></div>
<input type="file" id="Question_title_fileInput" style="display: none;">
<table data-custom-table-css="table" id="attachment_table_reminder" class="table table-sm mb-0" style="margin-top: 30px;">
<thead>
<tr>
<th>Attachments</th>
<th>Action</th>
</tr>
</thead>
<tbody id="attachment_tbody_reminder">
</tbody>
</table>
</div>
<div class="form-group text-right m-b-0 member_reminder_mail_action">
<button class="btn btn-primary waves-effect waves-light mr-1 preview_button"
id="">Preview</button>
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
id="btnGridSubmit_2">Submit</button>
</div>
</div>
<div class="member_reminder_mail_preview"></div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- 4 Modal content for the Large example => Ecard mail -->
<div class="modal fade" id="member_ecard_mail_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
aria-hidden="true" aria-modal="true" data-backdrop="static">
<div class="modal-dialog modal-full-width">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Member ecard mail <span id="nameOfThePolicy"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="text-center" id="no_data"></div>
<form role="form" class="parsley-examples" method="post" id="member_ecard_mail_form" enctype="multipart/form-data">
<div class="form-group">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="emp_code">Template Name</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="template_name" name="template_name" class="form-control" value="Member Ecard Mail" readonly placeholder="Template Name">
</div>
</div>
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="emp_code">Subject</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject">
</div>
<div class="form-group col-md-5 testmail" style="display: none;">
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="testMailSend(this,'send')">Test Mail</a>
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="PreviewTheMail(this,'preview','member_ecard_mail')">Preview Mail</a>
</div>
</div>
<div class="member_ecard_mail_section">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
<select id="member_ecard_mail_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) { ?>
<?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">
<div id="member_ecard_mail_editor_container" style="height: 600px"></div>
</div>
</div>
<div id="editor" name="content"></div>
<input type="file" id="Question_title_fileInput" style="display: none;">
<table data-custom-table-css="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>
</div>
<div class="member_ecard_mail_preview"></div>
<div class="form-group text-right m-b-0 member_ecard_mail_action">
<button class="btn btn-primary waves-effect waves-light mr-1 preview_button"
id="">Preview</button>
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
id="btnGridSubmit_2">Submit</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- 5 Modal content for the Large example => Review And Summary mail -->
<div class="modal fade" id="member_review_and_summary_mail_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
aria-hidden="true" aria-modal="true" data-backdrop="static">
<div class="modal-dialog modal-full-width">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Member Review and summary mail <span id="nameOfThePolicy"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="text-center" id="no_data"></div>
<form role="form" class="parsley-examples" method="post" id="member_review_and_summary_mail_form" enctype="multipart/form-data">
<div class="form-group">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="emp_code">Template Name</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="template_name" name="template_name" value="Member Review and Summary Mail" readonly class="form-control" placeholder="Template Name">
</div>
</div>
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="emp_code">Subject</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject">
</div>
<div class="form-group col-md-5 testmail" style="display: none;">
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="testMailSend(this,'send')">Test Mail</a>
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="PreviewTheMail(this,'preview','member_review_and_summary_mail')">Preview Mail</a>
</div>
</div>
<!-- <div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
<select name="" id="" class="form-control" style="z-index: 1;float: right;position: absolute;margin-top: 18px;right: 53px;width: 100px;height: 30px;">
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
<option value="">4</option>
<option value="">6</option>
</select>
</div>
</div> -->
<div class="member_review_and_summary_mail_section">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
<select id="member_review_and_summary_mail_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">
<div id="member_review_and_summary_mail_editor_container" style="height: 600px;"></div>
</div>
</div>
<div id="editor"></div>
<input type="file" id="Question_title_fileInput" style="display: none;">
</div>
<div class="member_review_and_summary_mail_preview"></div>
</div>
<div class="form-group text-right m-b-0 member_review_and_summary_mail_action">
<button class="btn btn-primary waves-effect waves-light mr-1 preview_button"
id="">Preview</button>
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
id="btnGridSubmit_2">Submit</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- 6 Modal content for the Large example => Acc Manager Summary mail -->
<div class="modal fade" id="account_maneger_summary_mail_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
aria-hidden="true" aria-modal="true" data-backdrop="static">
<div class="modal-dialog modal-full-width">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Member Review and summary mail <span id="nameOfThePolicy"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="text-center" id="no_data"></div>
<form role="form" class="parsley-examples" method="post" id="account_maneger_summary_mail_form" enctype="multipart/form-data">
<div class="form-group">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="emp_code">Template Name</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="template_name" name="template_name" value="Account Maneger Summary Mail" readonly class="form-control" placeholder="Template Name">
</div>
</div>
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="emp_code">Subject</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject">
</div>
<div class="form-group col-md-5 testmail" style="display: none;">
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="testMailSend(this,'send')">Test Mail</a>
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="PreviewTheMail(this,'preview','account_maneger_summary_mail')">Preview Mail</a>
</div>
</div>
<div class="account_maneger_summary_mail_section">
<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">
<div id="account_maneger_summary_mail_editor_container" style="height: 600px"></div>
</div>
<!-- </div> -->
</div>
<div class="account_maneger_summary_mail_preview"></div>
<div class="form-group text-right m-b-0 account_maneger_summary_mail_action">
<button class="btn btn-primary waves-effect waves-light mr-1 preview_button"
id="">Preview</button>
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
id="btnGridSubmit_2">Submit</button>
</div>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- 7 Modal content for the Large example => Client HR Summary mail -->
<div class="modal fade" id="client_hr_summary_mail_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
aria-hidden="true" aria-modal="true" data-backdrop="static">
<div class="modal-dialog modal-full-width">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Member Review and Summary Mail <span id="nameOfThePolicy"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="text-center" id="no_data"></div>
<form role="form" class="parsley-examples" method="post" id="client_hr_summary_mail_form" enctype="multipart/form-data">
<div class="form-group">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="template_name">Template Name</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="template_name" name="template_name" value="Client HR Summary Mail" readonly class="form-control" placeholder="Template Name">
</div>
</div>
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="subject">Subject</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject">
</div>
<div class="form-group col-md-5 testmail" style="display: none;">
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="testMailSend(this,'send')">Test Mail</a>
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="PreviewTheMail(this,'preview','client_hr_summary_mail')">Preview Mail</a>
</div>
</div>
<div class="client_hr_summary_mail_section">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
<select id="client_hr_summary_mail_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 (in_array($value, ['member_name','nhance_logo','client_logo','app_link','client_name','member_summary'])): ?>
<?php $valueChange = ucwords(str_replace('_',' ',$value)); ?>
<option value="{{<?php echo $value; ?>}}"><?php echo $valueChange; ?></option>
<?php endif; ?>
<?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">
<div id="client_hr_summary_mail_editor_container" style="height:600px;"></div>
</div>
</div>
<div id="editor"></div>
<input type="file" id="Question_title_fileInput" style="display:none;">
</div>
</div> <!-- /.form-group -->
<div class="form-group text-right m-b-0 client_hr_summary_mail_action">
<button type="button" class="btn btn-primary waves-effect waves-light mr-1 preview_button">Preview</button>
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1" id="btnGridSubmit_2">Submit</button>
</div>
<div class="client_hr_summary_mail_preview"></div>
</form>
</div> <!-- /.modal-body -->
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
<!-- 7 Modal content for the Large example => CD balance insufficent HR mail sent -->
<div class="modal fade" id="hr_cd_insufficient_balance_mail_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
aria-hidden="true" aria-modal="true" data-backdrop="static">
<div class="modal-dialog modal-full-width">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel"> HR CD Insufficient Balance Mail <span id="nameOfThePolicy"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="text-center" id="no_data"></div>
<form role="form" class="parsley-examples" method="post" id="hr_cd_insufficient_balance_mail_form" enctype="multipart/form-data">
<div class="form-group">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="template_name">Template Name</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="template_name" name="template_name" value="HR CD Insufficient Balance Mail" readonly class="form-control" placeholder="Template Name">
</div>
</div>
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-2">
<label for="subject">Subject</label>
</div>
<div class="form-group col-md-5">
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject">
</div>
<div class="form-group col-md-5 testmail" style="display: none;">
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="testMailSend(this,'send')">Test Mail</a>
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="PreviewTheMail(this,'preview','client_hr_summary_mail')">Preview Mail</a>
</div>
</div>
<div class="hr_cd_insufficient_balance_mail_section">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
<select id="hr_cd_insufficient_balance_mail_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 (in_array($value, ['hr_name', 'client_name'])): ?>
<?php $valueChange = ucwords(str_replace('_',' ',$value)); ?>
<option value="{{<?php echo $value; ?>}}"><?php echo $valueChange; ?></option>
<?php endif; ?>
<?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">
<div id="hr_cd_insufficient_balance_mail_editor_container" style="height:600px;"></div>
</div>
</div>
<div id="editor"></div>
<input type="file" id="Question_title_fileInput" style="display:none;">
</div>
</div> <!-- /.form-group -->
<div class="form-group text-right m-b-0 hr_cd_insufficient_balance_mail_action">
<button type="button" class="btn btn-primary waves-effect waves-light mr-1 preview_button">Preview</button>
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1" id="btnGridSubmit_2">Submit</button>
</div>
<div class="hr_cd_insufficient_balance_mail_preview"></div>
</form>
</div> <!-- /.modal-body -->
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
<div class="modal fade" id="preview_modal" tabindex="-1" role="dialog" aria-hidden="false" aria-modal="true" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Testing Mail Data<span id="nameOfThePolicy"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="text-center" id="no_data"></div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- <script>
$(document).ready(function() {
const fileInput = document.getElementById("Question_title_fileInput");
fileInput.addEventListener("change", () => {
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const imageUrl = e.target.result;
editor.selection.insertImage(imageUrl);
};
reader.readAsDataURL(file);
}
fileInput.value = '';
});
})
function testMailSend(input) {
let test_mail = prompt("Please enter test mail:");
console.log('mail address:', test_mail);
if (test_mail !== null || test_mail !== "") {
if (isValidEmail(test_mail)) {
var template_id = $(input).data('id');
console.log('templte id', template_id);
if (template_id) {
let url = '<?= base_url('util/sentTestMail/') ?>' + template_id + '/' + test_mail;
console.log('testing mail url:', url);
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: url,
type: "GET",
dataType: 'json',
success: function(res) {
console.log('Test mail send function response', res)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (res.status == true) {
let respond = res.respond;
console.log('Parsed respond', respond)
if (respond.status == 'success') {
toastr.success(respond.message, 'Success')
} else {
toastr.warning(respond.message, 'Warning')
}
} else {
toastr.warning('Failed to sent mail', 'Warning')
}
},
error: function(xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.error(xhr.responseText);
console.error(status, error);
}
});
} else {
let alert_msg = 'Template ID not exist'
toastr.warning(alert_msg, 'Warning');
}
} else {
toastr.warning('Please enter the valid mail', 'Warning');
}
} else {
toastr.warning('Please enter the valid mail', 'Warning');
}
}
function isValidEmail(email) {
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return emailPattern.test(email);
}
function addHTMLInput(data = null) {
console.log('addHTMLInput function called');
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) {
$(container).empty();
data.forEach(item => {
const newRow = document.createElement('tr');
newRow.className = 'dynamic-form-row';
newRow.innerHTML = `
<td> ${item.file_name} </td>
<td> <a class="mdi mdi-delete" data-id="${item.id}" onclick="removeAttachment('${item.id}')"></a></td>
`;
container.appendChild(newRow);
});
// Creating another row for the form with file input
const newFormRow = document.createElement('tr');
newFormRow.className = 'dynamic-form-row';
newFormRow.innerHTML = `
<td>
<form class="ajax" onsubmit="submitAttachmentForm(event, this)">
<div class="form-row">
<div class="form-group col-3">
<input type="file" class="file-input__input" name="file" required>
</div>
<div class="form-group col-2">
<button type="submit" class="btn btn-sm btn-primary">Submit</button>
</div>
</div>
</form>
</td>
`;
container.appendChild(newFormRow);
} else {
// If no data is passed, create a new empty row
const newRow = document.createElement('tr');
newRow.className = 'dynamic-form-row';
newRow.innerHTML = `
<td>
<form class="ajax" onsubmit="submitAttachmentForm(event, this)">
<div class="form-row">
<div class="form-group col-3">
<input type="file" class="file-input__input" name="file" required>
</div>
<div class="form-group col-2">
<button type="submit" class="btn btn-sm btn-primary">Submit</button>
</div>
</div>
</form>
</td>
`;
container.appendChild(newRow);
}
}
function removeHTMLInput(element) {
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) {
const row = element.closest('.dynamic-form-row');
row.remove();
}
}
function submitAttachmentForm(event, form) {
event.preventDefault(); // Prevent the default form submission
// 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
if (!fileInput.files.length) {
toastr.warning("Please select a file to upload.");
return;
}
// Optional: Display a loading indicator
const submitButton = form.querySelector('button[type="submit"]');
submitButton.disabled = true;
submitButton.innerText = 'Uploading...';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
// AJAX request to upload the file
$.ajax({
url: '<?= base_url('client/notification/add_attachment') ?>', // Replace with your actual upload URL
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
console.log(response)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (response.status == true) {
toastr.success(response.message, 'Success');
addHTMLInput(response.data);
} else {
toastr.error(response.message, 'Error');
}
},
error: function(xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
// Handle error
console.error('Upload error occurred:');
console.error('Status: ', status); // Status of the request
console.error('Error: ', error); // Specific error message
console.error('XHR Object: ', xhr); // Full XHR object with response details
// Optionally log server response, if available
if (xhr.responseText) {
console.error('Response Text: ', xhr.responseText);
}
toastr.warning('Error uploading file', 'Warning');
console.error('Upload error:', error);
},
complete: function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
// Re-enable the submit button and reset its text
submitButton.disabled = false;
submitButton.innerText = 'Submit';
}
});
}
function removeAttachment(id) {
// var template_name = template_name
var client_id = $('#general_PrimaryKey').val();
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: '<?php echo base_url('client/notification/removeAttachment/'); ?>' + id + '/' + client_id + '/' + template_name,
type: "GET",
dataType: 'json',
success: function(res) {
console.log('removeAttachment response', res)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (res.status == true) {
toastr.success(res.message, 'Success')
addHTMLInput(res.data);
} else {
toastr.warning(res.message, 'Warning')
}
},
error: function(xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.error(xhr.responseText);
console.error(status, error);
}
});
}
</script> -->
<script>
// Global editor variable
let editor = null;
let template_name = '';
var activeParentModalId = null;
$(document).ready(function() {
const fileInput = document.getElementById("Question_title_fileInput");
fileInput.addEventListener("change", () => {
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const imageUrl = e.target.result;
editor.selection.insertImage(imageUrl);
};
reader.readAsDataURL(file);
}
fileInput.value = '';
});
})
// keep watching
function testMailSend(input,StringFlag) {
let test_mail = prompt("Please enter test mail:");
console.log('mail address:', test_mail);
if (test_mail !== null || test_mail !== "") {
if (isValidEmail(test_mail)) {
var template_id = $(input).data('id');
console.log('templte id', template_id);
if (template_id) {
// let url = '<?= base_url('util/sentTestMail/') ?>' + template_id + '/' + test_mail;
let url = '<?= base_url('util/sentTestMail/') ?>' + template_id + '/' + test_mail + '/'+StringFlag;
console.log('testing mail url:', url);
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: url,
type: "GET",
dataType: 'json',
success: function(res) {
console.log('Test mail send function response', res)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (res.status == true) {
let respond = res.respond;
console.log('Parsed respond', respond)
if (respond.status == 'success') {
toastr.success(respond.message, 'Success')
} else {
toastr.warning(respond.message, 'Warning')
}
} else {
toastr.warning('Failed to sent mail', 'Warning')
}
},
error: function(xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.error(xhr.responseText);
console.error(status, error);
}
});
} else {
let alert_msg = 'Template ID not exist , Kindly Save to Send Test Mails ..!!'
toastr.warning(alert_msg, 'Warning');
}
} else {
toastr.warning('Please enter the valid mail', 'Warning');
}
} else {
toastr.warning('Please enter the valid mail', 'Warning');
}
}
function sendCommonMails(){
// test mail list
let test_mail_list = $('#common_mail').val();
let test_mail = test_mail_list.split(',')[0] ?? ''; //REF:SVM
if (test_mail !== null || test_mail !== "") {
console.log("valid email or not");
console.log(test_mail);
test_mail = test_mail.replace(/\s+/g, '').trim();
console.log("is valid email check");
console.log(isValidEmail((test_mail)));
if (isValidEmail(test_mail)) {
var template_id = $('#notification_temp_id').val();
console.log("template_id");
console.log(template_id);
if (template_id) {
console.log("testmail ..!!");
console.log(test_mail);
let url = '<?= base_url('util/sendCommonTestMail') ?>';
console.log('testing mail url:', url);
$.ajax({
url: url,
type: "POST",
data:{
template_id,
test_mail_list,
},
dataType: 'json',
success: function(res) {
console.log('Test mail send function response', res);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (res.status === true) {
toastr.success(res.message, 'Success');
} else {
toastr.warning('Failed to send mail', 'Warning');
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
}
}
}
}
function isValidEmail(email) {
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return emailPattern.test(email);
}
function addHTMLInput(data = null) {
console.log(`:) addHTMLInput function called for ${template_name}`); // REF : PS
var container = '';
if (template_name == 'member_welcome_mail') {
container = document.getElementById('attachment_tbody');
}
else if (template_name == 'member_common_mail') {
container = document.getElementById('attachment_tbody_common');
}
else if (template_name == 'member_reminder_mail') {
container = document.getElementById('attachment_tbody_reminder');
}
else {
container = document.getElementById('attachment_tbody_ecard');
}
if (data) {
$(container).empty();
data.forEach(item => {
const newRow = document.createElement('tr');
newRow.className = 'dynamic-form-row';
newRow.innerHTML = `
<td> ${item.file_name} </td>
<td> <a class="mdi mdi-delete" data-id="${item.id}" onclick="removeAttachment('${item.id}')"></a></td>
`;
container.appendChild(newRow);
});
// Creating another row for the form with file input
const newFormRow = document.createElement('tr');
newFormRow.className = 'dynamic-form-row';
// newFormRow.innerHTML = `
// <td>
// <form class="ajax" onsubmit="submitAttachmentForm(event, this)">
// <div class="form-row">
// <div class="form-group col-3">
// <input type="file" class="file-input__input" name="file" required>
// </div>
// <div class="form-group col-2">
// <button type="submit" class="btn btn-sm btn-primary">Submit</button>
// </div>
// </div>
// </form>
// </td>
// `; // DONT DELETE IT REF : VVJ
newFormRow.innerHTML = `<td>
<form class="ajax" onsubmit="submitAttachmentForm(event, this)">
<div style="display:flex; align-items:center; gap:10px; white-space:nowrap;">
<div>
<input type="file" name="file"
style="width:100%; min-width:160px;
padding: 0 !important;
background-color: transparent !important;
border-radius: 0 !important;
box-shadow: none !important;
border-color: initial !important; color: white;">
</div>
<div>
<button type="submit" class="btn btn-sm btn-primary">Submit</button>
</div>
</div>
</form>
</td><td></td>`; // REF : PS
container.appendChild(newFormRow);
} else {
// If no data is passed, create a new empty row
const newRow = document.createElement('tr');
newRow.className = 'dynamic-form-row';
newRow.innerHTML = `<td><form class="ajax" onsubmit="submitAttachmentForm(event, this)">
<div style="display:flex; align-items:center; gap:10px; white-space:nowrap;">
<div>
<input type="file" name="file"
style="width:100%; min-width:160px;
padding: 0 !important;
background-color: transparent !important;
border-radius: 0 !important;
box-shadow: none !important;
border-color: initial !important; color: white;">
</div>
<div>
<button type="submit" class="btn btn-sm btn-primary">Submit</button>
</div>
</div>
</form>
</td><td></td>`; // REF : PS
// newRow.innerHTML = `
// <td>
// <form class="ajax" onsubmit="submitAttachmentForm(event, this)">
// <div class="form-row">
// <div class="form-group col-3">
// <input type="file" class="file-input__input" name="file" required>
// </div>
// <div class="form-group col-2">
// <button type="submit" class="btn btn-sm btn-primary">Submit</button>
// </div>
// </div>
// </form>
// </td>
// `; // DONT DELETE IT REF : VVJ
container.appendChild(newRow);
}
}
function removeHTMLInput(element) {
if (template_name == 'member_welcome_mail') {
const container = document.getElementById('attachment_tbody');
}
else if (template_name == 'member_common_mail') {
container = document.getElementById('attachment_tbody_common');
}
else if (template_name == 'member_reminder_mail') {
container = document.getElementById('attachment_tbody_reminder');
}
else {
const container = document.getElementById('attachment_tbody_ecard');
}
const rows = container.querySelectorAll('.dynamic-form-row');
if (rows.length > 1) {
const row = element.closest('.dynamic-form-row');
row.remove();
}
}
function submitAttachmentForm(event, form) {
event.preventDefault(); // Prevent the default form submission
// var template_name = template_name;
var client_id = $('#general_PrimaryKey').val();
// console.log(client_id);
console.log(`:) Submitted for ${template_name}`);
const formData = new FormData(form);
formData.append('template_name', template_name);
formData.append('client_id', client_id);
const fileInput = form.querySelector('input[type="file"]');
// Check if a file is selected
if (!fileInput.files.length) {
toastr.warning("Please select a file to upload.");
return;
}
// Optional: Display a loading indicator
const submitButton = form.querySelector('button[type="submit"]');
submitButton.disabled = true;
submitButton.innerText = 'Uploading...';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
// AJAX request to upload the file
$.ajax({
url: '<?= base_url('client/notification/add_attachment') ?>', // Replace with your actual upload URL
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
console.log(response)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (response.status == true) {
toastr.success(response.message, 'Success');
addHTMLInput(response.data);
} else {
toastr.error(response.message, 'Error');
}
},
error: function(xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
// Handle error
console.error('Upload error occurred:');
console.error('Status: ', status); // Status of the request
console.error('Error: ', error); // Specific error message
console.error('XHR Object: ', xhr); // Full XHR object with response details
// Optionally log server response, if available
if (xhr.responseText) {
console.error('Response Text: ', xhr.responseText);
}
toastr.warning('Error uploading file', 'Warning');
console.error('Upload error:', error);
},
complete: function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
// Re-enable the submit button and reset its text
submitButton.disabled = false;
submitButton.innerText = 'Submit';
}
});
}
function removeAttachment(id) {
// var template_name = template_name
var client_id = $('#general_PrimaryKey').val();
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: '<?php echo base_url('client/notification/removeAttachment/'); ?>' + id + '/' + client_id + '/' + template_name,
type: "GET",
dataType: 'json',
success: function(res) {
console.log('removeAttachment response', res)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (res.status == true) {
toastr.success(res.message, 'Success')
addHTMLInput(res.data);
} else {
toastr.warning(res.message, 'Warning')
}
},
error: function(xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.error(xhr.responseText);
console.error(status, error);
}
});
}
// Function to check if unlayer is loaded and available
function isUnlayerLoaded() {
return typeof unlayer !== 'undefined' && unlayer !== null;
}
// Enhanced waiting function with better error handling
function waitForUnlayer(callback, maxAttempts = 20) {
let attempts = 0;
const checkUnlayer = setInterval(function() {
attempts++;
console.log("Checking for Unlayer, attempt:", attempts);
if (isUnlayerLoaded()) {
clearInterval(checkUnlayer);
console.log("Unlayer loaded successfully");
callback(true);
} else if (attempts >= maxAttempts) {
clearInterval(checkUnlayer);
console.error("Unlayer failed to load after", attempts, "attempts");
callback(false);
}
}, 1000); // Increased interval to 1 second
}
// Improved editor initialization function
function initializeEditor(callback) {
console.log("Starting editor initialization...");
const editorContainer = document.getElementById(`${template_name}_editor_container`);
if (!editorContainer) {
console.error("Editor container not found");
if (callback) callback(null);
return;
}
// Ensure the script is loaded
if (!document.querySelector('script[src*="unlayer"]')) {
console.error("Unlayer script is not included in the page");
if (callback) callback(null);
return;
}
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
waitForUnlayer(function(unlayerLoaded) {
if (!unlayerLoaded) {
console.error("Unlayer not available");
if (callback) callback(null);
return;
}
try {
// Destroy existing instance if it exists
if (editor) {
console.log("Destroying existing editor...");
editor.destroy();
editor = null;
}
// Clear the container
editorContainer.innerHTML = '';
// Create new editor instance with error handling
console.log("Creating new editor instance...");
editor = unlayer.createEditor({
id: `${template_name}_editor_container`,
projectId: <?= getenv('unlayer.projectID') ?>,
displayMode: "email",
features: {
textEditor: {
tables: true
},
preview: {
enabled: true,
deviceOptions: ['desktop', 'mobile']
},
preview: {
enabled: true
},
imageEditor: {
enabled: true
},
appearance: {
theme: 'light',
panels: {
tools: {
dock: "right"
}
}
}
},
branding: false,
tools: {
// Configure any specific tools you need
text: {
enabled: true
},
image: {
enabled: true
}
}
});
// Verify editor initialization
if (!editor || typeof editor.loadDesign !== 'function') {
throw new Error("Editor initialization failed - editor instance is invalid");
}
console.log("Editor initialization completed successfully");
$('.loader').fadeOut();
$('.loader-mask').fadeOut();
if (callback) callback(editor);
} catch (error) {
console.error("Error in editor initialization:", error);
if (callback) callback(null);
$('.loader').fadeOut();
$('.loader-mask').fadeOut();
}
});
}
// Modified template data function with better error handling
function getMailTemplateData(element) {
template_name = element.id;
const validTemplates = [
"account_maneger_summary_mail",
"member_reminder_mail",
"member_common_mail",
"member_ecard_mail",
"member_welcome_mail",
"member_review_and_summary_mail",
"client_hr_summary_mail",
"hr_cd_insufficient_balance_mail"
];
console.log(`:) getMailTemplateData function called for ${template_name}`); // REF : PS
if (!validTemplates.includes(template_name)) {
console.error("Invalid template name:", template_name);
return;
}
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
const primaryKey = $('#general_PrimaryKey').val();
const baseUrl = '<?= base_url("client/notification/getMailTemplateData/") ?>';
const form_action = `${baseUrl}${template_name}/${primaryKey}`;
$.ajax({
url: form_action,
type: "GET",
dataType: 'json',
success: function(res) {
console.log(':) getMailTemplateData Resp are', res);
if (res) {
// Set subject
$(`#${template_name}_form #subject`).val(res.subject || '');
// Initialize editor with retry mechanism
let retryCount = 0;
const initWithRetry = function() {
initializeEditor(function(editorInstance) {
if (!editorInstance && retryCount < 3) {
console.log(`Retrying editor initialization (${retryCount + 1}/3)...`);
retryCount++;
setTimeout(initWithRetry, 1000);
return;
}
if (!editorInstance) {
console.error("Editor initialization failed after retries");
toastr.error('Editor initialization failed. Please refresh the page.');
return;
}
if (res.mail_content_json) {
try {
const design = JSON.parse(res.mail_content_json);
editorInstance.loadDesign(design);
console.log("Design loaded successfully");
hideBranding();
} catch (error) {
console.error("Error parsing mail content JSON:", error);
toastr.error('Error loading email template');
}
} else {
hideBranding()
}
});
};
initWithRetry();
if (res.data) {
addHTMLInput(res.data);
} else {
addHTMLInput();
}
// Update UI elements
$('.testmail').toggle(!!res.id);
$('#attachment_table').toggle(!!res.id);
$('#attachment_table_ecard').toggle(!!res.id);
$('#attachment_table_common').toggle(!!res.id);
$('#attachment_table_reminder').toggle(!!res.id);
$('.setid').attr('data-id', res.id || '');
if (template_name == "member_common_mail"){
$('#notification_temp_id').val(res.id);
}
}
else{
console.log("Inside else");
let retryCount = 0;
const initWithRetry = function() {
initializeEditor(function(editorInstance) {
if (!editorInstance && retryCount < 3) {
console.log(`Retrying editor initialization (${retryCount + 1}/3)...`);
retryCount++;
setTimeout(initWithRetry, 1000);
return;
}
if (!editorInstance) {
console.error("Editor initialization failed after retries");
toastr.error('Editor initialization failed. Please refresh the page.');
return;
}
hideBranding();
});
};
initWithRetry();
}
if(res.comman_mails != ""){
console.log("common mails recieved here ........!!!!!!!!!!!");
console.log(res);
$('#common_mail').val(res.comman_mails);
}
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error("Ajax error:", {
status,
error,
response: xhr.responseText
});
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.error('Failed to load template data');
}
});
}
$('#account_maneger_summary_mail_form').submit(function(event) {
event.preventDefault();
// Check if editor instance exists
if (!editor) {
console.error("Editor not initialized");
toastr.error("Editor not ready. Please try again.");
return;
}
// Use the editor instance instead of unlayer directly
editor.exportHtml(function(data) {
var formData = new FormData($('#account_maneger_summary_mail_form')[0]);
// Append Unlayer data
formData.append('mailContent', data.html);
formData.append('client_id', $('#general_PrimaryKey').val());
formData.append('mailJson', JSON.stringify(data.design));
console.log([...formData.entries()]);
// Show loading indicators
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var form_action = '<?= base_url("client/notification/create") ?>';
$.ajax({
url: form_action,
type: "POST",
data: formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('#account_maneger_summary_mail_modal').find('.close').click();
toastr.success('Template saved successfully');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Went Wrong!', 'Warning');
}, 1000);
}
});
});
});
$('#member_welcome_mail_form').submit(function(event) {
event.preventDefault();
// Check if editor instance exists
if (!editor) {
console.error("Editor not initialized");
toastr.error("Editor not ready. Please try again.");
return;
}
// Use the editor instance instead of unlayer directly
editor.exportHtml(function(data) {
var formData = new FormData($('#member_welcome_mail_form')[0]);
// Append Unlayer data
formData.append('mailContent', data.html);
formData.append('client_id', $('#general_PrimaryKey').val());
formData.append('mailJson', JSON.stringify(data.design));
console.log([...formData.entries()]);
// Show loading indicators
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var form_action = '<?= base_url("client/notification/create") ?>';
$.ajax({
url: form_action,
type: "POST",
data: formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('#member_welcome_mail_modal').find('.close').click();
toastr.success('Template saved successfully');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Went Wrong!', 'Warning');
}, 1000);
}
});
});
});
$('#member_reminder_mail_form').submit(function(event) {
event.preventDefault();
// Check if editor instance exists
if (!editor) {
console.error("Editor not initialized");
toastr.error("Editor not ready. Please try again.");
return;
}
// Use the editor instance instead of unlayer directly
editor.exportHtml(function(data) {
var formData = new FormData($('#member_reminder_mail_form')[0]);
// Append Unlayer data
formData.append('mailContent', data.html);
formData.append('client_id', $('#general_PrimaryKey').val());
formData.append('mailJson', JSON.stringify(data.design));
console.log([...formData.entries()]);
// Show loading indicators
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var form_action = '<?= base_url("client/notification/create") ?>';
$.ajax({
url: form_action,
type: "POST",
data: formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('#member_reminder_mail_modal').find('.close').click();
toastr.success('Template saved successfully');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Went Wrong!', 'Warning');
}, 1000);
}
});
});
});
$('#member_ecard_mail_form').submit(function(event) {
event.preventDefault();
// Check if editor instance exists
if (!editor) {
console.error("Editor not initialized");
toastr.error("Editor not ready. Please try again.");
return;
}
// Use the editor instance instead of unlayer directly
editor.exportHtml(function(data) {
var formData = new FormData($('#member_ecard_mail_form')[0]);
// Append Unlayer data
formData.append('mailContent', data.html);
formData.append('client_id', $('#general_PrimaryKey').val());
formData.append('mailJson', JSON.stringify(data.design));
console.log([...formData.entries()]);
// Show loading indicators
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var form_action = '<?= base_url("client/notification/create") ?>';
$.ajax({
url: form_action,
type: "POST",
data: formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('#member_ecard_mail_modal').find('.close').click();
toastr.success('Template saved successfully');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Went Wrong!', 'Warning');
}, 1000);
}
});
});
});
$('#member_common_mail_form').submit(function(event) {
event.preventDefault();
// Check if editor instance exists
if (!editor) {
console.error("Editor not initialized");
toastr.error("Editor not ready. Please try again.");
return;
}
// Use the editor instance instead of unlayer directly
editor.exportHtml(function(data) {
var formData = new FormData($('#member_common_mail_form')[0]);
// Append Unlayer data
formData.append('mailContent', data.html);
formData.append('client_id', $('#general_PrimaryKey').val());
formData.append('mailJson', JSON.stringify(data.design));
console.log([...formData.entries()]);
// Show loading indicators
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var form_action = '<?= base_url("client/notification/create") ?>';
$.ajax({
url: form_action,
type: "POST",
data: formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('#member_common_mail_modal').find('.close').click();
toastr.success('Template saved successfully');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Went Wrong!', 'Warning');
}, 1000);
}
});
});
});
$('#member_review_and_summary_mail_form').submit(function(event) {
event.preventDefault();
// Check if editor instance exists
if (!editor) {
console.error("Editor not initialized");
toastr.error("Editor not ready. Please try again.");
return;
}
// Use the editor instance instead of unlayer directly
editor.exportHtml(function(data) {
var formData = new FormData($('#member_review_and_summary_mail_form')[0]);
// Append Unlayer data
formData.append('mailContent', data.html);
formData.append('client_id', $('#general_PrimaryKey').val());
formData.append('mailJson', JSON.stringify(data.design));
console.log([...formData.entries()]);
// Show loading indicators
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var form_action = '<?= base_url("client/notification/create") ?>';
$.ajax({
url: form_action,
type: "POST",
data: formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('#member_review_and_summary_mail_modal').find('.close').click();
toastr.success('Template saved successfully');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Went Wrong!', 'Warning');
}, 1000);
}
});
});
});
$('#client_hr_summary_mail_form').submit(function(event) {
event.preventDefault();
// Check if editor instance exists
if (!editor) {
console.error("Editor not initialized");
toastr.error("Editor not ready. Please try again.");
return;
}
// Use the editor instance instead of unlayer directly
editor.exportHtml(function(data) {
var formData = new FormData($('#client_hr_summary_mail_form')[0]);
// Append Unlayer data
formData.append('mailContent', data.html);
formData.append('client_id', $('#general_PrimaryKey').val());
formData.append('mailJson', JSON.stringify(data.design));
console.log([...formData.entries()]);
// Show loading indicators
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var form_action = '<?= base_url("client/notification/create") ?>';
$.ajax({
url: form_action,
type: "POST",
data: formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('#client_hr_summary_mail_modal').find('.close').click();
toastr.success('Template saved successfully');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Went Wrong!', 'Warning');
}, 1000);
}
});
});
});
$('#hr_cd_insufficient_balance_mail_form').submit(function(event) {
event.preventDefault();
// Check if editor instance exists
if (!editor) {
console.error("Editor not initialized");
toastr.error("Editor not ready. Please try again.");
return;
}
// Use the editor instance instead of unlayer directly
editor.exportHtml(function(data) {
var formData = new FormData($('#hr_cd_insufficient_balance_mail_form')[0]);
// Append Unlayer data
formData.append('mailContent', data.html);
formData.append('client_id', $('#general_PrimaryKey').val());
formData.append('mailJson', JSON.stringify(data.design));
console.log([...formData.entries()]);
// Show loading indicators
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var form_action = '<?= base_url("client/notification/create") ?>';
$.ajax({
url: form_action,
type: "POST",
data: formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('#client_hr_summary_mail_modal').find('.close').click();
toastr.success('Template saved successfully');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Went Wrong!', 'Warning');
}, 1000);
}
});
});
});
function hideBranding() {
$('iframe').on('load', function() {
console.log('Iframe loaded.');
const iframe = $(this);
// Overlay the branding area
const overlay = $('<div>', {
css: {
position: 'absolute',
bottom: '0', // Adjust based on branding position
left: '0',
width: iframe.width(),
height: '30px', // Adjust height to cover branding
backgroundColor: 'white',
zIndex: '9999',
pointerEvents: 'none',
},
});
const iframeParent = iframe.parent();
if (iframeParent.css('position') === 'static') {
iframeParent.css('position', 'relative');
}
iframeParent.append(overlay);
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);
});
}
}
$(document).on('click', '#notification_enable_form_submit', function() {
var formData = [];
console.log($('#hr_mail_id').val());
formData.push({
name: 'client_id',
value: $('#general_PrimaryKey').val()
})
formData.push({
name: 'nhance_team_mail_ids',
value: $('#nhance_team_mail_ids').val()
});
formData.push({
name: 'hr_mail_id',
value: $('#hr_mail_id').val()
});
formData.push({
name: 'mail_domain',
value: $('#mail_domain').val()
});
formData.push({
name: 'reply_to',
value: $('#reply_to').val()
});
formData.push({
name: 'member_welcome_mail_btn',
value: $('#member_welcome_mail_btn').prop('checked')
});
formData.push({
name: 'member_reminder_mail_btn',
value: $('#member_reminder_mail_btn').prop('checked')
});
formData.push({
name: 'member_ecard_mail_btn',
value: $('#member_ecard_mail_btn').prop('checked')
});
formData.push({
name: 'member_common_mail_btn',
value: $('#member_common_mail_btn').prop('checked')
});
formData.push({
name: 'member_review_and_summary_mail_btn',
value: $('#member_review_and_summary_mail_btn').prop('checked')
});
formData.push({
name: 'account_maneger_summary_mail_btn',
value: $('#account_maneger_summary_mail_btn').prop('checked')
});
formData.push({
name: 'client_hr_summary_mail_btn',
value: $('#client_hr_summary_mail_btn').prop('checked')
});
formData.push({
name: 'hr_cd_insufficient_balance_mail_btn',
value: $('#hr_cd_insufficient_balance_mail_btn').prop('checked')
});
var form_action = '<?= base_url("client/notification/update_enable") ?>';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: form_action,
type: "POST",
data: formData,
dataType: 'json',
success: function(res) {
if (res.status == true) {
toastr.success('Update Successfully');
}
if (res.status == false) {
let empty_templates = res.empty_templates.join(", ");
toastr.warning(`Updation Failed. The following templates were empty: ${empty_templates}`);
}
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Wrong!', 'Warning');
}, 1000);
}
});
})
function PreviewTheMail(button, StringFlag,className) {
let $btn = $(button);
let $formSection = $('.' + className + '_section');
let $actionButtons = $('.' + className + '_action');
let $previewSection= $('.' + className + '_preview');
console.log(":/");
console.log($formSection, $actionButtons, $previewSection);
// let $formSection = $('.client_hr_summary_mail_section');
// let $actionButtons = $('.client_hr_summary_mail_action');
// let $previewSection = $('.client_hr_summary_mail_preview');
// 2nd click → Close preview
if ($btn.data('previewing')) {
$formSection.show();
$actionButtons.show();
$previewSection.hide();
$btn.text('Preview Mail');
$btn.data('previewing', false);
return;
}
// 1st click → Open preview
let template_id = $btn.data('id');
let test_mail = "xyz@gmail.com";
if(!template_id){
toastr.warning('Template ID not exist', 'Warning');
return;
}
let url = '<?= base_url('util/sentTestMail/') ?>' + template_id + '/' + test_mail + '/' + StringFlag;
$('.loader, .loader-mask').fadeIn();
$.ajax({
url: url,
type: "GET",
dataType: 'json',
success: function(res){
$('.loader, .loader-mask').fadeOut();
if(res.status){
let content = res.content || "No Data Found";
$previewSection.html(content.message);
$formSection.hide();
$actionButtons.hide();
$previewSection.show();
$btn.text('Close Preview');
$btn.data('previewing', true);
} else {
toastr.warning('Failed to load content', 'Warning');
}
},
error: function(xhr){
$('.loader, .loader-mask').fadeOut();
console.error(xhr.responseText);
}
});
}
</script>