1 line
6.9 KiB
JavaScript
1 line
6.9 KiB
JavaScript
$(document).on("pageinit","#guest-page",function(){intervalCheckLastOsSystemAccess(5);getTables()});var selectedTableid=null;var syncisWorking=false;var dailycode=null;var tablecode=null;var products=null;var types=null;var currency="";var decpoint=".";var selectedproduct=null;var selectedtable=null;var timeout=0;var timecounter=0;function intervalCheckLastOsSystemAccess(b){doAjax("GET","php/system.php?command=getlastosaccess",null,insertSyncIsWorking,true);var a=setInterval(function(){doAjax("GET","php/system.php?command=getlastosaccess",null,insertSyncIsWorking,true)},b*1000)}function timeouting(){timecounter=0;var a=setInterval(function(){updateTimer()},1000)}function createReadableTimeValue(c){var b=Math.floor(c/60);var a=c%60;return"Verbleibende Zeit bis Neuanmeldung: "+b+":"+a}function updateTimer(){if(timecounter>0){$("#timecounter").show();$("#timecounter").html(createReadableTimeValue(timecounter))}else{$("#timecounter").hide()}if(timecounter>0){timecounter--;if(timecounter==0){var a=$("#tableselection").is(":visible");if(!a){$(".notcollapsible").hide();getTables()}}}}function insertSyncIsWorking(a){if(a.status=="OK"){if(a.msg==1){syncisWorking=true}else{syncisWorking=false}if(syncisWorking){$("#warningdiv").hide()}else{$("#warningdiv").show()}}}function getTables(){doAjax("GET","php/tables.php?command=gettables",null,insertTables,"Fehler beim Abruf der Tische",true)}function preventCollapsible(){$(".notcollapsible").off("collapsiblecollapse").on("collapsiblecollapse",function(a){a.stopImmediatePropagation();a.preventDefault();var b=this.id;$("#"+b).collapsible("expand")})}function insertTables(b){if(b.status!="OK"){alert("Es ist ein Fehler aufgetreten: "+b.msg)}else{currency=b.currency;decpoint=b.decpoint;timeout=b.timeout;var a="";a+=fillSelectionBox("tableselect",b.msg,"Tischauswahl");$("#tableselectionbox").html(a);$("#tableselection").show();$("#tableselection").trigger("create");preventCollapsible();$("#tableselectionbox").off("change").on("change",function(c){c.stopImmediatePropagation();c.preventDefault();selectedTableid=$("#tableselect").val();if(selectedTableid!=(-1)){$("#tableselection").hide();handleCodeInput()}});timeouting()}}function handleCodeInput(){$("#tablecodediv").show();preventCollapsible();$("#tablecodefield").val("");$("#dailycodefield").val("");$("#codebackbtn").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();$("#tablecodediv").hide();getTables()});$("#submitcodesbtn").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();tablecode=$("#tablecodefield").val();dailycode=$("#dailycodefield").val();var a={tableid:selectedTableid,tablecode:tablecode,dailycode:dailycode};doAjax("POST","php/tables.php?command=checkcodes",a,handleCodeCheck,"Fehler bei der Abfrage der Codes",true)})}function handleCodeCheck(a){if(a.status!="OK"){alert(a.msg)}else{timecounter=timeout;initProductsView()}}function fillSelectionBox(f,b,d){var e='<div class="ui-field-contain">';e+='<select name="'+f+'" id="'+f+'" data-theme="f">';e+='<option value="-1">'+toHtml(d)+"</option>";for(var c=0;c<b.length;c++){var a=b[c];e+="<option value="+a.id+">"+toHtml(a.name)+"</option>"}e+="</select>";return e}function toHtml(a){return(a.replace(/"/g,""").replace(/</g,"<").replace(/>/g,">"))}function initProductsView(){doAjax("POST","php/menu.php?command=getmenu",null,showProductsView,"Fehler bei der Abfrage der Speisekarte",true)}function showProductsView(a){preventCollapsible();if(a.status!="OK"){alert("Fehler: "+a.msg);$("#productsdiv").hide();getTables()}else{products=a.msg.products;types=a.msg.types;showProdTypes(0);$("#tablecodediv").hide();$("#productsdiv").show();$("#prodbackbtn").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();$("#productsdiv").hide();getTables()})}}function showProdTypes(c){var a=createTypesHtml(c);if(a!=null){$("#typesdiv").html(a);$("#typesdiv").trigger("create")}bindProdTypes();var b=createProdsHtml(c);if(b!=null){$("#prodsdiv").show();$("#prodsdiv").html(b);$("#prodsdiv").trigger("create");bindProducts()}else{$("#prodsdiv").hide()}preventCollapsible()}function bindProducts(){$(".product").off("click").on("click",function(c){c.stopImmediatePropagation();c.preventDefault();var b=this.id.split("_")[1];selectedproduct=b;$("#productsdiv").hide();$("#prodconfirmdiv").show();var a=getProductName(b);$("#selectedprod").html(toHtml(a));bindProdConfirm()})}function bindProdTypes(){$(".prodtype").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();var a=this.id.split("_")[1];showProdTypes(a)});$(".up").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();var a=this.id.split("_")[1];showProdTypes(a)})}function createTypesHtml(d){if(types==null){return null}var c='<ul data-role="listview" id="search-list" data-divider-theme="a" data-inset="true">';c+='<li data-role="list-divider" data-theme="b" data-role="heading">Produktgruppen</li>';for(var b=0;b<types.length;b++){var a=types[b];var e=a.reference;if(e==d){c+='<li data-theme="f" data-icon="false"><a href="#" id="type_'+a.id+'" class="prodtype" >'+toHtml(a.name)+"</a></li>"}}if(d!=0){var f=getParentOfReference(d);c+='<li data-theme="d" data-icon="false"><a href="#" id="type_'+f+'" class="up" >Zurück</a></li>'}c+="</ul>";return c}function getParentOfReference(c){for(var b=0;b<types.length;b++){var a=types[b];if(a.id==c){return a.reference}}return 0}function createProdsHtml(d){var c=false;var b='<ul data-role="listview" id="search-list" data-divider-theme="a" data-inset="true">';b+='<li data-role="list-divider" data-theme="b" data-role="heading">Produktauswahl</li>';for(var a=0;a<products.length;a++){var f=products[a];if(f.ref==d){c=true;var e=f.price;e=e.replace(".",decpoint)+" "+currency;b+='<li data-theme="f" data-icon="false"><a href="#" id="type_'+f.id+'" class="product" >'+toHtml(f.longname)+" <i>("+e+")</i></a></li>"}}b+="</ul>";if(c){return b}else{return null}}function getProductName(b){for(var a=0;a<products.length;a++){if(products[a].id==b){return products[a].longname}}return""}function bindProdConfirm(){$("#prodconfirmbackbtn").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();$("#prodconfirmdiv").hide();initProductsView()});$("#prodconfirmbtn").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();var a={prodid:selectedproduct,tableid:selectedTableid,dailycode:dailycode,tablecode:tablecode};doAjax("POST","php/queue.php?command=putintoqueue",a,askForMore,"Fehler beim Senden der Produktdaten",true)})}function askForMore(a){if(a.status!="OK"){alert("Fehler: "+a.msg)}else{$("#prodconfirmdiv").hide();$("#askformorediv").show();preventCollapsible();$("#askformorenobtn").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();$("#askformorediv").hide();getTables()});$("#askformoreyesbtn").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();$("#askformorediv").hide();initProductsView()})}}; |