You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB
JavaScript

/*
* 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;
}