From 65c2914ef9e08220ef4aa79ba2822254ea353903 Mon Sep 17 00:00:00 2001 From: gsemaj Date: Sat, 18 Sep 2021 12:31:40 -0400 Subject: [PATCH 1/4] Add edit button & server deselection on add --- assets/js/serverselector.js | 10 ++++++++++ index.html | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/assets/js/serverselector.js b/assets/js/serverselector.js index f6bf45a..c720fe5 100644 --- a/assets/js/serverselector.js +++ b/assets/js/serverselector.js @@ -8,6 +8,8 @@ var serverarray function enableServerListButtons() { $('#of-connect-button').removeClass('disabled'); $('#of-connect-button').prop('disabled', false); + $('#of-editserver-button').removeClass('disabled'); + $('#of-editserver-button').prop('disabled', false); $('#of-deleteserver-button').removeClass('disabled'); $('#of-deleteserver-button').prop('disabled', false); } @@ -15,6 +17,8 @@ function enableServerListButtons() { function disableServerListButtons() { $('#of-connect-button').addClass('disabled'); $('#of-connect-button').prop('disabled', true); + $('#of-editserver-button').addClass('disabled'); + $('#of-editserver-button').prop('disabled', true); $('#of-deleteserver-button').addClass('disabled'); $('#of-deleteserver-button').prop('disabled', true); } @@ -168,6 +172,12 @@ function connectToServer() { }); } +// If applicable, deselect currently selected server. +function deselectServer() { + disableServerListButtons(); + $(".server-listing-entry").removeClass('bg-primary'); +} + $('#server-table').on('click', '.server-listing-entry', function(event) { enableServerListButtons(); $(this).addClass('bg-primary').siblings().removeClass('bg-primary'); diff --git a/index.html b/index.html index dd26b0d..45bb85e 100644 --- a/index.html +++ b/index.html @@ -39,7 +39,11 @@
-
+
+ + + +
From 0cdf3df4d4a2c07aeb4487497c7f0be045ab45ed Mon Sep 17 00:00:00 2001 From: gsemaj Date: Sat, 18 Sep 2021 13:47:20 -0400 Subject: [PATCH 2/4] Implement Edit Modal for Server Entries --- assets/css/openfusion.css | 5 +++++ assets/js/serverselector.js | 34 ++++++++++++++++++++++++++++++++++ index.html | 15 ++++++++++++++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/assets/css/openfusion.css b/assets/css/openfusion.css index f810cf2..93464ba 100644 --- a/assets/css/openfusion.css +++ b/assets/css/openfusion.css @@ -80,6 +80,11 @@ body { border-color: #6699FF; } +#of-editservermodal > .modal-dialog > .modal-content { + background-color: #093363; + border-color: #6699FF; +} + #of-deleteservermodal > .modal-dialog > .modal-content { background-color: #093363; border-color: #6699FF; diff --git a/assets/js/serverselector.js b/assets/js/serverselector.js index c720fe5..f79f328 100644 --- a/assets/js/serverselector.js +++ b/assets/js/serverselector.js @@ -39,6 +39,20 @@ function addServer() { loadServerList(); } +function editServer() { + var jsontomodify = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json")); + $.each(jsontomodify["servers"], function( key, value ) { + if(value["uuid"] == getSelectedServer()) { + value['description'] = $("#editserver-descinput").val().length == 0 ? value['description'] : $("#editserver-descinput").val(); + value['ip'] = $("#editserver-ipinput").val().length == 0 ? value['ip'] : $("#editserver-ipinput").val(); + value['version'] = $("#editserver-versionselect option:selected").text(); + } + }); + + remotefs.writeFileSync(userdir+"\\servers.json", JSON.stringify(jsontomodify, null, 4)); + loadServerList(); +} + function deleteServer() { var jsontomodify = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json")); var result = jsontomodify['servers'].filter(function(obj) {return (obj.uuid === getSelectedServer())})[0]; @@ -56,6 +70,7 @@ function loadGameVersions() { versionarray = versionjson['versions']; $.each(versionarray, function( key, value ) { $(new Option(value.name, 'val')).appendTo('#addserver-versionselect'); + $(new Option(value.name, 'val')).appendTo('#editserver-versionselect'); }); } @@ -189,6 +204,25 @@ $('#server-table').on('dblclick', '.server-listing-entry', function(event) { connectToServer(); }); +$('#of-editservermodal').on('show.bs.modal', function (e) { + + var jsontomodify = JSON.parse(remotefs.readFileSync(userdir+"\\servers.json")); + $.each(jsontomodify["servers"], function( key, value ) { + if(value["uuid"] == getSelectedServer()) { + $("#editserver-descinput")[0].value = value['description']; + $("#editserver-ipinput")[0].value = value['ip']; + + var versionIndex = -1; + $.each($("#editserver-versionselect")[0], function( key, val ) { + if(val.text === value['version']) { + versionIndex = key; + } + }); + $("#editserver-versionselect")[0].selectedIndex = versionIndex; + } + }); +}); + $('#of-deleteservermodal').on('show.bs.modal', function (e) { var result = serverarray.filter(function(obj) {return (obj.uuid === getSelectedServer());})[0]; $("#deleteserver-servername").html(result.description); diff --git a/index.html b/index.html index 45bb85e..38dae89 100644 --- a/index.html +++ b/index.html @@ -41,7 +41,7 @@
- +
@@ -79,6 +79,19 @@
+ + +