${error.responseJSON.errors[x][0]}
`;
}
$('#postErrors ul').html(errors);
$('.request-loader').removeClass('show');
$('html, body').animate({
scrollTop: $('#postErrors').offset().top - 100
}, 1000);
}
});
});
$("#permissionBtn").on('click', function () {
$("#permissionsForm").trigger("submit");
});
$("#langBtn").on('click', function () {
$("#langForm").trigger("submit");
});
/* ***************************************************
==========Form Submit with AJAX Request End==========
******************************************************/
/* ***************************************************
==========datatables start==========
******************************************************/
$('#basic-datatables').DataTable({
responsive: true,
ordering: false
});
/* ***************************************************
==========datatables end==========
******************************************************/
/* ***************************************************
==========Form Prepopulate After Clicking Edit Button Start==========
******************************************************/
$(".editbtn").on('click', function () {
let datas = $(this).data();
delete datas['toggle'];
for (let x in datas) {
if ($("#in" + x).hasClass('summernote')) {
$("#in" + x).summernote('code', datas[x]);
} else if ($("#in" + x).hasClass('image')) {
$("#in" + x).attr('src', datas[x]);
} else if ($("#in" + x).data('role') == 'tagsinput') {
if (datas[x].length > 0) {
let arr = datas[x].split(" ");
for (let i = 0; i < arr.length; i++) {
$("#in" + x).tagsinput('add', arr[i]);
}
} else {
$("#in" + x).tagsinput('removeAll');
}
}
else if ($("input[name='" + x + "']").attr('type') == 'radio') {
$("input[name='" + x + "']").each(function (i) {
if ($(this).val() == datas[x]) {
$(this).prop('checked', true);
}
});
} else if (x === 'icon') {
$(".in_" + x).val(datas[x]);
$("#in" + x).removeAttr("class");
$("#in" + x).addClass(datas[x]);
}
else {
$("#in" + x).val(datas[x]);
}
}
});
/* ***************************************************
==========Form Prepopulate After Clicking Edit Button End==========
******************************************************/
/********************************************************************
==========Form Prepopulate After Clicking Edit Button Start=========
********************************************************************/
$(".editBtn").on('click', function () {
let datas = $(this).data();
delete datas['toggle'];
for (let x in datas) {
if ($("#in_" + x).hasClass('summernote')) {
$("#in_" + x).summernote('code', datas[x]);
} else if ($("#in_" + x).data('role') == 'tagsinput') {
if (datas[x].length > 0) {
let arr = datas[x].split(" ");
for (let i = 0; i < arr.length; i++) {
$("#in_" + x).tagsinput('add', arr[i]);
}
} else {
$("#in_" + x).tagsinput('removeAll');
}
} else if ($("input[name='" + x + "']").attr('type') == 'radio') {
$("input[name='" + x + "']").each(function (i) {
if ($(this).val() == datas[x]) {
$(this).prop('checked', true);
}
});
} else if ($("#in_" + x).hasClass('select2')) {
$("#in_" + x).val(datas[x]);
$("#in_" + x).trigger('change');
} else {
$("#in_" + x).val(datas[x]);
$('.brand-img').attr('src', datas['brand_img']);
$('.gallery-img').attr('src', datas['gallery_img']);
}
}
// focus & blur colorpicker inputs
setTimeout(() => {
$(".jscolor").each(function () {
$(this).focus();
$(this).blur();
});
}, 300);
});
/* ***************************************************
==========Form Prepopulate After Clicking Edit Button End==========
******************************************************/
/* ***************************************************
==========Form Update with AJAX Request Start==========
******************************************************/
$("#updateBtn").on('click', function (e) {
$(".request-loader").addClass("show");
let ajaxEditForm = document.getElementById('ajaxEditForm');
let fd = new FormData(ajaxEditForm);
let url = $("#ajaxEditForm").attr('action');
let method = $("#ajaxEditForm").attr('method');
if ($("#ajaxEditForm .summernote").length > 0) {
$("#ajaxEditForm .summernote").each(function (i) {
let content = $(this).summernote('isEmpty') ? '' : $(this).summernote('code');
fd.delete($(this).attr('name'));
fd.append($(this).attr('name'), content);
})
}
$.ajax({
url: url,
method: method,
data: fd,
contentType: false,
processData: false,
success: function (data) {
$(".request-loader").removeClass("show");
$(".em").each(function () {
$(this).html('');
})
if (data == "success") {
location.reload();
}
// if error occurs
else if (typeof data.error != 'undefined') {
for (let x in data) {
if (x == 'error') {
continue;
}
document.getElementById('eerr' + x).innerHTML = data[x][0];
}
}
},
error: function (error) {
$(".em").each(function () {
$(this).html('');
})
console.log(error.responseJSON.errors);
for (let x in error.responseJSON.errors) {
document.getElementById('Eerr_' + x).innerHTML = error.responseJSON.errors[x][0];
}
$(".request-loader").removeClass("show");
$(e.target).attr('disabled', false);
}
});
});
$(".update-btn").each(function () {
$(this).on('click', function (e) {
let $this = $(this);
$(".request-loader").addClass("show");
let formId = $(this).data('form_id');
let ajaxEditForm = document.getElementById(formId);
let fd = new FormData(ajaxEditForm);
let url = $("#" + formId).attr('action');
let method = $("#" + formId).attr('method');
if ($("#" + formId + " .summernote").length > 0) {
$("#" + formId + " .summernote").each(function (i) {
let content = $(this).summernote('code');
fd.delete($(this).attr('name'));
fd.append($(this).attr('name'), content);
})
}
$.ajax({
url: url,
method: method,
data: fd,
contentType: false,
processData: false,
success: function (data) {
let parentCount = $this.parents('.modal').length;
let parentId;
// if the form is in modal
if (parentCount > 0) {
parentId = $this.parents('.modal').attr('id');
}
// if the form is not in modal
else {
parentId = formId;
}
$(".request-loader").removeClass("show");
$("#" + parentId).children(".em").each(function () {
$(this).html('');
})
if (data == "success") {
location.reload();
}
// if error occurs
else if (typeof data.error != 'undefined') {
for (let x in data) {
if (x == 'error') {
continue;
}
$("#" + parentId + " .eerr" + x).html(data[x][0]);
}
}
}
});
});
});
/* ***************************************************
==========Form Update with AJAX Request End==========
******************************************************/
/* ***************************************************
==========Delete Using AJAX Request Start==========
******************************************************/
$('.deletebtn').on('click', function (e) {
e.preventDefault();
$(".request-loader").addClass("show");
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
buttons: {
confirm: {
text: 'Yes, delete it!',
className: 'btn btn-success'
},
cancel: {
visible: true,
className: 'btn btn-danger'
}
}
}).then((Delete) => {
if (Delete) {
$(this).parent(".deleteform").trigger('submit');
} else {
swal.close();
$(".request-loader").removeClass("show");
}
});
});
/* ***************************************************
==========Delete Using AJAX Request End==========
******************************************************/
/* ***************************************************
==========Close Ticket Using AJAX Request Start==========
******************************************************/
$('.close-ticket').on('click', function (e) {
e.preventDefault();
$(".request-loader").addClass("show");
swal({
title: 'Are you sure?',
text: "You want to close this ticket!",
type: 'warning',
buttons: {
confirm: {
text: 'Yes, close it!',
className: 'btn btn-success'
},
cancel: {
visible: true,
className: 'btn btn-danger'
}
}
}).then((Delete) => {
if (Delete) {
swal.close();
$(".request-loader").removeClass("show");
} else {
swal.close();
$(".request-loader").removeClass("show");
}
});
});
/* ***************************************************
==========Delete Using AJAX Request End==========
******************************************************/
/* ***************************************************
==========Delete Using AJAX Request Start==========
******************************************************/
$(document).on('change', '.bulk-check', function () {
let val = $(this).data('val');
let checked = $(this).prop('checked');
// if selected checkbox is 'all' then check all the checkboxes
if (val == 'all') {
if (checked) {
$(".bulk-check").each(function () {
$(this).prop('checked', true);
});
} else {
$(".bulk-check").each(function () {
$(this).prop('checked', false);
});
}
}
// if any checkbox is checked then flag = 1, otherwise flag = 0
let flag = 0;
$(".bulk-check").each(function () {
let status = $(this).prop('checked');
if (status) {
flag = 1;
}
});
// if any checkbox is checked then show the delete button
if (flag == 1) {
$(".bulk-delete").addClass('d-inline-block');
$(".bulk-delete").removeClass('d-none');
}
// if no checkbox is checked then hide the delete button
else {
$(".bulk-delete").removeClass('d-inline-block');
$(".bulk-delete").addClass('d-none');
}
});
$('.bulk-delete').on('click', function () {
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
buttons: {
confirm: {
text: 'Yes, delete it!',
className: 'btn btn-success'
},
cancel: {
visible: true,
className: 'btn btn-danger'
}
}
}).then((Delete) => {
if (Delete) {
$(".request-loader").addClass('show');
let href = $(this).data('href');
let ids = [];
// take ids of checked one's
$(".bulk-check:checked").each(function () {
if ($(this).data('val') != 'all') {
ids.push($(this).data('val'));
}
});
let fd = new FormData();
for (let i = 0; i < ids.length; i++) {
fd.append('ids[]', ids[i]);
}
$.ajax({
url: href,
method: 'POST',
data: fd,
contentType: false,
processData: false,
success: function (data) {
$(".request-loader").removeClass('show');
if (data == "success") {
location.reload();
}
}
});
} else {
swal.close();
}
});
});
/* ***************************************************
==========Delete Using AJAX Request End==========
******************************************************/
// image (id) preview js/
$(document).on('change', '#image', function (event) {
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function (e) {
$('.showImage img').attr('src', e.target.result);
};
reader.readAsDataURL(file);
})
// image (class) preview js/
$(document).on('change', '.image', function (event) {
let $this = $(this);
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function (e) {
$this.prev('.showImage').children('img').attr('src', e.target.result);
};
reader.readAsDataURL(file);
});
// datepicker & timepicker
$("input.datepicker").datepicker();
$('input.timepicker').timepicker();
// select2
if ($('.select2').length > 0) {
$('.select2').select2();
}
});
/*------------------------
Highlight Js
-------------------------- */
hljs.initHighlightingOnLoad();