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

@ -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);
}
}
});
}