144 lines
6.5 KiB
PHP
144 lines
6.5 KiB
PHP
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card-body">
|
|
<form role="form" class="parsley-examples" method="post" id="ticket_note_form"
|
|
enctype="multipart/form-data">
|
|
<div class="form-group">
|
|
<div class="form-row">
|
|
<div class="form-group col-md-12">
|
|
<label for="ticket_note">Add Notes</label>
|
|
<textarea class="form-control" id="ticket_note" name="note" rows="3"
|
|
placeholder="Enter Text"><?= isset($ticket_note['note']) ? $ticket_note['note'] : '' ?></textarea>
|
|
</div>
|
|
</div>
|
|
</div><input type="hidden" id="note_id">
|
|
<div class="form-group text-right m-b-0">
|
|
<button type="submit" class="btn btn-primary" id="ticket_note_submit">Save</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div> <!-- end col-->
|
|
</div>
|
|
<!-- end -->
|
|
|
|
<script>
|
|
|
|
$(document).ready(function() {
|
|
url = '<?= base_url('ticket/note/1')?>';
|
|
data = { id : $('#ticket_master_id').val(), is_auto_query : 0};
|
|
$.ajax({
|
|
url:url,
|
|
data:data,
|
|
type: 'POST',
|
|
success: function(res) {
|
|
if (res.status == true){
|
|
$('#ticket_note').val(res.data.note);
|
|
$('#note_id').val(res.data.id);
|
|
}
|
|
},
|
|
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);
|
|
}
|
|
})
|
|
|
|
$("#ticket_note_form").submit(function(event) {
|
|
|
|
event.preventDefault();
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
var url = '<?= base_url("/ticket/note/2"); ?>';
|
|
var formData = $(this).serializeArray();
|
|
var ticket_id = $('#ticket_master_id').val();
|
|
if (ticket_id != null && ticket_id != ''){
|
|
formData.push({ name: 'ticket_id', value: ticket_id});
|
|
}
|
|
var primary_key = $('#note_id').val();
|
|
if (primary_key != null && primary_key != ''){
|
|
formData.push({ name: 'id', value: primary_key});
|
|
}
|
|
console.log(formData);
|
|
sendAjaxRequestForGlobal(url, 'POST', formData, function(response) {
|
|
if (response.status == true) {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
toastr.success('Note Added Successfully','Success');
|
|
// console.log("Respone id is ")
|
|
// console.log(response.id);
|
|
$('#note_id').val(response.id);
|
|
// console.log($('#'))
|
|
|
|
|
|
} else {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
let message = response.message;
|
|
if (xhr.status === 400) {
|
|
let response = JSON.parse(xhr.responseText);
|
|
let errorMessages = "";
|
|
let seenMessages = []; // Array to store unique messages
|
|
if (response.errors) {
|
|
$.each(response.errors, function (field, message) {
|
|
if (!seenMessages.includes(message)) {
|
|
errorMessages += `• ${message}<br>`;
|
|
seenMessages.push(message); // Mark this message as "seen"
|
|
}
|
|
});
|
|
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
|
|
} else {
|
|
toastr.warning(response.message || 'Validation failed', 'Warning');
|
|
}
|
|
|
|
} else if (xhr.status === 403) {
|
|
let response = JSON.parse(xhr.responseText);
|
|
toastr.error(response.message, 'Security Policy');
|
|
} else if (xhr.status === 500) {
|
|
toastr.error('Something went wrong . Please try again later.', 'Server Error');
|
|
} else {
|
|
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}, function(xhr, status, error) {
|
|
console.error('Error fetching data:', error);
|
|
console.error(xhr.responseText);
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
if (xhr.status === 400) {
|
|
let response = JSON.parse(xhr.responseText);
|
|
let errorMessages = "";
|
|
let seenMessages = []; // Array to store unique messages
|
|
if (response.errors) {
|
|
$.each(response.errors, function (field, message) {
|
|
if (!seenMessages.includes(message)) {
|
|
errorMessages += `• ${message}<br>`;
|
|
seenMessages.push(message); // Mark this message as "seen"
|
|
}
|
|
});
|
|
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
|
|
} else {
|
|
toastr.warning(response.message || 'Validation failed', 'Warning');
|
|
}
|
|
|
|
} else if (xhr.status === 403) {
|
|
let response = JSON.parse(xhr.responseText);
|
|
toastr.error(response.message, 'Security Policy');
|
|
} else if (xhr.status === 500) {
|
|
toastr.error('Something went wrong . Please try again later.', 'Server Error');
|
|
} else {
|
|
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
|
|
}
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|