ordersprinter/webapp/kitchenbar.js

497 lines
17 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"];
var isInitialized = false;
var displayWorkToDo = false;
var displayFinished = false;
var displayHeaderFooter = false;
var cookedEntries = null;
var entriesToCook = null;
var user = "";
var beepordered = 0;
var oneclickcooked = 0;
function beep() {
var snd = new Audio("data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQwAEaYLWfkWgAI0wWs/ItAAAGDgYtAgAyN+QWaAAihwMWm4G8QQRDiMcCBcH3Cc+CDv/7xA4Tvh9Rz/y8QADBwMWgQAZG/ILNAARQ4GLTcDeIIIhxGOBAuD7hOfBB3/94gcJ3w+o5/5eIAIAAAVwWgQAVQ2ORaIQwEMAJiDg95G4nQL7mQVWI6GwRcfsZAcsKkJvxgxEjzFUgfHoSQ9Qq7KNwqHwuB13MA4a1q/DmBrHgPcmjiGoh//EwC5nGPEmS4RcfkVKOhJf+WOgoxJclFz3kgn//dBA+ya1GhurNn8zb//9NNutNuhz31f////9vt///z+IdAEAAAK4LQIAKobHItEIYCGAExBwe8jcToF9zIKrEdDYIuP2MgOWFSE34wYiR5iqQPj0JIeoVdlG4VD4XA67mAcNa1fhzA1jwHuTRxDUQ//iYBczjHiTJcIuPyKlHQkv/LHQUYkuSi57yQT//uggfZNajQ3Vmz+Zt//+mm3Wm3Q576v////+32///5/EOgAAADVghQAAAAA//uQZAUAB1WI0PZugAAAAAoQwAAAEk3nRd2qAAAAACiDgAAAAAAABCqEEQRLCgwpBGMlJkIz8jKhGvj4k6jzRnqasNKIeoh5gI7BJaC1A1AoNBjJgbyApVS4IDlZgDU5WUAxEKDNmmALHzZp0Fkz1FMTmGFl1FMEyodIavcCAUHDWrKA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TTdNa325mImNg3TTPV9q3pmY0xoO6bv3r00y+IDGid/9aaaZTGMuj9mpu9Mpio1dXrr5HERTZSmqU36A3CumzN/9Robv/Xx4v9ijkSRSNLQhAWumap82WRSBUqXStV/YcS+XVLnSS+WLDroqArFkMEsAS+eWmrUzrO0oEmE40RlMZ5+ODIkAyKAGUwZ3mVKmcamcJnMW26MRPgUw6j+LkhyHGVGYjSUUKNpuJUQoOIAyDvEyG8S5yfK6dhZc0Tx1KI/gviKL6qvvFs1+bWtaz58uUNnryq6kt5RzOCkPWlVqVX2a/EEBUdU1KrXLf40GoiiFXK///qpoiDXrOgqDR38JB0bw7SoL+ZB9o1RCkQjQ2CBYZKd/+VJxZRRZlqSkKiws0WFxUyCwsKiMy7hUVFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d//uQRCSAAjURNIHpMZBGYiaQPSYyAAABLAAAAAAAACWAAAAApUF/Mg+0aohSIRobBAsMlO//Kk4soosy1JSFRYWaLC4qZBYWFRGZdwqKiwkNBVmoWFSJkWFxX4FFRQWR+LsS4W/rFRb/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU=");
snd.play();
}
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",false);
}
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(answer) {
if (answer.status == "OK") {
entriesToCook = answer.msg.tocook;
fillTableWithEntriesToCookCore();
bindEntriesToCook();
var newproductsToPrepare = answer.msg.newproducts;
if ((newproductsToPrepare == 1) && (beepordered == 1)) {
beep();
}
}
}
function removeOrRedeclareAnIdFromPrepared(theId,doRemove) {
$.each(entriesToCook, function (j, table) {
var aList = table.queueitems;
var tablename = table.table;
var i=0;
var found = false;
for (i=0;i<aList.length;i++) {
var anEntry = aList[i];
if (anEntry.id == theId) {
found = true;
var longname = anEntry.longname;
var isguestorder = anEntry.isguestorder;
var option = anEntry.option;
var extras = anEntry.extras;
break;
}
}
if (found) {
if (doRemove) {
aList.splice(i,1);
var newEntry = {
id: theId,
tablename: tablename,
longname: longname,
isguestorder: isguestorder,
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 (oneclickcooked == 1) {
doRemove = true;
}
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) {
var idlist = this.id;
var idarr = idlist.split("_");
var firstid = idarr[0]; // this is the id to handle!
var doRemove = false;
if (oneclickcooked == 1) {
doRemove = true;
}
if ($(this).hasClass("cooking")) {
doRemove = true;
}
if (doRemove) {
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.isguestorder == 1) {
label = "<span class='guestorder'>" + label + "</span>";
}
if (entry.cooking != '') {
theme ='d';
status = "cooking";
label += "<small><i> (" + entry.cooking + ")</i></small>";
}
var extratxt = createExtraParagraph(entry.extras);
var entryToAdd = {
name: label + extratxt,
isguestorder: entry.isguestorder,
cooking: entry.cooking,
queueid: entry.id,
option: option,
waiticon: entry.waiticon
};
var setLength = qset.length;
qset[setLength] = entryToAdd;
});
var grouped = groupItemToMake(qset);
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<Math.min(length,10);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 {
$("#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 übermittelt");
}
function setUser(userAndVersion) {
user = userAndVersion.user;
}
function insertGeneralConfigItems(configResult) {
if (configResult.status == "OK") {
var values = configResult.msg;
beepordered = values.beepordered;
oneclickcooked = values.oneclickcooked;
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
}
}
function setWorkMode(urlsuffix) {
displayWorkToDo = true;
displayFinished = true;
displayHeaderFooter = true;
return;
}
/**
* Not possible in setWorkMode, because set Lang would overwrite.
* So set headlines in method that can be called later
*/
function setHeadlines() {
if (!displayHeaderFooter) {
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 isguestorders = [];
var options = [];
var extras = [];
var tables = [];
var queueids = [];
var grouped = {
counts:counts,
joinedvals : joinedvals,
names: names,
isguestorders: isguestorders,
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 isguestorder = anEntry.isguestorder;
var option=anEntry.option;
var extras = anEntry.extras;
var table = anEntry.table;
var queueid = anEntry.queueid;
var joinedNeedle = name + "-" + isguestorder + " - " + option + "-" + "-" + table + "_" + extras;
var index = grouped.joinedvals.indexOf(joinedNeedle);
if (index >= 0) {
grouped.counts[index] = grouped.counts[index] + 1;
var queueidsarr = grouped.queueids[index];
queueidsarr[queueidsarr.length] = queueid;
grouped.queueids[index] = queueidsarr;
} else {
var gLength = grouped.counts.length;
grouped.counts[gLength] = 1;
grouped.joinedvals[gLength] = joinedNeedle;
grouped.names[gLength] = name;
grouped.isguestorders[gLength] = isguestorder;
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 isguestorders = [];
var options = [];
var cookings = [];
var waiticons = [];
var queueids = [];
var grouped = { counts:counts,
joinedvals : joinedvals,
names: names,
isguestorders: isguestorders,
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 isguestorder = anEntry.isguestorder;
var option=anEntry.option;
var waiticon = anEntry.waiticon;
var cooking = anEntry.cooking;
var queueid = anEntry.queueid;
var joinedNeedle = name + "-" + isguestorder + "-" + option + "-" + waiticon + "-" + cooking;
var index = grouped.joinedvals.indexOf(joinedNeedle);
if (index >= 0) {
grouped.counts[index] = grouped.counts[index] + 1;
var queueidsarr = grouped.queueids[index];
queueidsarr[queueidsarr.length] = queueid;
grouped.queueids[index] = queueidsarr;
} else {
var gLength = grouped.counts.length;
grouped.counts[gLength] = 1;
grouped.joinedvals[gLength] = joinedNeedle;
grouped.names[gLength] = name;
grouped.isguestorders[gLength] = isguestorder;
grouped.options[gLength] = option;
grouped.cookings[gLength] = cooking;
grouped.waiticons[gLength] = waiticon;
grouped.queueids[gLength] = [queueid];
}
}
return grouped;
}