Add setting stuff, clean up

This commit is contained in:
2025-06-09 19:03:49 -05:00
parent 3f7783ae2e
commit bf068bfd40

View File

@ -13,15 +13,13 @@ $(document).ready(function() {
setLanguage(persistenceManager.getLanguage()); setLanguage(persistenceManager.getLanguage());
readServerList(); readServerList();
updateServerList(); updateServerList();
//Check SSL host //Check SSL host
if (location.protocol != 'https:'){ if(location.protocol != 'https:'){
$("#addServerModalSslAdvice").hide(); $("#addServerModalSslAdvice").hide();
}else{ }else{
$("#server-ssl").prop('checked', true); $("#server-ssl").prop('checked', true);
$("#server-ssl").prop("disabled", true); $("#server-ssl").prop("disabled", true);
} }
//Remove servers from persistence with invalid names. See v1.4-rev2 for details //Remove servers from persistence with invalid names. See v1.4-rev2 for details
var servers = persistenceManager.getAllServers(); var servers = persistenceManager.getAllServers();
for(var i = 0; i < servers.length; i++){ for(var i = 0; i < servers.length; i++){
@ -41,63 +39,38 @@ $("#saveAndConnectServerButton").click(function() {
addServerForm.classList.add('was-validated'); addServerForm.classList.add('was-validated');
return; return;
} }
//Save server //Save server
var name = $("#server-name").val().replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"").replace(/"/g,""); var name = $("#server-name").val().replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"").replace(/"/g,"");
var wcIp = $("#server-ip").val(); var wcIp = $("#server-ip").val();
var wcPort = $("#server-port").val(); var wcPort = $("#server-port").val();
var wcSsl = $("#server-ssl").prop('checked'); var wcSsl = $("#server-ssl").prop('checked');
var uri; var uri;
if(wcSsl){ if(wcSsl){ uri = `wss://${wcIp}:${wcPort}`; }else{ uri = `ws://${wcIp}:${wcPort}`; }
uri = "wss://" + wcIp + ":" + wcPort;
}else{
uri = "ws://" + wcIp + ":" + wcPort;
}
persistenceManager.saveServer(new WSServer(name, uri)); persistenceManager.saveServer(new WSServer(name, uri));
//Close modal //Close modal
addServerForm.classList.remove('was-validated'); addServerForm.classList.remove('was-validated');
$("#addServerModal").modal('hide'); $("#addServerModal").modal('hide');
//Empty all modal values //Empty all modal values
$("#server-name").val(""); $("#server-name").val(""); $("#server-ip").val(""); $("#server-port").val("");
$("#server-ip").val(""); updateServerList(); //Update GUI serverlist
$("#server-port").val(""); openServer(name); //Connect to server
//Update GUI serverlist
updateServerList();
//Connect to server
openServer(name);
}); });
/** /** Password modal button click */
* Password modal button click
*/
$("#passwordSendButton").click(function() { $("#passwordSendButton").click(function() {
//Close modal $('#passwordModal').modal('hide'); //Close modal
$('#passwordModal').modal('hide');
}); });
/** Password modal Enter key pressed */
/**
* Password modal Enter key pressed
*/
$("#passwordForm").submit(function(event){ $("#passwordForm").submit(function(event){
//Solves bug with forms: //Solves bug with forms:
event.preventDefault(); event.preventDefault();
$('#passwordModal').modal('hide'); //Close modal
//Close modal
$('#passwordModal').modal('hide');
}); });
/** On password modal close (Login) */
/**
* On password modal close (Login)
*/
$('#passwordModal').on('hidden.bs.modal', function (e) { $('#passwordModal').on('hidden.bs.modal', function (e) {
//Send LOGIN command to server //Send LOGIN command to server
var pwd = $("#server-pwd").val(); var pwd = $("#server-pwd").val();
connectionManager.sendPassword(pwd); connectionManager.sendPassword(pwd);
//Save password if set //Save password if set
var savePasswordChecked = $("#rememberPwdCheckbox").prop("checked"); var savePasswordChecked = $("#rememberPwdCheckbox").prop("checked");
if(savePasswordChecked){ if(savePasswordChecked){
@ -107,36 +80,22 @@ $('#passwordModal').on('hidden.bs.modal', function (e) {
svObj.setPassword(pwd); svObj.setPassword(pwd);
persistenceManager.saveServer(svObj); persistenceManager.saveServer(svObj);
} }
$("#server-pwd").val(''); //Remove password from modal
//Remove password from modal
$("#server-pwd").val('');
}); });
/** On send command button click */
/**
* On send command button click
*/
$("#sendCommandButton").click(function() { $("#sendCommandButton").click(function() {
connectionManager.sendConsoleCmd($("#commandInput").val()); connectionManager.sendConsoleCmd($("#commandInput").val());
$("#commandInput").val(''); $("#commandInput").val('');
commandHistoryIndex = -1; //Reset command history index commandHistoryIndex = -1; //Reset command history index
}); });
/** Enter or arrow down/up key on command input */
/**
* Enter or arrow down/up key on command input
*/
$("#commandInput").on('keyup', function (e) { $("#commandInput").on('keyup', function (e) {
if(e.which === 13){ //Detect enter key if(e.which === 13){ //Detect enter key
//Disable textbox to prevent multiple submit //Disable textbox to prevent multiple submit
$(this).attr("disabled", "disabled"); $(this).attr("disabled", "disabled");
sendCommandButton.click(); //Send command
//Send command $(this).removeAttr("disabled"); //Enable the textbox again.
sendCommandButton.click(); $(this).focus(); //Focus again
//Enable the textbox again.
$(this).removeAttr("disabled");
//Focus again
$(this).focus();
}else if(e.which === 38){ //Detect arrow up key }else if(e.which === 38){ //Detect arrow up key
//Replace with older command //Replace with older command
if(commandHistoryIndex == -1){ if(commandHistoryIndex == -1){
@ -153,75 +112,49 @@ $("#commandInput").on('keyup', function (e) {
commandHistoryIndex = commandHistoryIndex + 1; commandHistoryIndex = commandHistoryIndex + 1;
} }
}else if(e.which == 9){ //Detect tab key }else if(e.which == 9){ //Detect tab key
//TODO Suggest user from connectionManager.activeConnection.players; //TODO Suggest user from connectionManager.activeConnection.players; ##################################
} }
}); });
/** On delete server button click */
/**
* On delete server button click
*/
$("#deleteServerButton").click(function() { $("#deleteServerButton").click(function() {
var name = connectionManager.activeConnection.serverName; var name = connectionManager.activeConnection.serverName;
//Remove subscribers connectionManager.activeConnection.removeSubscribers(); //Remove subscribers
connectionManager.activeConnection.removeSubscribers(); connectionManager.deleteConnection(name); //Delete from active connections
backToHomepage(); //Back to homepage
//Delete from active connections persistenceManager.deleteServer(name); //Remove from persistence
connectionManager.deleteConnection(name); updateServerList(); //Update dropdown
//Back to homepage
backToHomepage();
//Remove from persistence
persistenceManager.deleteServer(name);
//Update dropdown
updateServerList();
}); });
/** On Navbar Home link clicked */
/** $("#navbarBrandLink").click(function() { backToHomepage(); });
* On Navbar Home link clicked /** On Navbar Brand link clicked */
*/ $("#navbarHomeLink").click(function() { backToHomepage(); });
$("#navbarBrandLink").click(function() { /** On DisconnectedModal, back to welcome screen clicked */
backToHomepage(); $("#disconnectionModalWelcomeScreenButton").click(function() { backToHomepage(); });
}); /** On Settings link clicked */
/**
* On Navbar Brand link clicked
*/
$("#navbarHomeLink").click(function() {
backToHomepage();
});
/**
* On DisconnectedModal, back to welcome screen clicked
*/
$("#disconnectionModalWelcomeScreenButton").click(function() {
backToHomepage();
});
/**
* On Settings link clicked
*/
$("#settingsLink").click(function() { $("#settingsLink").click(function() {
//Update modal switches and boxes with saved settings //Update modal switches and boxes with saved settings
$("#showDateSettingsSwitch").prop("checked", persistenceManager.getSetting("dateTimePrefix")); $("#showDateSettingsSwitch").prop("checked", persistenceManager.getSetting("dateTimePrefix"));
$("#readLogFileSwitch").prop("checked", persistenceManager.getSetting("retrieveLogFile")); $("#readLogFileSwitch").prop("checked", persistenceManager.getSetting("retrieveLogFile"));
$("#infoRefreshIntervalField").prop("value", persistenceManager.getSetting("infoRefreshInterval"));
$("#consoleFontSizeField").prop("value", persistenceManager.getSetting("consoleFontSize"));
}); });
/** On showDateSettingsSwitch switche */
/**
* On showDateSettingsSwitch switched
*/
$("#showDateSettingsSwitch").click(function() { $("#showDateSettingsSwitch").click(function() {
//Update modal switches and boxes with saved settings //Update modal switches and boxes with saved settings
persistenceManager.setSetting("dateTimePrefix", $("#showDateSettingsSwitch").is(":checked")); persistenceManager.setSetting("dateTimePrefix", $("#showDateSettingsSwitch").is(":checked"));
}); });
/** On readLogFileSwitch switched */
/**
* On readLogFileSwitch switched
*/
$("#readLogFileSwitch").click(function() { $("#readLogFileSwitch").click(function() {
//Update modal switches and boxes with saved settings //Update modal switches and boxes with saved settings
persistenceManager.setSetting("retrieveLogFile", $("#readLogFileSwitch").is(":checked")); persistenceManager.setSetting("retrieveLogFile", $("#readLogFileSwitch").is(":checked"));
}); });
$("#infoRefreshIntervalField").on('input', function() {
//Update modal switches and boxes with saved settings
persistenceManager.setSetting("infoRefreshInterval", $("#infoRefreshIntervalField").val());
});
$("#consoleFontSizeField").on('input', function() {
//Update modal switches and boxes with saved settings
persistenceManager.setSetting("consoleFontSize", $("#consoleFontSizeField").val());
$("#consoleTextArea").css("font-size", persistenceManager.getSetting("consoleFontSize")+"px");
});