|
Server : Apache/2.4.41 (Ubuntu) System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 8.2.12 Disable Function : NONE Directory : /var/www/poskrypt/admin.poskrypt.com/resources/views/taxonomy/ |
Upload File : |
<script type="text/javascript">
$(document).ready( function() {
function getTaxonomiesIndexPage () {
var data = {category_type : $('#category_type').val()};
$.ajax({
method: "GET",
dataType: "html",
url: '/taxonomies-ajax-index-page',
data: data,
async: false,
success: function(result){
$('.taxonomy_body').html(result);
}
});
}
function initializeTaxonomyDataTable() {
//Category table
if ($('#category_table').length) {
var category_type = $('#category_type').val();
category_table = $('#category_table').DataTable({
processing: true,
serverSide: true,
ajax: '/taxonomies?type=' + category_type,
columns: [
{ data: 'name', name: 'name' },
@if($cat_code_enabled)
{ data: 'short_code', name: 'short_code' },
@endif
{ data: 'description', name: 'description' },
{ data: 'action', name: 'action', orderable: false, searchable: false},
],
});
}
}
@if(empty(request()->get('type')))
getTaxonomiesIndexPage();
@endif
initializeTaxonomyDataTable();
});
$(document).on('submit', 'form#category_add_form', function(e) {
e.preventDefault();
var form = $(this);
var data = form.serialize();
$.ajax({
method: 'POST',
url: $(this).attr('action'),
dataType: 'json',
data: data,
beforeSend: function(xhr) {
__disable_submit_button(form.find('button[type="submit"]'));
},
success: function(result) {
if (result.success === true) {
$('div.category_modal').modal('hide');
toastr.success(result.msg);
if(typeof category_table !== 'undefined') {
category_table.ajax.reload();
}
var evt = new CustomEvent("categoryAdded", {detail: result.data});
window.dispatchEvent(evt);
//event can be listened as
//window.addEventListener("categoryAdded", function(evt) {}
} else {
toastr.error(result.msg);
}
},
});
});
$(document).on('click', 'button.edit_category_button', function() {
$('div.category_modal').load($(this).data('href'), function() {
$(this).modal('show');
$('form#category_edit_form').submit(function(e) {
e.preventDefault();
var form = $(this);
var data = form.serialize();
$.ajax({
method: 'POST',
url: $(this).attr('action'),
dataType: 'json',
data: data,
beforeSend: function(xhr) {
__disable_submit_button(form.find('button[type="submit"]'));
},
success: function(result) {
if (result.success === true) {
$('div.category_modal').modal('hide');
toastr.success(result.msg);
category_table.ajax.reload();
} else {
toastr.error(result.msg);
}
},
});
});
});
});
$(document).on('click', 'button.delete_category_button', function() {
swal({
title: LANG.sure,
icon: 'warning',
buttons: true,
dangerMode: true,
}).then(willDelete => {
if (willDelete) {
var href = $(this).data('href');
var data = $(this).serialize();
$.ajax({
method: 'DELETE',
url: href,
dataType: 'json',
data: data,
success: function(result) {
if (result.success === true) {
toastr.success(result.msg);
category_table.ajax.reload();
} else {
toastr.error(result.msg);
}
},
});
}
});
});
</script>