+
@@ -237,32 +249,30 @@ $(document).ready(function() {
console.error("Table atet found.");
}
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 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);
+ const editor = Jodit.make("#ticket_mail_editor", editorConfig);
- let lastActiveField = null;
+ let lastActiveField = null;
-// Track last active input field
-$("#template_subject").on("focus", function() {
+ // Track last active input field
+ $("#template_subject").on("focus", function() {
lastActiveField = this;
});
@@ -270,8 +280,8 @@ $("#template_subject").on("focus", function() {
editor.events.on("focus", function() {
lastActiveField = editor;
});
-
-document.addEventListener('change', function(event) {
+
+ document.addEventListener('change', function(event) {
var target = event.target;
if (target.matches('#ticket_mail_customButton')) {
let placeholderValue = $(target).val();
@@ -297,7 +307,8 @@ document.addEventListener('change', function(event) {
} 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.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;
@@ -305,22 +316,22 @@ document.addEventListener('change', function(event) {
}
-$('.close').click(function () {
- $('#template_subject').val('');
- $('#template_name').val('');
- $('#primaryKey').val('');
- $('#policy_type').val('').change();
- $('#trigger_type').val('').change();
- editor.setEditorValue('');
- $('#primaryKey').val(null);
- $('#statusSwitch').prop('checked', false);
+ $('.close').click(function() {
+ $('#template_subject').val('');
+ $('#template_name').val('');
+ $('#primaryKey').val('');
+ $('#policy_type').val('').change();
+ $('#trigger_type').val('').change();
+ editor.setEditorValue('');
+ $('#primaryKey').val(null);
+ $('#statusSwitch').prop('checked', false);
-})
-$('#ticket_mail_editor_modal').submit(function (event) {
+ })
+ $('#ticket_mail_editor_modal').submit(function(event) {
- event.preventDefault();
- let isValid = true;
- $('#ticket_mail_editor_modal [required]').each(function () {
+ event.preventDefault();
+ let isValid = true;
+ $('#ticket_mail_editor_modal [required]').each(function() {
if (!this.value.trim()) {
isValid = false;
$(this).addClass('is-invalid'); // Add a red border for visibility
@@ -333,58 +344,61 @@ $('#ticket_mail_editor_modal').submit(function (event) {
toastr.error('Please fill all required fields.', 'Validation Error');
return; // Prevent submission
}
- 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 primary_key = $('#primaryKey').val();
- if (primary_key != null && primary_key != ''){
- formData.push({ name: 'id', value: primary_key});
- }
- $('.loader').fadeIn();
- $('.loader-mask').fadeIn();
- var form_action = '= base_url("ticket/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();
- $('.loader').fadeOut();
- $('.loader-mask').delay(350).fadeOut('slow');
- toastr.success('Template saved successfully!', 'Success');
- location.reload();
- }else if (res.status == false){
- toastr.error('Failed to Save Data', '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);
- }
+ 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 primary_key = $('#primaryKey').val();
+ if (primary_key != null && primary_key != '') {
+ formData.push({
+ name: 'id',
+ value: primary_key
});
- }
- else
- {
- console.error("Jodit editor instance is not defined.");
}
-})
+ $('.loader').fadeIn();
+ $('.loader-mask').fadeIn();
+ var form_action = '= base_url("ticket/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();
+ $('.loader').fadeOut();
+ $('.loader-mask').delay(350).fadeOut('slow');
+ toastr.success('Template saved successfully!', 'Success');
+ location.reload();
+ } else if (res.status == false) {
+ toastr.error('Failed to Save Data', '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.");
+ }
+ })
});
@@ -393,9 +407,11 @@ function openModal() {
myModal.show();
}
-function deleteTemplate(id){
- const url = '= base_url("ticket/crud_mail_template/3") ?>';
- const data = { id: id }; // Ensure data is passed as an object
+function deleteTemplate(id) {
+ const url = '= base_url("ticket/crud_mail_template/3") ?>';
+ const data = {
+ id: id
+ }; // Ensure data is passed as an object
Swal.fire({
title: "Are you sure?",
@@ -437,13 +453,16 @@ function deleteTemplate(id){
}
});
}
+
function getMailTemplateData(id) {
const template_name = 'new_mail_template';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
- var form_action = '= base_url("ticket/crud_mail_template/2") ?>';
- var data = { id: id };
+ var form_action = '= base_url("ticket/crud_mail_template/2") ?>';
+ var data = {
+ id: id
+ };
$.ajax({
url: form_action,
@@ -454,15 +473,15 @@ function getMailTemplateData(id) {
if (res) {
if (res.status == true) {
// Open the modal
- openModal();
+ openModal();
// Populate the form fields
$('#template_subject').val(res.data.subject);
- $('#template_name').val(res.data.template_name);
+ $('#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.ticket_type).change();
- $('.jodit-wysiwyg').html(res.data.mail_content);
+ $('.jodit-wysiwyg').html(res.data.mail_content);
// Set the auto mail switch
if (res.data.is_auto_mail == 1) {
@@ -486,7 +505,7 @@ function getMailTemplateData(id) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
- error: function (xhr, status, error) {
+ error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
@@ -497,27 +516,24 @@ function getMailTemplateData(id) {
}
});
}
-
-