489 lines
13 KiB
JavaScript
489 lines
13 KiB
JavaScript
var KB_READY = ["Zubereitet","Ready","Preparado"];
|
||
var KB_MAX_WAIT = ["Max. Wartezeit: ","Max. waited: ","Tiempo de espera: "];
|
||
var KB_TO_MAKE = ["Herzustellen","To prepare","Para preparar"];
|
||
var KB_TO_FINISHED = ["Fertig","Ready to serve","Completo"];
|
||
var KB_TABLE = ["Tisch","Table","Mesa"];
|
||
|
||
// user has rights (default: no)
|
||
var isInitialized = false;
|
||
|
||
var displayWorkToDo = false;
|
||
var displayFinished = false;
|
||
var displayHeaderFooter = false;
|
||
|
||
var cookedEntries = null;
|
||
var entriesToCook = null;
|
||
var user = "";
|
||
|
||
// increase performance by calling AJAX a bit later as a thread
|
||
function declareProductBeCookingOrCooked(queueid,action) {
|
||
window.setTimeout(function(){declareProductBeCookingOrCooked_orig(queueid,action)},100);
|
||
}
|
||
|
||
function declareProductBeCookingOrCooked_orig(queueid,action) {
|
||
var data = { queueid: queueid,
|
||
action : action};
|
||
doAjax("POST","php/contenthandler.php?module=queue&command=declareProductBeCookingOrCooked",data,resultOfProductDeclaration,"could not declare product");
|
||
}
|
||
|
||
function resultOfProductDeclaration(jsonText) {
|
||
if (jsonText.status != "OK") {
|
||
alert("Fehler " + jsonText.code + ": " + jsonText.msg);
|
||
}
|
||
}
|
||
|
||
function declareProductNOTBeCooked(queueid) {
|
||
var data = { queueid: queueid };
|
||
doAjax("POST","php/contenthandler.php?module=queue&command=declareProductNotBeCooked",data,resultOfProductDeclaration,"could not unmake product");
|
||
}
|
||
|
||
function fillTableWithEntriesToCook(allEntriesToCook) {
|
||
entriesToCook = allEntriesToCook;
|
||
fillTableWithEntriesToCookCore();
|
||
bindEntriesToCook();
|
||
}
|
||
|
||
function removeOrRedeclareAnIdFromPrepared(theId,doRemove) {
|
||
$.each(entriesToCook, function (j, table) {
|
||
var aList = table.queueitems;
|
||
var tablename = table.table;
|
||
|
||
// now remove this from the list or change entry!
|
||
|
||
var i=0;
|
||
var found = false;
|
||
for (i=0;i<aList.length;i++) {
|
||
var anEntry = aList[i];
|
||
if (anEntry.id == theId) {
|
||
// then delete it
|
||
found = true;
|
||
var longname = anEntry.longname;
|
||
var option = anEntry.option;
|
||
var extras = anEntry.extras;
|
||
break;
|
||
}
|
||
}
|
||
if (found) {
|
||
if (doRemove) {
|
||
aList.splice(i,1);
|
||
// add to list above
|
||
var newEntry = {
|
||
id: theId,
|
||
tablename: tablename,
|
||
longname: longname,
|
||
option: option,
|
||
extras: extras
|
||
};
|
||
cookedEntries.splice(0,0,newEntry);
|
||
fillTableWithCookedEntriesCore();
|
||
bindCookedEntries();
|
||
} else {
|
||
var theEntry = aList[i];
|
||
theEntry.cooking = user;
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
function bindEntriesToCook() {
|
||
$(".toprep").off("click").on("click", function (e) {
|
||
e.stopImmediatePropagation();
|
||
e.preventDefault();
|
||
var ids = this.closest(".preparedlistitem").id;
|
||
var doRemove = false;
|
||
if ($(this.closest(".preparedlistitem")).hasClass("cooking")) {
|
||
doRemove = true;
|
||
}
|
||
var idarr = ids.split("_");
|
||
var i=0;
|
||
for (i=0;i<idarr.length;i++) {
|
||
var id = idarr[i];
|
||
if (doRemove) {
|
||
removeOrRedeclareAnIdFromPrepared(id,true);
|
||
declareProductBeCookingOrCooked(id,"r");
|
||
} else {
|
||
removeOrRedeclareAnIdFromPrepared(idarr[i],false);
|
||
declareProductBeCookingOrCooked(id,"c");
|
||
}
|
||
}
|
||
fillTableWithEntriesToCookCore();
|
||
bindEntriesToCook();
|
||
});
|
||
$(".preparedlistitem").off("click").on("click", function (e) {
|
||
// first get all the ids:
|
||
var idlist = this.id;
|
||
var idarr = idlist.split("_");
|
||
var firstid = idarr[0]; // this is the id to handle!
|
||
var doRemove = false;
|
||
if ($(this).hasClass("cooking")) {
|
||
doRemove = true;
|
||
declareProductBeCookingOrCooked(firstid,"r");
|
||
} else {
|
||
declareProductBeCookingOrCooked(firstid,"c");
|
||
}
|
||
|
||
removeOrRedeclareAnIdFromPrepared(firstid,doRemove);
|
||
|
||
fillTableWithEntriesToCookCore();
|
||
bindEntriesToCook();
|
||
});
|
||
}
|
||
|
||
function fillTableWithEntriesToCookCore() {
|
||
var aList = '';
|
||
$.each(entriesToCook, function (i, table) {
|
||
aList += listOfTable(table);
|
||
});
|
||
|
||
$("#listWithEntriesToCook").html(aList);
|
||
$("#listWithEntriesToCook").trigger("create");
|
||
}
|
||
|
||
function listOfTable(table) {
|
||
var tableid = table.tableid;
|
||
var tablename = table.table;
|
||
var maxWaitTime = table.maxwaittime;
|
||
|
||
var itemsForTable = table.queueitems;
|
||
|
||
var qset = [];
|
||
|
||
$.each(itemsForTable, function (i, entry) {
|
||
var option = '';
|
||
if (entry.option != '') {
|
||
var theComment = toHtml(entry.option);
|
||
option = '<p>' + theComment + '</p>';
|
||
}
|
||
var icon = "check";
|
||
var status = "not_cooking";
|
||
var label = toHtml(entry.longname);
|
||
if (entry.cooking != '') {
|
||
theme ='d';
|
||
status = "cooking";
|
||
label += "<small><i> (" + entry.cooking + ")</i></small>";
|
||
}
|
||
|
||
var extratxt = createExtraParagraph(entry.extras);
|
||
|
||
var entryToAdd = {
|
||
name: label + extratxt,
|
||
cooking: entry.cooking,
|
||
queueid: entry.id,
|
||
option: option,
|
||
waiticon: entry.waiticon
|
||
};
|
||
var setLength = qset.length;
|
||
qset[setLength] = entryToAdd;
|
||
});
|
||
|
||
var grouped = groupItemToMake(qset);
|
||
|
||
// now format these entries
|
||
var aList = '<ul data-role="listview" id="' + tableid + '" data-divider-theme="a" data-inset="true">';
|
||
aList += '<li data-role="list-divider" data-theme="c" data-role="heading">' + tablename + ' (' + KB_MAX_WAIT[lang] + maxWaitTime + ' min)</li>';
|
||
|
||
var i=0;
|
||
var length = grouped.counts.length;
|
||
|
||
for (i=0;i<length;i++) {
|
||
var img = '<img src="img/waittimes/' + grouped.waiticons[i] + '" />';
|
||
var id_joined = grouped.queueids[i].join("_");
|
||
var theme = 'c';
|
||
var icon = "check";
|
||
var status = "not_cooking";
|
||
var count = grouped.counts[i];
|
||
|
||
var label = grouped.names[i];
|
||
var imgpart = "";
|
||
if (count > 1) {
|
||
label = "<span style='font-size: 23px;'>" + count + "x</span> " + label;
|
||
imgpart = "<div class='counting toprep'><img src='img/multi.png' /></div>";
|
||
}
|
||
var cooking = grouped.cookings[i];
|
||
var option = grouped.options[i];
|
||
if (cooking != '') {
|
||
theme ='d';
|
||
icon = "arrow-d";
|
||
status = "cooking";
|
||
}
|
||
aList += '<li data-theme="' + theme + '" data-icon="' + icon + '" class="preparedlistitem ' + status + '" + id="'+ id_joined + '"><a href="#">' + img + label + option + imgpart + '</a></li>';
|
||
}
|
||
|
||
aList += '</ul>';
|
||
|
||
return aList;
|
||
}
|
||
|
||
function fillTableWithCookedEntries(entries) {
|
||
cookedEntries = entries;
|
||
fillTableWithCookedEntriesCore();
|
||
bindCookedEntries();
|
||
}
|
||
|
||
function bindCookedEntries() {
|
||
$(".deliveredlistitem").off("click").on("click", function (e) {
|
||
|
||
var idlist = this.id;
|
||
var idarr = idlist.split("_");
|
||
var firstid = idarr[0]; // this is the id to handle!
|
||
declareProductNOTBeCooked(firstid);
|
||
|
||
getAndDisplayAllEntries();
|
||
|
||
});
|
||
}
|
||
|
||
function fillTableWithCookedEntriesCore() {
|
||
if ((cookedEntries != null) && (cookedEntries.length > 0)) {
|
||
|
||
var qset = [];
|
||
|
||
$.each(cookedEntries, function (i, entry) {
|
||
var option = '';
|
||
if (entry.option != '') {
|
||
var theComment = toHtml(entry.option);
|
||
option = '<p>' + theComment + '</p>';
|
||
}
|
||
|
||
var label = toHtml(entry.longname);
|
||
|
||
var extratxt = createExtraParagraph(entry.extras);
|
||
|
||
var table = entry.tablename;
|
||
var entryToAdd = {
|
||
name: label + extratxt,
|
||
queueid: entry.id,
|
||
option: option,
|
||
extras: extratxt,
|
||
table: table
|
||
};
|
||
var setLength = qset.length;
|
||
qset[setLength] = entryToAdd;
|
||
});
|
||
|
||
var grouped = groupMadeItems(qset);
|
||
|
||
var theList = '<ul data-role="listview" id="deliveredProdsList" data-divider-theme="a" data-inset="true">';
|
||
theList += '<li data-role="list-divider" data-theme="b" data-role="heading" data-icon="check">' + KB_READY[lang] + '</li>';
|
||
|
||
var length = grouped.counts.length;
|
||
|
||
for (i=0;i<length;i++) {
|
||
var count = grouped.counts[i];
|
||
|
||
var label = grouped.names[i];
|
||
var imgpart = "";
|
||
if (count > 1) {
|
||
label = "<span style='font-size: 23px;'>" + count + "x</span> " + label;
|
||
//imgpart = "<div class='counting'><img src='img/multi.png' /></div>";
|
||
}
|
||
var option = grouped.options[i];
|
||
var tablename = KB_TABLE[lang] + ": " + grouped.tables[i];
|
||
var infotext = tablename;
|
||
if (option != '') {
|
||
infotext = option + "<p>" + tablename + "</p>";
|
||
}
|
||
|
||
var id_joined = grouped.queueids[i].join("_");
|
||
theList += '<li data-theme="e" data-icon="arrow-u" id="' + id_joined + '" class="deliveredlistitem"><a href="#">' + label;
|
||
theList += '<p>' + infotext + '</p>' + imgpart;
|
||
theList += '</A></LI>';
|
||
}
|
||
|
||
theList += '</ul>';
|
||
|
||
$("#listWithCookedEntries").html(theList);
|
||
$("#listWithCookedEntries").trigger("create");
|
||
|
||
|
||
} else {
|
||
// remove also headline of list, if list is empty
|
||
$("#listWithCookedEntries").html("");
|
||
}
|
||
}
|
||
|
||
function handleGlobalRefresh(name) {
|
||
parent.frames[name].location.reload();
|
||
getAndDisplayAllEntries();
|
||
}
|
||
|
||
function getAndDisplayAllEntries()
|
||
{
|
||
checkForLogIn();
|
||
if (isInitialized) {
|
||
if (displayWorkToDo) {
|
||
getEntriesToCook();
|
||
}
|
||
if (displayFinished) {
|
||
getCookedEntries();
|
||
}
|
||
}
|
||
}
|
||
|
||
function getGeneralConfigItems() {
|
||
doAjax("GET", "php/contenthandler.php?module=admin&command=getGeneralConfigItems", null, insertGeneralConfigItems, "Fehler Konfigurationsdaten");
|
||
doAjax("GET","php/contenthandler.php?module=admin&command=getJsonMenuItemsAndVersion",null,setUser,"Benutzerdaten nicht <20>bermittelt");
|
||
}
|
||
|
||
function setUser(userAndVersion) {
|
||
user = userAndVersion.user;
|
||
}
|
||
|
||
function insertGeneralConfigItems(configResult) {
|
||
if (configResult.status == "OK") {
|
||
var values = configResult.msg;
|
||
setLanguage(values.userlanguage);
|
||
isInitialized = true;
|
||
if (displayHeaderFooter) {
|
||
initializeMainMenu("#modulemenu");
|
||
} else {
|
||
$("#modulepanel").hide();
|
||
$("#menuswitch").hide();
|
||
$("#thefooterr").hide();
|
||
}
|
||
initializeEverything();
|
||
setHeadlines();
|
||
getAndDisplayAllEntries();
|
||
} else {
|
||
setTimeout(function(){document.location.href = "index.html"},250); // not logged in
|
||
//alert("Fehler beim Aufruf der Seite: " + configResult.msg);
|
||
}
|
||
}
|
||
|
||
function setWorkMode(urlsuffix) {
|
||
if (urlsuffix.length<=1) {
|
||
// no limitations - display all
|
||
displayWorkToDo = true;
|
||
displayFinished = true;
|
||
displayHeaderFooter = true;
|
||
} else {
|
||
var modes = (urlsuffix.replace("?","")).split(",");
|
||
$("#hrline").hide();
|
||
if (modes.indexOf("toprepare") >= 0) {
|
||
displayWorkToDo = true;
|
||
}
|
||
if (modes.indexOf("finished") >= 0) {
|
||
displayFinished = true;
|
||
}
|
||
if (modes.indexOf("headerfooter") >= 0) {
|
||
displayHeaderFooter = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Not possible in setWorkMode, because set Lang would overwrite.
|
||
* So set headlines in method that can be called later
|
||
*/
|
||
function setHeadlines() {
|
||
if (!displayHeaderFooter) {
|
||
// then replace by individual footer (embedded in iframe)
|
||
if (displayWorkToDo) {
|
||
$("#moduleheadline").html(KB_TO_MAKE[lang]);
|
||
} else if (displayFinished) {
|
||
$("#moduleheadline").html(KB_TO_FINISHED[lang]);
|
||
}
|
||
$("#headerline").trigger("create");
|
||
}
|
||
}
|
||
|
||
function groupMadeItems(theSet) {
|
||
var counts = [];
|
||
var joinedvals = [];
|
||
var names = [];
|
||
var options = [];
|
||
var extras = [];
|
||
var tables = [];
|
||
var queueids = [];
|
||
|
||
var grouped = {
|
||
counts:counts,
|
||
joinedvals : joinedvals,
|
||
names: names,
|
||
options: options,
|
||
extras: extras,
|
||
tables: tables,
|
||
queueids : queueids
|
||
};
|
||
|
||
var i=0;
|
||
for (i=0;i<theSet.length;i++) {
|
||
var anEntry = theSet[i];
|
||
var name=anEntry.name;
|
||
var option=anEntry.option;
|
||
var extras = anEntry.extras;
|
||
var table = anEntry.table;
|
||
var queueid = anEntry.queueid;
|
||
var joinedNeedle = name + "-" + option + "-" + "-" + table + "_" + extras;
|
||
var index = grouped.joinedvals.indexOf(joinedNeedle);
|
||
if (index >= 0) {
|
||
// element is already in group
|
||
grouped.counts[index] = grouped.counts[index] + 1;
|
||
var queueidsarr = grouped.queueids[index];
|
||
// append the current queueid
|
||
queueidsarr[queueidsarr.length] = queueid;
|
||
grouped.queueids[index] = queueidsarr;
|
||
} else {
|
||
// new element to be inserted in grouped
|
||
var gLength = grouped.counts.length;
|
||
grouped.counts[gLength] = 1;
|
||
grouped.joinedvals[gLength] = joinedNeedle;
|
||
grouped.names[gLength] = name;
|
||
grouped.options[gLength] = option;
|
||
grouped.extras[gLength] = extras;
|
||
grouped.tables[gLength] = table;
|
||
grouped.queueids[gLength] = [queueid];
|
||
}
|
||
}
|
||
return grouped;
|
||
}
|
||
|
||
function groupItemToMake(theSet) {
|
||
var counts = [];
|
||
var joinedvals = [];
|
||
var names = [];
|
||
var options = [];
|
||
var cookings = [];
|
||
var waiticons = [];
|
||
var queueids = [];
|
||
|
||
var grouped = { counts:counts,
|
||
joinedvals : joinedvals,
|
||
names: names,
|
||
options: options,
|
||
cookings: cookings,
|
||
waiticons: waiticons,
|
||
queueids : queueids
|
||
};
|
||
|
||
var i=0;
|
||
for (i=0;i<theSet.length;i++) {
|
||
var anEntry = theSet[i];
|
||
var name=anEntry.name;
|
||
var option=anEntry.option;
|
||
var waiticon = anEntry.waiticon;
|
||
var cooking = anEntry.cooking;
|
||
var queueid = anEntry.queueid;
|
||
var joinedNeedle = name + "-" + option + "-" + waiticon + "-" + cooking;
|
||
var index = grouped.joinedvals.indexOf(joinedNeedle);
|
||
if (index >= 0) {
|
||
// element is already in group
|
||
grouped.counts[index] = grouped.counts[index] + 1;
|
||
var queueidsarr = grouped.queueids[index];
|
||
// append the current queueid
|
||
queueidsarr[queueidsarr.length] = queueid;
|
||
grouped.queueids[index] = queueidsarr;
|
||
} else {
|
||
// new element to be inserted in grouped
|
||
var gLength = grouped.counts.length;
|
||
grouped.counts[gLength] = 1;
|
||
grouped.joinedvals[gLength] = joinedNeedle;
|
||
grouped.names[gLength] = name;
|
||
grouped.options[gLength] = option;
|
||
grouped.cookings[gLength] = cooking;
|
||
grouped.waiticons[gLength] = waiticon;
|
||
grouped.queueids[gLength] = [queueid];
|
||
}
|
||
}
|
||
return grouped;
|
||
} |