From 6cdc9acb6a98df7cbb6fb180aa45cb50f4a2b4b7 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Tue, 26 Dec 2017 23:02:56 -0700 Subject: [PATCH] Add setup/configuration tool, add "no connection" UI and handling --- assets/img/no-connection-horizontal.svg | 120 ++++++++++++++++++++++++ assets/img/no-connection-vertical.svg | 116 +++++++++++++++++++++++ index.html | 15 ++- js/init.js | 10 ++ js/settings.js | 37 +++++++- js/setup.js | 22 +++++ pages/login.html | 21 +++-- pages/noconnection.html | 82 ++++++++++++++++ pages/setup.html | 47 ++++++++++ 9 files changed, 458 insertions(+), 12 deletions(-) create mode 100644 assets/img/no-connection-horizontal.svg create mode 100644 assets/img/no-connection-vertical.svg create mode 100644 js/init.js create mode 100644 js/setup.js create mode 100644 pages/noconnection.html create mode 100644 pages/setup.html diff --git a/assets/img/no-connection-horizontal.svg b/assets/img/no-connection-horizontal.svg new file mode 100644 index 0000000..2b1de20 --- /dev/null +++ b/assets/img/no-connection-horizontal.svg @@ -0,0 +1,120 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/img/no-connection-vertical.svg b/assets/img/no-connection-vertical.svg new file mode 100644 index 0000000..72a6065 --- /dev/null +++ b/assets/img/no-connection-vertical.svg @@ -0,0 +1,116 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/index.html b/index.html index a1c780c..c2788e9 100644 --- a/index.html +++ b/index.html @@ -30,9 +30,22 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. + \ No newline at end of file diff --git a/js/init.js b/js/init.js new file mode 100644 index 0000000..15de116 --- /dev/null +++ b/js/init.js @@ -0,0 +1,10 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + + +$.ajaxSetup({ + timeout: 10000 +}); \ No newline at end of file diff --git a/js/settings.js b/js/settings.js index 6dd7111..eda8fdc 100644 --- a/js/settings.js +++ b/js/settings.js @@ -5,9 +5,42 @@ */ -var accounthubapi = "http://localhost/accounthub/api.php"; -var apikey = "123"; +var accounthubapi = localStorage.getItem("apiurl"); +var apikey = localStorage.getItem("apikey"); +var kioskmode = localStorage.getItem("kioskmode"); +var largebtns = localStorage.getItem("largebtns"); function getAPIKey() { return apikey; +} + +/** + * Validate the connection settings. Callback will be run with `true` an error message, or `false` for a connection failure. + * @param function callback(resp) a function to receive whether or not the settings are valid. + * @returns {undefined} + */ +function validateSettings(callback) { + $.post(accounthubapi, { + key: apikey, + action: "ping" + }, function (resp) { + if (resp.status == "OK") { + callback(true); + } else { + callback(resp.msg); + } + }, "json").fail(function (data) { + if (data.readyState == 4) { + callback(data.statusText); + } else { + callback(false); + } + }); +} + +function reloadSettings() { + accounthubapi = localStorage.getItem("apiurl"); + apikey = localStorage.getItem("apikey"); + kioskmode = localStorage.getItem("kioskmode"); + largebtns = localStorage.getItem("largebtns"); } \ No newline at end of file diff --git a/js/setup.js b/js/setup.js new file mode 100644 index 0000000..c2b900c --- /dev/null +++ b/js/setup.js @@ -0,0 +1,22 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + + +$("#settings_form").submit(function (event) { + event.preventDefault(); + localStorage.setItem("apiurl", $("#url").val()); + localStorage.setItem("apikey", $("#key").val()); + localStorage.setItem("kioskmode", $("#kioskmode").is(":checked") ? true : null); + localStorage.setItem("largebtns", $("#largebtns").is(":checked") ? true : null); + reloadSettings(); + validateSettings(function (resp) { + if (resp !== true) { + showmsg("Error", "danger", "Something is wrong. Check the settings you entered."); + return; + } + document.location.href = "index.html"; + }); +}); \ No newline at end of file diff --git a/pages/login.html b/pages/login.html index bf1d872..6b63ac3 100644 --- a/pages/login.html +++ b/pages/login.html @@ -3,7 +3,7 @@

Login

-
diff --git a/pages/noconnection.html b/pages/noconnection.html new file mode 100644 index 0000000..2234734 --- /dev/null +++ b/pages/noconnection.html @@ -0,0 +1,82 @@ + + + + +
+

No connection

+

Could not communicate with the server.

+ Try again +
\ No newline at end of file diff --git a/pages/setup.html b/pages/setup.html new file mode 100644 index 0000000..f9a67d9 --- /dev/null +++ b/pages/setup.html @@ -0,0 +1,47 @@ + +
+
+
+
+

+ Settings +

+
+
+ The connection settings are invalid. Please set them. +
+
+
+ + +
+
+ + +
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+ \ No newline at end of file