partial update close modal on all page and disable create transaction with no stock
This commit is contained in:
@@ -1,101 +1,112 @@
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
||||
}
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||||
},
|
||||
});
|
||||
|
||||
var table = $('#kt_table').DataTable({
|
||||
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},
|
||||
]
|
||||
{ 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")
|
||||
})
|
||||
|
||||
$("#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)
|
||||
let action = $("#destroyCategory" + id).attr("data-action");
|
||||
console.log(action);
|
||||
Swal.fire({
|
||||
title: 'Hapus Kategori?',
|
||||
title: "Hapus Kategori?",
|
||||
icon: "question",
|
||||
text: "Data Pekerjaan yang terkait dengan kategori ini juga akan terhapus!",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#d33',
|
||||
cancelButtonColor: '#dedede',
|
||||
confirmButtonText: 'Hapus'
|
||||
confirmButtonColor: "#d33",
|
||||
cancelButtonColor: "#dedede",
|
||||
confirmButtonText: "Hapus",
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
$.ajax({
|
||||
url: action,
|
||||
type: 'POST',
|
||||
type: "POST",
|
||||
data: {
|
||||
_token: $('meta[name="csrf-token"]').attr('content'),
|
||||
_method: 'DELETE'
|
||||
_token: $('meta[name="csrf-token"]').attr("content"),
|
||||
_method: "DELETE",
|
||||
},
|
||||
success: function(res) {
|
||||
Swal.fire(
|
||||
'Kategori Dihapus!'
|
||||
)
|
||||
table.ajax.reload()
|
||||
}
|
||||
})
|
||||
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);
|
||||
})
|
||||
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()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
// Add event handlers for modal close buttons
|
||||
$('.close, [data-dismiss="modal"]').on("click", function () {
|
||||
$("#categoryModal").modal("hide");
|
||||
});
|
||||
|
||||
});
|
||||
// Also handle the "Batal" button
|
||||
$('.btn-secondary[data-dismiss="modal"]').on("click", function () {
|
||||
$("#categoryModal").modal("hide");
|
||||
});
|
||||
|
||||
$("#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