first initial
This commit is contained in:
101
public/js/pages/back/master/category.js
Normal file
101
public/js/pages/back/master/category.js
Normal file
@@ -0,0 +1,101 @@
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
||||
}
|
||||
});
|
||||
|
||||
var table = $('#kt_table').DataTable({
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
ajax: $("input[name='ajax_url']"),
|
||||
columns: [
|
||||
{data: 'name', name: 'name'},
|
||||
{data: 'form', name: 'form'},
|
||||
{data: 'action', name: 'action', orderable: false, searchable: false},
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
$("#addCategory").click(function() {
|
||||
$("#categoryModal").modal("show")
|
||||
let form_action = $("input[name='store_url']").val()
|
||||
$("#categoryForm").attr('action', form_action)
|
||||
$("#categoryForm input[name='_method']").remove()
|
||||
$("#categoryForm").attr('data-form', 'store')
|
||||
$("#categoryForm").trigger("reset")
|
||||
})
|
||||
|
||||
|
||||
function destroyCategory(id) {
|
||||
let action = $("#destroyCategory"+id).attr("data-action")
|
||||
console.log(action)
|
||||
Swal.fire({
|
||||
title: 'Hapus Kategori?',
|
||||
text: "Data Pekerjaan yang terkait dengan kategori ini juga akan terhapus!",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#d33',
|
||||
cancelButtonColor: '#dedede',
|
||||
confirmButtonText: 'Hapus'
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
$.ajax({
|
||||
url: action,
|
||||
type: 'POST',
|
||||
data: {
|
||||
_token: $('meta[name="csrf-token"]').attr('content'),
|
||||
_method: 'DELETE'
|
||||
},
|
||||
success: function(res) {
|
||||
Swal.fire(
|
||||
'Kategori Dihapus!'
|
||||
)
|
||||
table.ajax.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function editCategory(id) {
|
||||
let form_action = $("#editCategory"+id).attr("data-action")
|
||||
let edit_url = $("#editCategory"+id).attr("data-url")
|
||||
$("#categoryModal").modal("show")
|
||||
$("#categoryForm").append('<input type="hidden" name="_method" value="PUT">')
|
||||
$("#categoryForm").attr('action', form_action)
|
||||
$("#categoryForm").attr('data-form', 'update')
|
||||
$.get(edit_url, function(res) {
|
||||
$("#categoryForm input[name='name']").val(res.data.name)
|
||||
$("#categoryForm option[value='"+ res.data.form +"']").prop('selected', true);
|
||||
})
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#categoryForm").submit(function(e) {
|
||||
e.preventDefault();
|
||||
let dataForm = $("#categoryForm").attr('data-form')
|
||||
if(dataForm == 'store') {
|
||||
$.ajax({
|
||||
url: $('#categoryForm').attr("action"),
|
||||
type: 'POST',
|
||||
data: $('#categoryForm').serialize(),
|
||||
success: function(res) {
|
||||
$("#categoryModal").modal("hide")
|
||||
$('#categoryForm').trigger("reset")
|
||||
table.ajax.reload()
|
||||
}
|
||||
})
|
||||
}else if(dataForm == 'update') {
|
||||
$.ajax({
|
||||
url: $('#categoryForm').attr("action"),
|
||||
type: 'POST',
|
||||
data: $('#categoryForm').serialize(),
|
||||
success: function(res) {
|
||||
$("#categoryModal").modal("hide")
|
||||
$('#categoryForm').trigger("reset")
|
||||
table.ajax.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user