nhance/app/Views/ticket_reply.php

217 lines
9.3 KiB
PHP

<div class="row">
<div class="col-12">
<div class="card-body">
<form role="form" class="parsley-examples" method="post" id="ticket_reply_form" enctype="multipart/form-data">
<div class="form-group">
<div class="form-row">
<!-- Email To Field -->
<div class="form-group col-md-4">
<label for="emp_mail_for_to">To</label>
<input type="text" value="<?= isset($ticket_data['emp_mail'])?$ticket_data['emp_mail']:'' ?>" class="form-control" id="emp_mail_for_to" name="emp_mail" placeholder="Recipient email" readonly>
</div>
<!-- Subject Field -->
<div class="form-group col-md-8">
<label for="mail_subject">Subject</label>
<input type="text" class="form-control" value="<?= isset($reply_data['subject'])?$reply_data['subject']:'' ?>" id="mail_subject" name="mail_subject" placeholder="Mail subject">
</div>
<!-- Mail Content Field -->
<div class="form-group col-md-12">
<!-- <textarea class="form-control" rows="5" placeholder="Enter Mail Content"></textarea> -->
<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 // if($value == 'member_name' || $value == 'member_mobile' || $value == 'nhance_logo' || $value == 'client_logo' || $value == 'app_link' || $value == 'client_name'){ ?>member_mobile -->
<?php $valueChange = str_replace('_', ' ', $value); $valueChange = ucwords($valueChange); ?>
<option value="<?php echo $key; ?>"><?php echo $valueChange; ?></option>
<?php //} ?>
<?php endforeach; ?>
</select>
</div>
</div>
<div id="ticket_mail_editor" name="content" style="height: 300px;"></div>
</div>
</div><input type="hidden" id="claim_status" name="claim_status" value="<?= isset($reply_data['claim_status_id'])??'' ?>">
</div>
<!-- Submit Button -->
<div class="form-group text-right">
<button type="submit" class="btn btn-primary" id="ticket_reply_submit">Send Mail</button>
</div>
</form>
</div>
</div>
</div>
<script>
var toolbar = "bold,italic,strikethrough,|,superscript,subscript,|,align,";
const editorConfig = {
buttons: toolbar.concat(['fontsize']),
fontsize: [8, 10, 12, 14, 16, 18, 20, 22, 24], // Customize font sizes
showPlaceholder: false,
toolbarButtonSize: 'small',
toolbarAdaptive: false,
saveHeightInStorage: true,
minHeight: 400,
extraButtons: [
{
name: 'info',
iconURL: '<?= base_url()."public"; ?>/assets/images/image-solid.svg', // Replace with the actual icon URL
exec: function (editor) {
const fileInput = document.getElementById("Question_title_fileInput");
fileInput.click();
},
},
],
};
$(document).ready(function() {
var toolbar = "bold,italic,strikethrough,|,superscript,subscript,|,align,";
const editorConfig = {
buttons: toolbar.concat(['fontsize']),
fontsize: [8, 10, 12, 14, 16, 18, 20, 22, 24], // Customize font sizes
showPlaceholder: false,
toolbarButtonSize: 'small',
toolbarAdaptive: false,
saveHeightInStorage: true,
minHeight: 400,
extraButtons: [
{
name: 'info',
iconURL: '<?= base_url()."public"; ?>/assets/images/image-solid.svg', // Replace with the actual icon URL
exec: function (editor) {
const fileInput = document.getElementById("Question_title_fileInput");
fileInput.click();
},
},
],
};
const editor = Jodit.make("#ticket_mail_editor", editorConfig);
var mail_content = `<?=isset($reply_data['mail_content'])?$reply_data['mail_content']:'' ?>`;
// console.log(mail_content);
if (editor) {
editor.value = mail_content;
}
// $('.jodit-wysiwyg').html(mail_content);
let lastActiveField = null;
// Track last active input field
$("#mail_subject").on("focus", function() {
lastActiveField = this;
});
// Track Jodit editor focus separately
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 === "mail_subject") {
insertAtCursor(lastActiveField, placeholderValue);
} else {
editor.selection.insertHTML(placeholderValue);
}
}
$(target).val('');
}
});
function insertAtCursor(input, textToInsert) {
if (document.selection) {
input.focus();
var sel = document.selection.createRange();
sel.text = textToInsert;
} else if (input.selectionStart || input.selectionStart === 0) {
let startPos = input.selectionStart;
let endPos = input.selectionEnd;
input.value = input.value.substring(0, startPos) + textToInsert + input.value.substring(endPos, input.value.length);
input.selectionStart = input.selectionEnd = startPos + textToInsert.length;
} else {
input.value += textToInsert;
}
}
$("#ticket_reply_form").submit(function(event) {
event.preventDefault();
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 });
// formData.push({ name: 'client_id', value: $('#general_PrimaryKey').val() });
// var isAutoMailEnabled = $('#statusSwitch').is(':checked') ? 1 : 0;
// formData.push({ name: 'is_auto_mail', value: isAutoMailEnabled });
var ticket_id = $('#ticket_master_id').val();
if (ticket_id != null && ticket_id != ''){
formData.push({ name: 'ticket_id', value: ticket_id});
}
// console.log(formData);
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var form_action = '<?= base_url("/ticket/reply"); ?>';
$.ajax({
url: form_action,
type: "POST",
data: formData,
dataType: 'json',
success: function(res)
{
if(res.status == true){
// $('#new_mail_template').find('.close').click();
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.success('Message Sent successfully!', 'Success');
reloadTicket_conversation();
}else if (res.status == false){
toastr.error('Failed to Send Message', 'error');
}
},
error: function (xhr, status, error)
{
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function()
{
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.error('Something Wrong!', 'warning');
}, 1000);
}
});
}
else
{
console.error("Jodit editor instance is not defined.");
}
});
});
</script>
<script>
function reloadTicket_conversation() {
$("#ticket_messages_div").load(location.href + " #ticket_messages_div");
}
</script>