first initial
This commit is contained in:
104
public/js/pages/back/master/work.js
Normal file
104
public/js/pages/back/master/work.js
Normal file
@@ -0,0 +1,104 @@
|
||||
$.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: 'category_name', name: 'c.name'},
|
||||
{data: 'name', name: 'w.name'},
|
||||
{data: 'shortname', name: 'w.shortname'},
|
||||
{data: 'desc', name: 'w.desc'},
|
||||
{data: 'action', name: 'action', orderable: false, searchable: false},
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
$("#addWork").click(function() {
|
||||
$("#workModal").modal("show")
|
||||
let form_action = $("input[name='store_url']").val()
|
||||
$("#workForm").attr('action', form_action)
|
||||
$("#workForm input[name='_method']").remove()
|
||||
$("#workForm").attr('data-form', 'store')
|
||||
$("#workForm").trigger("reset")
|
||||
$("#workForm textarea[name='desc']").val("")
|
||||
})
|
||||
|
||||
function destroyWork(id) {
|
||||
let action = $("#destroyWork"+id).attr("data-action")
|
||||
Swal.fire({
|
||||
title: 'Hapus Pekerjaan?',
|
||||
text: "Anda tidak akan bisa mengembalikannya!",
|
||||
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(
|
||||
'Dealer Dihapus!'
|
||||
)
|
||||
table.ajax.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function editWork(id) {
|
||||
let form_action = $("#editWork"+id).attr("data-action")
|
||||
let edit_url = $("#editWork"+id).attr("data-url")
|
||||
$("#workModal").modal("show")
|
||||
$("#workForm").append('<input type="hidden" name="_method" value="PUT">')
|
||||
$("#workForm").attr('action', form_action)
|
||||
$("#workForm").attr('data-form', 'update')
|
||||
$.get(edit_url, function(res) {
|
||||
$("#workForm input[name='name']").val(res.data.name)
|
||||
$("#workForm input[name='shortname']").val(res.data.shortname)
|
||||
$("#workForm textarea[name='desc']").html(res.data.desc)
|
||||
$("#workForm option[value='"+ res.data.category_id +"']").prop('selected', true);
|
||||
})
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#workForm").submit(function(e) {
|
||||
e.preventDefault();
|
||||
let dataForm = $("#workForm").attr('data-form')
|
||||
if(dataForm == 'store') {
|
||||
$.ajax({
|
||||
url: $('#workForm').attr("action"),
|
||||
type: 'POST',
|
||||
data: $('#workForm').serialize(),
|
||||
success: function(res) {
|
||||
$("#workModal").modal("hide")
|
||||
$('#workForm').trigger("reset")
|
||||
table.ajax.reload()
|
||||
}
|
||||
})
|
||||
}else if(dataForm == 'update') {
|
||||
$.ajax({
|
||||
url: $('#workForm').attr("action"),
|
||||
type: 'POST',
|
||||
data: $('#workForm').serialize(),
|
||||
success: function(res) {
|
||||
$("#workModal").modal("hide")
|
||||
$('#workForm').trigger("reset")
|
||||
table.ajax.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user