diff --git a/client/js/carrack.js b/client/js/carrack.js deleted file mode 100644 index db11e92..0000000 --- a/client/js/carrack.js +++ /dev/null @@ -1,19 +0,0 @@ -function sendHttpRequest(url, method, data, callback, contentType = "multipart/form-data", authorization = "") { - var xhr = new XMLHttpRequest(); - xhr.open(method, url, true); - xhr.setRequestHeader("Content-Type", contentType); - xhr.setRequestHeader("Authorization", authorization); - xhr.onreadystatechange = function () { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - var response = xhr.responseText; - callback(null, response); - } - else callback(xhr.status, null); - } - }; - var requestData; - if (contentType === "application/json") requestData = JSON.stringify(data); - else requestData = data; - xhr.send(requestData); -} diff --git a/client/js/data.js b/client/js/data.js deleted file mode 100644 index 49621fa..0000000 --- a/client/js/data.js +++ /dev/null @@ -1,88 +0,0 @@ -function buttonAct(id) { - return ` ` -} - -var table = $('#table-list').DataTable({ - "ajax": { - "url": "http://localhost:11000/api/read", - "type": "POST", - "dataSrc": "data", - "contentType": "application/json", - "data": function(d) { - // Customize the data payload sent in the POST request - return JSON.stringify({}); - }, - "error": function (xhr, error, thrown) { - console.error('Error fetching data:', thrown); - console.error('Response:', xhr.responseText); - } - }, - "columns": [ - { - "data": "id", - "render": function(data, type, row) { - return data; - } - }, - { - "data": "name", - "render": function(data, type, row) { - return ``; - } - }, - { - "data": "phone", - "render": function(data, type, row) { - return ``; - } - }, - { - "data": null, - "render": function(data, type, row) { - return buttonAct(row.id); - } - }, - ], -}) - -function buttonAdd() { - var name = document.getElementById("form-add-name").value; - var phone = document.getElementById("form-add-phone").value; - var url = "http://localhost:11000/api/create"; - var payload = { - "name":name, - "phone":phone - } - sendHttpRequest(url, "POST", payload, function (error, response) { - if (error) console.error(`Error: ${error}`); - else table.ajax.reload(null, false); - }, "application/json"); -} - -function buttonEdit(key) { - var name = document.getElementById(`form-edit-name-${key}`).value; - var phone = document.getElementById(`form-edit-phone-${key}`).value; - var url = "http://localhost:11000/api/update"; - var payload = { - "key":key, - "name":name, - "phone":phone - } - sendHttpRequest(url, "POST", payload, function (error, response) { - if (error) console.error(`Error: ${error}`); - else table.ajax.reload(null, false); - }, "application/json"); - alert("Data berhasil dirubah"); -} - -function buttonRemove(key) { - var url = "http://localhost:11000/api/delete"; - var payload = { - "key":key - } - sendHttpRequest(url, "POST", payload, function (error, response) { - if (error) console.error(`Error: ${error}`); - else table.ajax.reload(null, false); - }, "application/json"); - alert("Data berhasil dihapus, permanent, selamanya!"); -}