nhance/app/Views/non_eb_claim_mail_template.php
2026-04-16 15:28:06 +05:30

323 lines
17 KiB
PHP

<style>
.table th, .table td { padding: 8px; }
table.dataTable tbody td { padding: 4px 4px !important; }
.dataTables_filter { position: absolute; }
.addbtnStyle { margin-left: 20px !important; color: #000; }
.jodit-container .jodit-wysiwyg, .jodit-container .jodit-wysiwyg * { color: #000 !important; background-color: #fff !important; }
.dataTables_length label { height: 21px !important; }
</style>
<script>
var pageHideMainNavTitle = true;
var pageTitle = 'Non-EB Mail Templates';
</script>
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row" style="padding-bottom: 10px;">
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">Mail Template List</h4>
</div>
</div>
<div class="table-responsive">
<table data-custom-table-css="table" id="noneb-mail-template-table" class="table w-100 nowrap">
<thead class="bg-light">
<tr>
<th>Template Name</th>
<th>Policy Type</th>
<th>Trigger Type</th>
<th>Mail Send Type</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (isset($ticket_data)): foreach ($ticket_data as $row): ?>
<tr>
<td>
<?= $row['template_name'] ?? '' ?>&nbsp;
<i class="fe-alert-circle" style="color:#000;" data-toggle="tooltip" data-placement="top" title="Status: <?= $row['tool_tip'] ?? '' ?>"></i>
</td>
<td>
<?php
$ptName = '';
if (isset($policy_types)) {
foreach ($policy_types as $pt) {
if ($pt['id'] == $row['ticket_type']) { $ptName = $pt['policy_type']; break; }
}
}
echo $ptName;
?>
</td>
<td><?= $trigger_type[$row['trigger_type']] ?? '' ?></td>
<td><?= $row['is_auto_mail'] == 1 ? 'Auto' : 'Manual' ?></td>
<td>
<div class="btn-group dropdown">
<a href="javascript:void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown"><i class="mdi mdi-dots-horizontal"></i></a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#" onclick="getMailTemplateData(<?= $row['id'] ?>)"><i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<a class="dropdown-item" onclick="deleteTemplate(<?= $row['id'] ?>)"><i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete</a>
</div>
</div>
</td>
</tr>
<?php endforeach; endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Add/Edit Template Modal -->
<div class="modal fade" id="new_mail_template" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog modal-full-width">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add New Template</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
</div>
<div class="modal-body">
<form role="form" method="post" id="ticket_mail_editor_modal" enctype="multipart/form-data" novalidate>
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">
<label>Template Name</label>
<input type="text" id="template_name" name="template_name" class="form-control" placeholder="Template Name" required>
</div>
<div class="form-group col-md-3">
<label>Policy Type</label>
<select class="form-control" id="policy_type" name="ticket_type" required>
<option value="">Select Policy Type</option>
<?php if (isset($policy_types)): foreach ($policy_types as $pt): ?>
<option value="<?= $pt['id'] ?>"><?= $pt['policy_type'] ?></option>
<?php endforeach; endif; ?>
</select>
</div>
<div class="form-group col-md-3">
<label>Trigger Type</label>
<select class="form-control" id="trigger_type" name="trigger_type" required>
<option value="">Select Trigger</option>
<?php if (isset($trigger_type)): foreach ($trigger_type as $k => $v): ?>
<option value="<?= $k ?>"><?= $v ?></option>
<?php endforeach; endif; ?>
</select>
<input id="primaryKey" type="hidden">
</div>
<div class="form-group col-md-2">
<div id="statusSwitchWrapper" class="dt-switch-wrapper" style="padding-top:40px;padding-left:10px;">
<div class="custom-control custom-switch" style="text-align:left;">
<input type="checkbox" class="custom-control-input" id="statusSwitch">
<label class="custom-control-label" for="statusSwitch">Auto Mail</label>
</div>
</div>
</div>
<div class="form-group col-md-6">
<label>Claim Status</label>
<input type="text" readonly id="claim_status_for_template" class="form-control">
</div>
<div class="form-group col-md-6">
<label>Subject</label>
<input type="text" id="template_subject" name="subject" class="form-control" placeholder="Subject" required>
</div>
</div>
<hr>
<div class="form-row">
<div class="form-group col-md-12">
<div class="form-row" id="rac_rate_dropdown">
<div class="form-group col-md-12">
<select id="ticket_mail_customButton" class="form-control" style="border:none;right:6px;width:auto;position:absolute;z-index:1;top:17px;height:32px;float:right;">
<option value="">PlaceHolders</option>
<?php foreach ($placeHolders as $key => $value): ?>
<?php $valueChange = ucwords(str_replace('_', ' ', $value)); ?>
<option value="<?= $key ?>"><?= $valueChange ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div id="ticket_mail_editor" name="content" style="height: 300px;"></div>
</div>
</div>
<div class="form-group text-right m-b-0">
<button type="submit" class="btn btn-primary" id="btnGridSubmit_2">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
var ticketsTable = $('#noneb-mail-template-table');
if (ticketsTable.length) {
ticketsTable.DataTable({
scrollX: true,
dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'B>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
buttons: [{
text: 'Add Template',
className: 'buttons-html5 addbtnStyle',
action: function() { openModal(); }
}],
language: {
search: '<div class="datatable-search-wrapper" style="position:relative;display:inline-block;">_INPUT_<i class="mdi mdi-magnify datatable-search-icon" style="position:absolute;right:10px;top:50%;transform:translateY(-50%);color:#666;"></i></div>',
searchPlaceholder: "Search",
emptyTable: '<div class="text-center text-muted">No Data found</div>'
},
paging: true, pageLength: 10, ordering: false,
});
}
var toolbar = "bold,italic,strikethrough,|,superscript,subscript,|,align,";
const editorConfig = {
buttons: toolbar.concat(['fontsize']),
fontsize: [8, 10, 12, 14, 16, 18, 20, 22, 24],
showPlaceholder: false,
toolbarButtonSize: 'small',
toolbarAdaptive: false,
saveHeightInStorage: true,
minHeight: 400,
defaultStyle: { color: '#000000' },
};
const editor = Jodit.make("#ticket_mail_editor", editorConfig);
let lastActiveField = null;
$("#template_subject").on("focus", function() { lastActiveField = this; });
editor.events.on("focus", function() { lastActiveField = editor; });
document.addEventListener('change', function(event) {
var target = event.target;
if (target.matches('#ticket_mail_customButton')) {
let placeholderValue = $(target).val();
if (!placeholderValue) return;
if (lastActiveField) {
if (lastActiveField.id === "template_subject") {
let input = lastActiveField;
let startPos = input.selectionStart;
let endPos = input.selectionEnd;
input.value = input.value.substring(0, startPos) + placeholderValue + input.value.substring(endPos);
input.selectionStart = input.selectionEnd = startPos + placeholderValue.length;
} else {
editor.selection.insertHTML(placeholderValue);
}
}
$(target).val('');
}
});
$('.close').click(function() {
$('#template_subject').val('');
$('#template_name').val('');
$('#primaryKey').val('');
$('#policy_type').val('').change();
$('#trigger_type').val('').change();
$("#claim_status_for_template").val("");
editor.setEditorValue('');
$('#statusSwitch').prop('checked', false);
});
// Submit template
$('#ticket_mail_editor_modal').submit(function(event) {
event.preventDefault();
let isValid = true;
$('#ticket_mail_editor_modal [required]').each(function() {
if (!this.value.trim()) { isValid = false; $(this).addClass('is-invalid'); } else { $(this).removeClass('is-invalid'); }
});
if (!isValid) { toastr.error('Please fill all required fields.', 'Validation Error'); return; }
var joditEditor = editor;
if (joditEditor) {
var mailContent = $(joditEditor.currentPlace.container).find('.jodit-wysiwyg').html();
var formData = $(this).serializeArray();
formData.push({ name: 'mail_content', value: mailContent });
var isAutoMailEnabled = $('#statusSwitch').is(':checked') ? 1 : 0;
formData.push({ name: 'is_auto_mail', value: isAutoMailEnabled });
var primary_key = $('#primaryKey').val();
if (primary_key) { formData.push({ name: 'id', value: primary_key }); }
$('.loader').fadeIn(); $('.loader-mask').fadeIn();
var form_action = '<?= base_url("non-eb-claim/crud_mail_template/1") ?>';
$.ajax({
url: form_action, type: "POST", data: formData, dataType: 'json',
success: function(res) {
if (res.status == true) {
$('#new_mail_template').find('.close').click();
toastr.success('Template saved successfully!', 'Success');
location.reload();
} else { toastr.error('Failed to Save Data', 'Error'); }
$('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr) {
$('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow');
if (xhr.status === 400) {
let response = JSON.parse(xhr.responseText);
if (response.errors) {
let msgs = ""; $.each(response.errors, function(f, m) { msgs += '• ' + m + '<br>'; });
toastr.error(msgs, 'Validation Error', { "allowHtml": true });
} else { toastr.warning(response.message || 'Validation failed'); }
} else { toastr.error('Something went wrong.', 'Error'); }
}
});
}
});
});
function openModal() {
var myModal = new bootstrap.Modal(document.getElementById('new_mail_template'));
myModal.show();
}
function deleteTemplate(id) {
Swal.fire({
title: "Are you sure?", text: "You want to remove this template.", icon: "info",
showCancelButton: true, confirmButtonColor: "#3085d6", confirmButtonText: "Yes",
}).then((result) => {
if (result.isConfirmed) {
$('.loader').fadeIn(); $('.loader-mask').fadeIn();
$.ajax({
url: '<?= base_url("non-eb-claim/crud_mail_template/3") ?>', type: "POST", data: { id: id },
success: function(res) {
if (res.status === true) { location.reload(); toastr.success('Template Deleted!', 'Success'); }
else { toastr.error('Failed to Delete Template', 'Error'); }
$('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow');
},
error: function() {
$('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow');
toastr.error('Something went wrong!', 'Error');
}
});
}
});
}
function getMailTemplateData(id) {
$('.loader').fadeIn(); $('.loader-mask').fadeIn();
$.ajax({
url: '<?= base_url("non-eb-claim/crud_mail_template/2") ?>', type: "POST", data: { id: id },
success: function(res) {
if (res && res.status == true) {
openModal();
$('#template_subject').val(res.data.subject);
$('#template_name').val(res.data.template_name);
$('#primaryKey').val(res.data.id);
$('#policy_type').val(res.data.ticket_type).change();
$('#trigger_type').val(res.data.trigger_type).change();
$('#claim_status_for_template').val(res.data.tool_tip);
$('.jodit-wysiwyg').html(res.data.mail_content);
$('#statusSwitch').prop('checked', res.data.is_auto_mail == 1);
} else { toastr.error('Data Not Found', 'Error'); }
$('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow');
},
error: function() {
$('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something Went Wrong!', 'Warning');
}
});
}
</script>