var table = $('#model-chain-type-table');
function addModelChainType() {
$.ajax({
type: 'GET',
dataType: 'html',
url: "{{ route('production.model.chain_type.add') }}",
success: function(data) {
$('.modal-title').text("{{ get_phrases('add_model_chain_type') }}");
$('#modelChainTypeForm').attr('action', "{{ route('production.model.chain_type.store') }}");
$('.modal-body').html(data);
$('#modelChainTypeModal').modal('show');
}
});
}
$(document).ready(function() {
$('#modelChainTypeForm').submit(function(e) {
e.preventDefault();
var url = $('#modelChainTypeForm').attr('action');
var csrf = $('meta[name="csrf-token"]').attr('content');
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': csrf,
},
});
var formData = new FormData($('#modelChainTypeForm')[0]);
$.ajax({
type: 'POST',
url: url,
data: formData,
cache: false,
contentType: false,
processData: false,
success: function(data) {
$('#modelChainTypeForm').trigger('reset');
$('#modelChainTypeModal').modal('hide');
table.DataTable().ajax.reload();
if (data.error == false) {
toastr.success(data.msg, 'Success', {
timeOut: 5000
});
} else {
toastr.error(data.msg, 'Error', {
timeOut: 5000
});
}
},
error: function(data) {
$.each(data.responseJSON.errors, function(field_name, error) {
toastr.error(error, 'Error:' + field_name, {
timeOut: 5000
});
$('#modelChainTypeForm').trigger('reset');
})
}
});
});
});
function editModelChainType(id) {
var url = "{{ route('production.model.chain_type.edit', ':id') }}";
url = url.replace(':id', id);
$.ajax({
type: 'GET',
dataType: 'html',
url: url,
success: function(data) {
var up_url = "{{ route('production.model.chain_type.update', ':id') }}";
f_up_url = up_url.replace(':id', id);
$('.modal-title').text("{{ get_phrases('edit_model_chain_type') }}");
$('#modelChainTypeForm').attr('action', f_up_url);
$('.modal-body').html(data);
$('#modelChainTypeModal').modal('show');
}
});
}
$(document).on('click', '.delete-no-load', function () {
let url = $(this).data('route');
let csrf = $(this).data('csrf');
let table = $(this).data('table');
Swal.fire({
title: 'Are you sure?',
text: "You want to Delete Data",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: 'POST',
dataType: 'json',
url: url,
data: {
_token: csrf,
_method: 'DELETE'
},
success: function (data) {
$("#"+table).DataTable().draw();
Swal.fire({
position: 'top-end',
icon: 'success',
title: 'Deleted Successfully',
showConfirmButton: false,
timer: 1000
})
}
});
}
})
});