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