+
\ No newline at end of file
diff --git a/www/js/index.js b/www/js/index.js
index 28ec829..71d18a2 100644
--- a/www/js/index.js
+++ b/www/js/index.js
@@ -10,6 +10,11 @@ var setupMode = false;
var serverUrl = "";
var apiKey = "";
+function showErrorScreen(message) {
+ $("#maindiv").load("parts/error.html", function () {
+ $("#errormsg").html(message);
+ });
+}
function loadSetupMode() {
$("#setupbtn").click(function () {
@@ -60,7 +65,12 @@ function loadSetupMode() {
}
function loadUserMode() {
- $("#usermode").removeClass("d-none");
+ $("#maindiv").removeClass("d-none");
+ getRoles(function (roles) {
+ for (var i = 0; i < roles.length; i++) {
+ loadRoleContent(roles[i]['id']);
+ }
+ });
}
@@ -69,6 +79,12 @@ document.addEventListener("deviceready", function () {
});
$(document).ready(function () {
+
+ $("body").on("submit", ".apiform", function (event) {
+ event.preventDefault();
+ console.log($(this).serialize() + "&key=" + apiKey);
+ });
+
if (typeof nw !== 'undefined') {
inNwjs = true;
}
@@ -80,6 +96,28 @@ $(document).ready(function () {
if (setupMode) {
loadSetupMode();
} else {
+ serverUrl = localStorage.getItem('server');
+ apiKey = localStorage.getItem('apikey');
loadUserMode();
}
-});
\ No newline at end of file
+});
+
+
+function getAPIData(action, arguments, success) {
+ arguments['key'] = apiKey;
+ arguments['action'] = action;
+ $.get(serverUrl, arguments, function (data) {
+ success(data);
+ }).fail(function (xhr) {
+ try {
+ var resp = JSON.parse(xhr.responseText);
+ if (typeof resp['status'] != 'undefined' && resp['status'] == 'ERROR') {
+ alert("Error: " + resp['message']);
+ } else {
+ alert("Error connecting to server.");
+ }
+ } catch (ex) {
+ alert("Error connecting to server.");
+ }
+ });
+}
\ No newline at end of file
diff --git a/www/js/roles.js b/www/js/roles.js
new file mode 100644
index 0000000..0cf997b
--- /dev/null
+++ b/www/js/roles.js
@@ -0,0 +1,64 @@
+/*
+ * 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/.
+ */
+
+var roles = [];
+
+const ROLE_VIEWBYID = 1;
+const ROLE_ADDEDIT = 2;
+const ROLE_ADDHIST = 3;
+const ROLE_VIEWBULK = 4;
+
+function getRoles(success) {
+ $.getJSON(serverUrl, {
+ key: apiKey,
+ action: "myroles"
+ }, function (resp) {
+ if (resp['status'] == 'OK') {
+ roles = resp['roles'];
+ success(roles);
+ } else {
+ showErrorScreen("Problem communicating with server.");
+ }
+ }).fail(function (xhr) {
+ try {
+ var resp = JSON.parse(xhr.responseText);
+ if (typeof resp['status'] != 'undefined' && resp['status'] == 'ERROR') {
+ showErrorScreen("Error: " + resp['message']);
+ } else {
+ showErrorScreen("Error connecting to server.");
+ }
+ } catch (ex) {
+ showErrorScreen("Error connecting to server.");
+ }
+ });
+}
+
+function loadRoleContent(roleid, callback) {
+ var file = "";
+ switch (roleid * 1) {
+ case ROLE_VIEWBYID:
+ file = "roles/view.html";
+ break;
+ case ROLE_ADDEDIT:
+ file = "roles/edit.html";
+ break;
+ case ROLE_ADDHIST:
+ file = "roles/history.html";
+ break;
+ default:
+ return false;
+ }
+ if (file == "") {
+ return false;
+ }
+ $.get(file, [], function (data) {
+ $("#maindiv").append(data);
+ if (typeof callback == "function") {
+ callback();
+ }
+ });
+ return true;
+}
\ No newline at end of file
diff --git a/www/js/scan.js b/www/js/scan.js
new file mode 100644
index 0000000..1253117
--- /dev/null
+++ b/www/js/scan.js
@@ -0,0 +1,27 @@
+/*
+ * 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/.
+ */
+
+function scancode(target) {
+ cordova.plugins.barcodeScanner.scan(
+ function (result) {
+ if (!result.cancelled) {
+ $(target).val(result.text);
+ }
+ },
+ function (error) {
+ alert("Scanning failed: " + error);
+ },
+ {
+ "showFlipCameraButton": true,
+ "prompt": "Scan Barcode"
+ }
+ );
+}
+$(document).ready(function () {
+ $("#maindiv").on("click", "[data-scancode]", function (e) {
+ scancode($(this).data('scancode'));
+ });
+});
\ No newline at end of file
diff --git a/www/parts/error.html b/www/parts/error.html
new file mode 100644
index 0000000..67d8f93
--- /dev/null
+++ b/www/parts/error.html
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+ Restart Application
+
+
\ No newline at end of file
diff --git a/www/roles/history.html b/www/roles/history.html
new file mode 100644
index 0000000..94c6e21
--- /dev/null
+++ b/www/roles/history.html
@@ -0,0 +1,50 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/www/roles/view.html b/www/roles/view.html
new file mode 100644
index 0000000..58c61e3
--- /dev/null
+++ b/www/roles/view.html
@@ -0,0 +1,79 @@
+
+
+
+
+
\ No newline at end of file