218 lines
6.9 KiB
HTML
218 lines
6.9 KiB
HTML
<!doctype html>
|
|
<html lang="en-US">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Kaj Forney -- GIMM 285 CRUD API Project</title>
|
|
<meta name="description" content="">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
<link rel="manifest" href="site.webmanifest">
|
|
<link rel="apple-touch-icon" href="icon.png">
|
|
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
|
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
|
|
<link rel="stylesheet" href="css/normalize.css">
|
|
<link rel="stylesheet" href="css/main.css">
|
|
|
|
<meta name="theme-color" content="#488ea7">
|
|
</head>
|
|
|
|
<body>
|
|
<div id="navbar">
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<div class="container-fluid">
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
|
|
data-bs-target="#navbarMenu" aria-controls="navbarSupportedContent"
|
|
aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarMenu">
|
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
|
<li class="navbar-brand">ADMIN</li>
|
|
<li class="nav-item m-2">
|
|
<a href="viewGameData.html">View Games</a>
|
|
</li>
|
|
<li class="nav-item dropdown">
|
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
|
|
data-bs-toggle="dropdown" aria-expanded="false">
|
|
Add
|
|
</a>
|
|
|
|
<ul class="dropdown-menu bg-dark" aria-labelledby="navbarDropdown">
|
|
<li>
|
|
<a class="dropdown-item" href="insert.html">Add Game</a>
|
|
</li>
|
|
<li>
|
|
<a class="dropdown-item" href="insertDeveloper.html">Add Developer</a>
|
|
</li>
|
|
<li>
|
|
<a class="dropdown-item" href="insertPublisher.html">Add Publisher</a>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<div class="nav-item m-2 align-content-end">
|
|
<a href="index.html">Exit Admin View</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</div>
|
|
|
|
<div id="header" class="container">
|
|
<h1>Add New Developer</h1>
|
|
<hr/>
|
|
</div>
|
|
|
|
<div class="row mb-3">
|
|
<div class="col"></div>
|
|
<div class="col card" id="successMessage"></div>
|
|
<div class="col"></div>
|
|
</div>
|
|
|
|
<div class="row mb-3">
|
|
<div class="col"></div>
|
|
<div class="col card" id="errorMessage"></div>
|
|
<div class="col"></div>
|
|
</div>
|
|
|
|
<div id="form">
|
|
<div class="container">
|
|
|
|
<div class="row mb-3">
|
|
<div class="col">
|
|
<label>Name</label>
|
|
</div>
|
|
<div class="col">
|
|
<input id="name" type="text"/>
|
|
</div>
|
|
<div class="col"></div>
|
|
</div>
|
|
|
|
<div class='row'>
|
|
<div id='name-error' class='col-12 error-message'> </div>
|
|
</div>
|
|
|
|
<div class="row mb-3">
|
|
<div class="col">
|
|
<label>Description</label>
|
|
<p>(maximum 250 characters)</p>
|
|
</div>
|
|
<div class="col">
|
|
<textarea id="description" rows="5" cols="40" maxlength="250"></textarea>
|
|
</div>
|
|
<div class="col"></div>
|
|
</div>
|
|
|
|
<div class='row'>
|
|
<div id='description-error' class='col-12 error-message'> </div>
|
|
</div>
|
|
|
|
<div class="row mb-3">
|
|
<div class="col">
|
|
<label>Homepage</label>
|
|
</div>
|
|
<div class="col">
|
|
<input id="homepage" type="text"/>
|
|
</div>
|
|
<div class="col"></div>
|
|
</div>
|
|
|
|
<div class='row'>
|
|
<div id='homepage-error' class='col-12 error-message'> </div>
|
|
</div>
|
|
|
|
<div class="row mb-3">
|
|
<div class="col-2 align-content-center">
|
|
<button id="submitButton" type="submit">Submit</button>
|
|
</div>
|
|
<div class="col-2 align-content-center">
|
|
<button id="backButton">Back</button>
|
|
</div>
|
|
<div class="col-8"></div>
|
|
</div>
|
|
|
|
<hr/>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
<footer id="footer">
|
|
<p>Page created by <a href="https://lunarpenguin.net/">Kaj Forney</a>, as work for class (GIMM 285).</p>
|
|
<p>All example data used is originally from <a href="https://store.steampowered.com/">Steam</a>.</p>
|
|
</footer>
|
|
|
|
<script src="js/vendor/modernizr-3.11.2.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"
|
|
integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
|
|
crossorigin="anonymous" defer></script>
|
|
|
|
<script>
|
|
const isEmpty = (obj) => Object.keys(obj).length === 0;
|
|
|
|
document.getElementById("successMessage").hidden = true;
|
|
document.getElementById("errorMessage").hidden = true;
|
|
|
|
document.getElementById('backButton').addEventListener('click', (event) => {
|
|
history.back();
|
|
});
|
|
|
|
document.getElementById('submitButton').addEventListener('click', (event) => {
|
|
//const formData = new FormData();
|
|
const parameters = {};
|
|
|
|
if (document.getElementById('name').value.length !== 0) {
|
|
parameters.name = document.getElementById('name').value;
|
|
}
|
|
if (document.getElementById('description').value.length !== 0) {
|
|
parameters.description = document.getElementById('description').value;
|
|
}
|
|
if (document.getElementById('homepage').value.length !== 0) {
|
|
parameters.homepage = document.getElementById('homepage').value;
|
|
}
|
|
|
|
|
|
//Settings for FETCH API request
|
|
let fetchSettings = {
|
|
method: 'POST',
|
|
};
|
|
|
|
//Send FETCH API request
|
|
fetch("http://localhost:8787/developers" + (!isEmpty(parameters) ? '?' + new URLSearchParams(parameters) : ''), fetchSettings)
|
|
.then((response) => {
|
|
return new Promise((resolve) => response.json()
|
|
.then((json) => resolve({
|
|
status: response.status,
|
|
json,
|
|
})
|
|
));
|
|
})
|
|
.then(({status, json}) => {
|
|
if (status === 200) {
|
|
let message = "Submission successful!"
|
|
document.getElementById('successMessage').hidden = false;
|
|
document.getElementById('successMessage').innerHTML = message;
|
|
} else if (status === 400) {
|
|
let message = "There was a problem with your submission. Please check for errors and try again."
|
|
document.getElementById("errorMessage").hidden = false;
|
|
document.getElementById("errorMessage").innerHTML = message;
|
|
|
|
const elementErrorMessages = document.getElementsByClassName('error-message');
|
|
for(error of json.errors) {
|
|
const errorID = error.param + '-error';
|
|
document.getElementById(errorID).innerHTML = error.msg;
|
|
}
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
});
|
|
return;
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|