106 lines
2.9 KiB
JavaScript
106 lines
2.9 KiB
JavaScript
async function add_asset() {
|
|
let serial = document.getElementById("add-asset-serial");
|
|
let tag = document.getElementById("add-asset-tag");
|
|
let category = document.getElementById("add-asset-category");
|
|
let model = document.getElementById("add-asset-model");
|
|
|
|
if (serial.value == "") {
|
|
alert("Add asset error:\nThe seiral field cannot be empty!");
|
|
return;
|
|
}
|
|
|
|
let serial_data = (serial.value == "") ? null : serial.value;
|
|
let tag_data = (tag.value == "") ? null : tag.value;
|
|
let category_data = (category.value == "N/A") ? null : category.value;
|
|
let model_data = (model.value == "N/A") ? null : model.value;
|
|
|
|
let data = {
|
|
"tag": tag_data,
|
|
"serial": serial_data,
|
|
"category": category_data,
|
|
"model": model_data
|
|
}
|
|
|
|
await fetch("/add_asset", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(data),
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
console.log(data);
|
|
})
|
|
|
|
serial.value = "";
|
|
tag.value = "";
|
|
category.value = "N/A";
|
|
model.value = "N/A";
|
|
}
|
|
|
|
async function add_user() {
|
|
let id = document.getElementById("add-user-id");
|
|
let username = document.getElementById("add-user-name");
|
|
let asset = document.getElementById("add-assigned-asset");
|
|
let card = document.getElementById("add-assigned-card");
|
|
|
|
if (username.value == "") {
|
|
alert("Add user error:\nUser name field cannot be null!");
|
|
return;
|
|
}
|
|
|
|
let id_data = (id.value == "") ? null : id.value;
|
|
let username_data = (username.value == "") ? null : username.value;
|
|
let asset_data = (asset.value == "") ? null : asset.value;
|
|
let card_data = (card.value == "") ? null : card.value;
|
|
|
|
let data = {
|
|
"id": id_data,
|
|
"name": username_data,
|
|
"asset": asset_data,
|
|
"card": card_data
|
|
}
|
|
|
|
|
|
await fetch("/add_user",{
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type":"application/json",
|
|
},
|
|
body: JSON.stringify(data),
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
console.log(data);
|
|
})
|
|
|
|
id.value = "";
|
|
username.value = "";
|
|
asset.value = "";
|
|
card.value = "";
|
|
}
|
|
|
|
function add_card() {
|
|
let display = document.getElementById("add-display-number");
|
|
let card = document.getElementById("add-card-number");
|
|
|
|
if (card.value == "") {
|
|
alert("Add card error:\nCard number field cannot be null");
|
|
return;
|
|
}
|
|
console.log(
|
|
(display.value == "") ? null : display.value,
|
|
(card.value == "") ? null : card.value
|
|
)
|
|
display.value = "";
|
|
card.value = "";
|
|
}
|
|
|
|
function post_data_format(argsObject) {
|
|
args = []
|
|
for (let property in argsObject) {
|
|
args.push(`${property}=${argsObject[property]}`)
|
|
}
|
|
return "?" + args.join('&');
|
|
} |