271 lines
7.2 KiB
JavaScript
271 lines
7.2 KiB
JavaScript
function initializeMainMenu(menuid) {
|
|
$.ajax({ type: "GET",
|
|
dataType: "json",
|
|
url: "php/contenthandler.php?module=admin&command=getJsonMenuItemsAndVersion",
|
|
async: false,
|
|
success : function(moduleEntries)
|
|
{
|
|
$("#versioninfo").html(moduleEntries.version + " ");
|
|
if (moduleEntries.loggedin == 1) {
|
|
$("#loggedinuser").html(" " + moduleEntries.user);
|
|
var li='<li data-role="list-divider" data-theme="b" data-role="heading">Hauptmenü</li>';
|
|
$.each(moduleEntries.menu, function (i, module) {
|
|
var name = module.name;
|
|
var link = module.link;
|
|
if ((name != "Abmelden") && (name != "Log out") && (name != "Adios")) {
|
|
li += '<li data-theme="e"><a href="' + link + '" target="_top" class="modulebutton">' + name + '</a></li>';
|
|
} else {
|
|
li += '<li data-theme="e"><a href="' + link + '" target="_top">' + name + '</a></li>';
|
|
}
|
|
});
|
|
$(menuid).empty().append(li).promise().done(function () {
|
|
$(menuid).listview("refresh");
|
|
});
|
|
$("#menuswitch").show();
|
|
} else {
|
|
$("#menuswitch").hide();
|
|
}
|
|
},
|
|
error: function( text ) {
|
|
alert( "Kommunikationsproblem zum Server bei Modulabfrage!" );
|
|
}
|
|
});
|
|
|
|
$(".modulebutton").off("click").on("click", function (e) {
|
|
var view = $(this).attr("href");
|
|
doAjax("POST","php/contenthandler.php?module=admin&command=setLastModuleOfUser",
|
|
{ view: view}, null, "Problem Benutzerdatenpflege");
|
|
});
|
|
|
|
intervalGetPrinterStatus(5);
|
|
intervalCheckConnection(2);
|
|
}
|
|
|
|
function intervalGetPrinterStatus(seconds) {
|
|
doAjax("GET","php/contenthandler.php?module=admin&command=isPrinterServerActive",null,setPrinterStatus,null,true);
|
|
var fetchTimer = setInterval(function() {
|
|
doAjax("GET","php/contenthandler.php?module=admin&command=isPrinterServerActive",null,setPrinterStatus,null,true);
|
|
}, seconds * 1000);
|
|
}
|
|
|
|
function setPrinterStatus(answer) {
|
|
if (answer.status === "OK") {
|
|
if (answer.msg === 0) {
|
|
$(".printerstatus").show();
|
|
return;
|
|
}
|
|
}
|
|
$(".printerstatus").hide();
|
|
}
|
|
|
|
function hideMenu() {
|
|
$( "#modulepanel" ).panel( "close" );
|
|
$("#menuswitch").off("click").on("click", function (e) {
|
|
$("#menuswitch").trigger("mouseout");
|
|
e.stopImmediatePropagation();
|
|
e.preventDefault();
|
|
$( "#modulepanel" ).panel( "open" );;
|
|
});
|
|
}
|
|
|
|
// to make IE happy...
|
|
function refreshList(selector) {
|
|
if ( $(selector).hasClass('ui-listview')) {
|
|
$(selector).listview('refresh');
|
|
} else {
|
|
$(selector).trigger('create');
|
|
}
|
|
}
|
|
|
|
function doAjax(getOrPost, url, data, functionToCallIfSuccess, errorMsg, doAsync) {
|
|
if (typeof doAsync === 'undefined') {
|
|
doAsync = false;
|
|
}
|
|
$.ajax({type: getOrPost,
|
|
url: url,
|
|
dataType: "json",
|
|
data: data,
|
|
async: doAsync,
|
|
success: function (jsonContent)
|
|
{
|
|
if (functionToCallIfSuccess != null) {
|
|
functionToCallIfSuccess(jsonContent);
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
|
|
if (url != "php/debug.php") {
|
|
var debugData = {
|
|
cmd: url,
|
|
fct: functionToCallIfSuccess.name,
|
|
xhr: xhr.responseText,
|
|
errormsg: errorMsg,
|
|
status: status
|
|
};
|
|
|
|
var n = getMillis();
|
|
|
|
if (errorMsg != null) {
|
|
if ($(".connectionstatus").is(":visible")) {
|
|
alert("Kommunikation zum Server ist unterbrochen!");
|
|
} else {
|
|
var errorMsgTxt = errorMsg + error + " (" + url + ")";
|
|
alert("Kommunikationsfehler zum Server: " + errorMsgTxt);
|
|
doAjax("POST", "php/debug.php?n=" + n, debugData, null, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function doAjaxAsync(getOrPost, url, data, functionToCallIfSuccess) {
|
|
$.ajax({type: getOrPost,
|
|
url: url,
|
|
dataType: "json",
|
|
data: data,
|
|
async: true,
|
|
success: function (jsonContent)
|
|
{
|
|
if (functionToCallIfSuccess != null) {
|
|
functionToCallIfSuccess(jsonContent);
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
if (url != "php/debug.php") {
|
|
var debugData = {
|
|
cmd: url,
|
|
fct: functionToCallIfSuccess.name,
|
|
xhr: xhr.responseText,
|
|
errormsg: errorMsg,
|
|
status: status
|
|
};
|
|
|
|
var n = getMillis();
|
|
|
|
if (errorMsg != null) {
|
|
if ($(".connectionstatus").is(":visible")) {
|
|
alert("Kommunikation zum Server ist unterbrochen!");
|
|
} else {
|
|
var errorMsgTxt = errorMsg + error + " (" + url + ")";
|
|
alert("Kommunikationsfehler zum Server: " + errorMsgTxt);
|
|
doAjax("POST", "php/debug.php?n=" + n, debugData, null, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function doAjaxTransmitData(getOrPost,url,data,functionToCallIfSuccess,errorMsg,dataToTransmit) {
|
|
$.ajax({ type: getOrPost,
|
|
url: url,
|
|
dataType: "json",
|
|
data: data,
|
|
async: false,
|
|
success : function(jsonContent)
|
|
{
|
|
if (functionToCallIfSuccess != null) {
|
|
functionToCallIfSuccess(jsonContent,dataToTransmit);
|
|
}
|
|
},
|
|
error: function(xhr,status,error ) {
|
|
if (errorMsg != null) {
|
|
var errorMsgTxt = errorMsg + ", Status: " + status + ", Error:" + error + ", Msg: " + xhr.responseText + " (" + url + ")";
|
|
alert( "Kommunikationsfehler zum Server: " + errorMsgTxt);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function doAjaxSuppressError(getOrPost,url,data,functionToCallIfSuccess,errorMsg) {
|
|
$.ajax({ type: getOrPost,
|
|
url: url,
|
|
dataType: "json",
|
|
data: data,
|
|
async: false,
|
|
success : function(jsonContent)
|
|
{
|
|
if (functionToCallIfSuccess != null) {
|
|
functionToCallIfSuccess(jsonContent);
|
|
}
|
|
},
|
|
error: function( text ) {
|
|
functionToCallIfSuccess("ERROR");
|
|
}
|
|
});
|
|
}
|
|
|
|
function doAjaxNonJsonNonCall(getOrPost,url,data) {
|
|
$.ajax({ type: getOrPost,
|
|
data : data,
|
|
url: url,
|
|
async: false,
|
|
error: function( text ) {
|
|
alert( "Kommunikationsproblem zum Server" );
|
|
}
|
|
});
|
|
}
|
|
|
|
function toHtml(text) {
|
|
if (typeof text === 'string') {
|
|
return (text.replace(/"/g, '"').replace(/</g, "<").replace(/>/g, ">"));
|
|
} else {
|
|
return text;
|
|
}
|
|
}
|
|
|
|
function createExtraParagraph(extras) {
|
|
if ((extras == null) || (extras == "")) {
|
|
return "";
|
|
}
|
|
var extratxt = "";
|
|
for (var j=0;j<extras.length;j++) {
|
|
extratxt += "<p>+ " + toHtml(extras[j]) + "</p>";
|
|
}
|
|
return extratxt;
|
|
}
|
|
|
|
function checkForLogIn() {
|
|
doAjax("GET","php/contenthandler.php?module=admin&command=isUserAlreadyLoggedIn",null,handleTestForLoggedIn,null);
|
|
}
|
|
function handleTestForLoggedIn(answer) {
|
|
if (answer != "YES") {
|
|
setTimeout(function(){document.location.href = "index.html"},250);
|
|
}
|
|
}
|
|
function isInt(value) {
|
|
if(Math.floor(value) == value && $.isNumeric(value)) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function isFloat(n){
|
|
return Number(n) === n && n % 1 !== 0;
|
|
}
|
|
|
|
function getMillis() {
|
|
var d = new Date();
|
|
var n = d.getTime();
|
|
return n;
|
|
}
|
|
|
|
function intervalCheckConnection(seconds) {
|
|
checkConnection();
|
|
var fetchTimer = setInterval(function() {
|
|
checkConnection();
|
|
}, seconds * 1000);
|
|
}
|
|
|
|
function checkConnection() {
|
|
var img = new Image();
|
|
img.onerror = function () {
|
|
$(".connectionstatus").show();
|
|
}
|
|
img.onload = function () {
|
|
$(".connectionstatus").hide();
|
|
}
|
|
img.src = "img/gray.png?t=" + (+new Date);
|
|
} |