Added a check to make sure the server doesn't exist before creating it

This commit is contained in:
2022-10-06 21:11:54 -04:00
parent 4007b99833
commit 54199bf7c8
4 changed files with 40 additions and 3 deletions

View File

@ -2,6 +2,18 @@ body{
background-color: #e6e6e6;
}
input[type=submit]:disabled,
button:disabled{
background-color: darkgrey;
}
input[type=submit]:disabled:hover,
button:disabled:hover{
background-color: darkgrey;
border: 1px solid #bbb;
color: #555;
cursor: not-allowed;
}
/* set the max-width for centered content */
.container{
max-width: 1100px;

View File

@ -1,7 +1,11 @@
$(document).ready(function () {
// periodically check for server status updates
$('.serverItem').each(function() {
setInterval(updateServer, 5000, $(this));
});
// set the serverName input field to check if the server exists
$('input#serverName').on('change', checkServerExists);
});
function updateServer(elem) {
@ -10,3 +14,16 @@ function updateServer(elem) {
elem.children('.serverState').eq(0).text(data.state);
});
}
function checkServerExists() {
$.get('/server/' + $(this).val() + '/status', function(data, state) {
if (data.exists) {
$('input#createSubmit').prop('disabled', true);
alert('That server name is already used; please use another name!');
} else {
if ($('input#createSubmit').prop('disabled')) {
$('input#createSubmit').prop('disabled', false);
}
}
});
}