Add setting stuff, clean up
This commit is contained in:
@ -1,227 +1,160 @@
|
|||||||
/**
|
/**
|
||||||
JS File containing all JQuery-related handlers
|
JS File containing all JQuery-related handlers
|
||||||
https://github.com/mesacarlos
|
https://github.com/mesacarlos
|
||||||
2019-2020 Carlos Mesa under MIT License.
|
2019-2020 Carlos Mesa under MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show saved serverlist on startup
|
* Show saved serverlist on startup
|
||||||
*/
|
*/
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$("#serverContainer").hide();
|
$("#serverContainer").hide();
|
||||||
persistenceManager.initializeSettings();
|
persistenceManager.initializeSettings();
|
||||||
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
|
||||||
|
var servers = persistenceManager.getAllServers();
|
||||||
//Remove servers from persistence with invalid names. See v1.4-rev2 for details
|
for(var i = 0; i < servers.length; i++){
|
||||||
var servers = persistenceManager.getAllServers();
|
if(servers[i].serverName.includes("\'") || servers[i].serverName.includes("\"") || servers[i].serverName.includes("<") || servers[i].serverName.includes(">")){
|
||||||
for(var i = 0; i < servers.length; i++){
|
persistenceManager.deleteServer(servers[i].serverName);
|
||||||
if(servers[i].serverName.includes("\'") || servers[i].serverName.includes("\"") || servers[i].serverName.includes("<") || servers[i].serverName.includes(">")){
|
}
|
||||||
persistenceManager.deleteServer(servers[i].serverName);
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
});
|
/**
|
||||||
|
* Add server modal button click
|
||||||
/**
|
*/
|
||||||
* Add server modal button click
|
$("#saveAndConnectServerButton").click(function() {
|
||||||
*/
|
//Validate form data
|
||||||
$("#saveAndConnectServerButton").click(function() {
|
var addServerForm = document.getElementById("addServerForm");
|
||||||
//Validate form data
|
if(!addServerForm.checkValidity()){
|
||||||
var addServerForm = document.getElementById("addServerForm");
|
addServerForm.classList.add('was-validated');
|
||||||
if(!addServerForm.checkValidity()){
|
return;
|
||||||
addServerForm.classList.add('was-validated');
|
}
|
||||||
return;
|
//Save server
|
||||||
}
|
var name = $("#server-name").val().replace(/</g,"<").replace(/>/g,">").replace(/'/g,"").replace(/"/g,"");
|
||||||
|
var wcIp = $("#server-ip").val();
|
||||||
//Save server
|
var wcPort = $("#server-port").val();
|
||||||
var name = $("#server-name").val().replace(/</g,"<").replace(/>/g,">").replace(/'/g,"").replace(/"/g,"");
|
var wcSsl = $("#server-ssl").prop('checked');
|
||||||
var wcIp = $("#server-ip").val();
|
var uri;
|
||||||
var wcPort = $("#server-port").val();
|
if(wcSsl){ uri = `wss://${wcIp}:${wcPort}`; }else{ uri = `ws://${wcIp}:${wcPort}`; }
|
||||||
var wcSsl = $("#server-ssl").prop('checked');
|
persistenceManager.saveServer(new WSServer(name, uri));
|
||||||
var uri;
|
//Close modal
|
||||||
if(wcSsl){
|
addServerForm.classList.remove('was-validated');
|
||||||
uri = "wss://" + wcIp + ":" + wcPort;
|
$("#addServerModal").modal('hide');
|
||||||
}else{
|
//Empty all modal values
|
||||||
uri = "ws://" + wcIp + ":" + wcPort;
|
$("#server-name").val(""); $("#server-ip").val(""); $("#server-port").val("");
|
||||||
}
|
updateServerList(); //Update GUI serverlist
|
||||||
persistenceManager.saveServer(new WSServer(name, uri));
|
openServer(name); //Connect to server
|
||||||
|
});
|
||||||
//Close modal
|
|
||||||
addServerForm.classList.remove('was-validated');
|
/** Password modal button click */
|
||||||
$("#addServerModal").modal('hide');
|
$("#passwordSendButton").click(function() {
|
||||||
|
$('#passwordModal').modal('hide'); //Close modal
|
||||||
//Empty all modal values
|
});
|
||||||
$("#server-name").val("");
|
/** Password modal Enter key pressed */
|
||||||
$("#server-ip").val("");
|
$("#passwordForm").submit(function(event){
|
||||||
$("#server-port").val("");
|
//Solves bug with forms:
|
||||||
|
event.preventDefault();
|
||||||
//Update GUI serverlist
|
$('#passwordModal').modal('hide'); //Close modal
|
||||||
updateServerList();
|
});
|
||||||
|
/** On password modal close (Login) */
|
||||||
//Connect to server
|
$('#passwordModal').on('hidden.bs.modal', function (e) {
|
||||||
openServer(name);
|
//Send LOGIN command to server
|
||||||
});
|
var pwd = $("#server-pwd").val();
|
||||||
|
connectionManager.sendPassword(pwd);
|
||||||
/**
|
//Save password if set
|
||||||
* Password modal button click
|
var savePasswordChecked = $("#rememberPwdCheckbox").prop("checked");
|
||||||
*/
|
if(savePasswordChecked){
|
||||||
$("#passwordSendButton").click(function() {
|
var serverName = connectionManager.activeConnection.serverName;
|
||||||
//Close modal
|
var serverURI = connectionManager.activeConnection.serverURI;
|
||||||
$('#passwordModal').modal('hide');
|
var svObj = new WSServer(serverName, serverURI);
|
||||||
});
|
svObj.setPassword(pwd);
|
||||||
|
persistenceManager.saveServer(svObj);
|
||||||
/**
|
}
|
||||||
* Password modal Enter key pressed
|
$("#server-pwd").val(''); //Remove password from modal
|
||||||
*/
|
});
|
||||||
$("#passwordForm").submit(function(event){
|
/** On send command button click */
|
||||||
//Solves bug with forms:
|
$("#sendCommandButton").click(function() {
|
||||||
event.preventDefault();
|
connectionManager.sendConsoleCmd($("#commandInput").val());
|
||||||
|
$("#commandInput").val('');
|
||||||
//Close modal
|
commandHistoryIndex = -1; //Reset command history index
|
||||||
$('#passwordModal').modal('hide');
|
});
|
||||||
});
|
/** Enter or arrow down/up key on command input */
|
||||||
|
$("#commandInput").on('keyup', function (e) {
|
||||||
/**
|
if(e.which === 13){ //Detect enter key
|
||||||
* On password modal close (Login)
|
//Disable textbox to prevent multiple submit
|
||||||
*/
|
$(this).attr("disabled", "disabled");
|
||||||
$('#passwordModal').on('hidden.bs.modal', function (e) {
|
sendCommandButton.click(); //Send command
|
||||||
//Send LOGIN command to server
|
$(this).removeAttr("disabled"); //Enable the textbox again.
|
||||||
var pwd = $("#server-pwd").val();
|
$(this).focus(); //Focus again
|
||||||
connectionManager.sendPassword(pwd);
|
}else if(e.which === 38){ //Detect arrow up key
|
||||||
|
//Replace with older command
|
||||||
//Save password if set
|
if(commandHistoryIndex == -1){
|
||||||
var savePasswordChecked = $("#rememberPwdCheckbox").prop("checked");
|
//If not browsing history, start by latest command sent
|
||||||
if(savePasswordChecked){
|
commandHistoryIndex = connectionManager.activeConnection.commands.length;
|
||||||
var serverName = connectionManager.activeConnection.serverName;
|
}
|
||||||
var serverURI = connectionManager.activeConnection.serverURI;
|
$("#commandInput").val(connectionManager.activeConnection.commands[commandHistoryIndex - 1]);
|
||||||
var svObj = new WSServer(serverName, serverURI);
|
commandHistoryIndex = commandHistoryIndex - 1;
|
||||||
svObj.setPassword(pwd);
|
}else if(e.which === 40){ //Detect arrow down key
|
||||||
persistenceManager.saveServer(svObj);
|
//Replace with newer command
|
||||||
}
|
if(commandHistoryIndex !== -1){
|
||||||
|
//If not browsing history, do nothing
|
||||||
//Remove password from modal
|
$("#commandInput").val(connectionManager.activeConnection.commands[commandHistoryIndex + 1]);
|
||||||
$("#server-pwd").val('');
|
commandHistoryIndex = commandHistoryIndex + 1;
|
||||||
});
|
}
|
||||||
|
}else if(e.which == 9){ //Detect tab key
|
||||||
/**
|
//TODO Suggest user from connectionManager.activeConnection.players; ##################################
|
||||||
* On send command button click
|
}
|
||||||
*/
|
});
|
||||||
$("#sendCommandButton").click(function() {
|
/** On delete server button click */
|
||||||
connectionManager.sendConsoleCmd($("#commandInput").val());
|
$("#deleteServerButton").click(function() {
|
||||||
$("#commandInput").val('');
|
var name = connectionManager.activeConnection.serverName;
|
||||||
commandHistoryIndex = -1; //Reset command history index
|
connectionManager.activeConnection.removeSubscribers(); //Remove subscribers
|
||||||
});
|
connectionManager.deleteConnection(name); //Delete from active connections
|
||||||
|
backToHomepage(); //Back to homepage
|
||||||
/**
|
persistenceManager.deleteServer(name); //Remove from persistence
|
||||||
* Enter or arrow down/up key on command input
|
updateServerList(); //Update dropdown
|
||||||
*/
|
|
||||||
$("#commandInput").on('keyup', function (e) {
|
});
|
||||||
if(e.which === 13){ //Detect enter key
|
/** On Navbar Home link clicked */
|
||||||
//Disable textbox to prevent multiple submit
|
$("#navbarBrandLink").click(function() { backToHomepage(); });
|
||||||
$(this).attr("disabled", "disabled");
|
/** On Navbar Brand link clicked */
|
||||||
|
$("#navbarHomeLink").click(function() { backToHomepage(); });
|
||||||
//Send command
|
/** On DisconnectedModal, back to welcome screen clicked */
|
||||||
sendCommandButton.click();
|
$("#disconnectionModalWelcomeScreenButton").click(function() { backToHomepage(); });
|
||||||
|
/** On Settings link clicked */
|
||||||
//Enable the textbox again.
|
$("#settingsLink").click(function() {
|
||||||
$(this).removeAttr("disabled");
|
//Update modal switches and boxes with saved settings
|
||||||
|
$("#showDateSettingsSwitch").prop("checked", persistenceManager.getSetting("dateTimePrefix"));
|
||||||
//Focus again
|
$("#readLogFileSwitch").prop("checked", persistenceManager.getSetting("retrieveLogFile"));
|
||||||
$(this).focus();
|
$("#infoRefreshIntervalField").prop("value", persistenceManager.getSetting("infoRefreshInterval"));
|
||||||
}else if(e.which === 38){ //Detect arrow up key
|
$("#consoleFontSizeField").prop("value", persistenceManager.getSetting("consoleFontSize"));
|
||||||
//Replace with older command
|
});
|
||||||
if(commandHistoryIndex == -1){
|
/** On showDateSettingsSwitch switche */
|
||||||
//If not browsing history, start by latest command sent
|
$("#showDateSettingsSwitch").click(function() {
|
||||||
commandHistoryIndex = connectionManager.activeConnection.commands.length;
|
//Update modal switches and boxes with saved settings
|
||||||
}
|
persistenceManager.setSetting("dateTimePrefix", $("#showDateSettingsSwitch").is(":checked"));
|
||||||
$("#commandInput").val(connectionManager.activeConnection.commands[commandHistoryIndex - 1]);
|
});
|
||||||
commandHistoryIndex = commandHistoryIndex - 1;
|
/** On readLogFileSwitch switched */
|
||||||
}else if(e.which === 40){ //Detect arrow down key
|
$("#readLogFileSwitch").click(function() {
|
||||||
//Replace with newer command
|
//Update modal switches and boxes with saved settings
|
||||||
if(commandHistoryIndex !== -1){
|
persistenceManager.setSetting("retrieveLogFile", $("#readLogFileSwitch").is(":checked"));
|
||||||
//If not browsing history, do nothing
|
});
|
||||||
$("#commandInput").val(connectionManager.activeConnection.commands[commandHistoryIndex + 1]);
|
$("#infoRefreshIntervalField").on('input', function() {
|
||||||
commandHistoryIndex = commandHistoryIndex + 1;
|
//Update modal switches and boxes with saved settings
|
||||||
}
|
persistenceManager.setSetting("infoRefreshInterval", $("#infoRefreshIntervalField").val());
|
||||||
}else if(e.which == 9){ //Detect tab key
|
});
|
||||||
//TODO Suggest user from connectionManager.activeConnection.players;
|
$("#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");
|
||||||
|
});
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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"));
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On showDateSettingsSwitch switched
|
|
||||||
*/
|
|
||||||
$("#showDateSettingsSwitch").click(function() {
|
|
||||||
//Update modal switches and boxes with saved settings
|
|
||||||
persistenceManager.setSetting("dateTimePrefix", $("#showDateSettingsSwitch").is(":checked"));
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On readLogFileSwitch switched
|
|
||||||
*/
|
|
||||||
$("#readLogFileSwitch").click(function() {
|
|
||||||
//Update modal switches and boxes with saved settings
|
|
||||||
persistenceManager.setSetting("retrieveLogFile", $("#readLogFileSwitch").is(":checked"));
|
|
||||||
});
|
|
Reference in New Issue
Block a user