first initial
This commit is contained in:
128
public/js/pages/back/master/dealer.js
Normal file
128
public/js/pages/back/master/dealer.js
Normal file
@@ -0,0 +1,128 @@
|
||||
$.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: 'dealer_code', name: 'dealer_code'},
|
||||
{data: 'name', name: 'name'},
|
||||
{data: 'pic_name', name: 'u.name'},
|
||||
{data: 'address', name: 'address'},
|
||||
{data: 'action', name: 'action', orderable: false, searchable: false},
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
$("#addDealer").click(function() {
|
||||
$("#dealerModal").modal("show")
|
||||
let form_action = $("input[name='store_url']").val()
|
||||
$("#dealerForm").attr('action', form_action)
|
||||
$("#dealerForm input[name='_method']").remove()
|
||||
$("#dealerForm").attr('data-form', 'store')
|
||||
$("#dealerForm").trigger("reset")
|
||||
})
|
||||
|
||||
function destroyDealer(id) {
|
||||
let action = $("#destroyDealer"+id).attr("data-action")
|
||||
Swal.fire({
|
||||
title: 'Hapus Dealer?',
|
||||
text: "Data pengguna yang terkait dengan dealer 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(
|
||||
'Dealer Dihapus!'
|
||||
)
|
||||
table.ajax.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function editDealer(id) {
|
||||
let form_action = $("#editDealer"+id).attr("data-action")
|
||||
let edit_url = $("#editDealer"+id).attr("data-url")
|
||||
$("#dealerModal").modal("show")
|
||||
$("#dealerForm").append('<input type="hidden" name="_method" value="PUT">')
|
||||
$("#dealerForm").attr('action', form_action)
|
||||
$("#dealerForm").attr('data-form', 'update')
|
||||
$.get(edit_url, function(res) {
|
||||
$("#dealerForm input[name='name']").val(res.data.name)
|
||||
$("#dealerForm input[name='dealer_code']").val(res.data.dealer_code)
|
||||
$("#dealerForm input[name='address']").val(res.data.address)
|
||||
})
|
||||
}
|
||||
|
||||
function addPic(id) {
|
||||
let form_action = $("#addPic"+id).attr("data-action")
|
||||
let edit_url = $("#addPic"+id).attr("data-url")
|
||||
$("#picModal").modal("show")
|
||||
$("#picForm").append('<input type="hidden" name="_method" value="PUT">')
|
||||
$("#picForm").attr('action', form_action)
|
||||
$.get(edit_url, function(res) {
|
||||
$("#picForm input[name='name']").val(res.data.name)
|
||||
$("#picForm input[name='dealer_code']").val(res.data.dealer_code)
|
||||
})
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#picForm").submit(function(e) {
|
||||
e.preventDefault()
|
||||
$.ajax({
|
||||
url: $('#picForm').attr("action"),
|
||||
type: 'POST',
|
||||
data: {pic: $('#picForm select[name="pic_id"]').val()},
|
||||
success: function(res) {
|
||||
$("#picModal").modal("hide")
|
||||
$('#picForm').trigger("reset")
|
||||
table.ajax.reload()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
$("#dealerForm").submit(function(e) {
|
||||
e.preventDefault();
|
||||
let dataForm = $("#dealerForm").attr('data-form')
|
||||
if(dataForm == 'store') {
|
||||
$.ajax({
|
||||
url: $('#dealerForm').attr("action"),
|
||||
type: 'POST',
|
||||
data: $('#dealerForm').serialize(),
|
||||
success: function(res) {
|
||||
$("#dealerModal").modal("hide")
|
||||
$('#dealerForm').trigger("reset")
|
||||
table.ajax.reload()
|
||||
}
|
||||
})
|
||||
}else if(dataForm == 'update') {
|
||||
$.ajax({
|
||||
url: $('#dealerForm').attr("action"),
|
||||
type: 'POST',
|
||||
data: $('#dealerForm').serialize(),
|
||||
success: function(res) {
|
||||
$("#dealerModal").modal("hide")
|
||||
$('#dealerForm').trigger("reset")
|
||||
table.ajax.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user