1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
$(document).on("pageinit","#guest-page",function(){var d=Date.now();$("#logoarea").html('<img src="php/ossystem.php?command=getlogo&t='+d+'" style="max-height:300px;"/>');intervalCheckLastOsSystemAccess(5);tablesPreselected=false;var c=location.search;if(c.length!=0){var a=c.slice(1);var f=a.split("=");if((f.length>=2)&&(f[0]=="code")){var b=f[1];var e=b.split("_");if(e.length>=2){tablecode=e[0];selectedTableid=e[1];tablesPreselected=true}}}getTables()});var tablesPreselected=false;var selectedTableid=null;var syncisWorking=false;var dailycode=null;var tablecode=null;var products=null;var types=null;var currency="";var guesttheme=0;var decpoint=".";var selectedproduct=null;var selectedtable=null;var timeout=0;var timecounter=0;var askdaycode=1;var asktablecode=1;var fetchTimer=null;var orders=[];var tablevalues=[];function intervalCheckLastOsSystemAccess(b){doAjax("GET","php/ossystem.php?command=getsystemstatus",null,insertSyncIsWorking,true);var a=setInterval(function(){doAjax("GET","php/ossystem.php?command=getsystemstatus",null,insertSyncIsWorking,true)},b*1000)}function timeouting(){if(fetchTimer!=null){clearTimeout(fetchTimer)}if(timeout!=0){timecounter=0;fetchTimer=setInterval(function(){updateTimer()},1000)}}function createReadableTimeValue(c){var b=Math.floor(c/60);var a=c%60;if(a<10){a="0"+a.toString()}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(c){if(c.status=="OK"){if(c.msg.lastaccessok==1){syncisWorking=true}else{syncisWorking=false}if(syncisWorking){$("#warningdiv").hide()}else{$("#warningdiv").show()}var a=c.msg.dbwritestatus;var d=a.writeable;if(d==0){var b=a.file;if(a.reason!=""){b+=" (Zusatzinfo: "+a.reason+")"}$("#writeprotectedfile").html(b);$("#warningdiv2").show()}else{$("#warningdiv2").hide()}}}function requestTableInfoWithoutGUI(){orders=[];doAjax("GET","php/tables.php?command=gettables",null,insertTablesNoGui,"Fehler beim Abruf der Tische",true)}function requestTableInfoWithGUI(){orders=[];doAjax("GET","php/tables.php?command=gettables",null,insertTables,"Fehler beim Abruf der Tische",true)}function getTables(){if(tablesPreselected){requestTableInfoWithoutGUI()}else{requestTableInfoWithGUI()}}function preventCollapsible(){$(".notcollapsible").off("collapsiblecollapse").on("collapsiblecollapse",function(a){a.stopImmediatePropagation();a.preventDefault();var b=this.id;$("#"+b).collapsible("expand")})}function insertTablesNoGui(a){if(a.status!="OK"){alert("Es ist ein Fehler aufgetreten: "+a.msg)}else{currency=a.currency;guesttheme=a.guesttheme;decpoint=a.decpoint;timeout=a.timeout;askdaycode=a.askdaycode;asktablecode=a.asktablecode;tablevalues=a.msg;timeouting();handleCodeInput()}}function insertTables(b){if(b.status!="OK"){alert("Es ist ein Fehler aufgetreten: "+b.msg)}else{currency=b.currency;guesttheme=b.guesttheme;decpoint=b.decpoint;timeout=b.timeout;askdaycode=b.askdaycode;asktablecode=b.asktablecode;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(){if((askdaycode==0)&&tablesPreselected){startCodeCheck(selectedTableid,tablecode,"empty");return}if((askdaycode==0)&&(asktablecode==0)){if(!tablesPreselected){tablecode="empty"}dailycode="empty";timecounter=timeout;initProductsView();return}$("#tablecodediv").show();preventCollapsible();if(askdaycode==1){if(!tablesPreselected){tablecode="empty"}$("#daycodearea").show()}if((asktablecode==1)&&!tablesPreselected){dailycode="empty";$("#tablecodearea").show()}$("#tablecodefield").val("");$("#dailycodefield").val("");$("#codebackbtn").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();hideCodeAreas();$("#tablecodediv").hide();getTables()});$("#submitcodesbtn").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();if(!tablesPreselected){tablecode=$("#tablecodefield").val().trim()}dailycode=$("#dailycodefield").val().trim();startCodeCheck(selectedTableid,tablecode,dailycode)})}function startCodeCheck(a,d,b){var c={tableid:a,tablecode:d,dailycode:b};doAjax("POST","php/tables.php?command=checkcodes",c,handleCodeCheck,"Fehler bei der Abfrage der Codes",true)}function hideCodeAreas(){$("#daycodearea").hide();$("#tablecodearea").hide()}function handleCodeCheck(a){if(a.status!="OK"){alert(a.msg)}else{hideCodeAreas();timecounter=timeout;initProductsView()}}function fillSelectionBox(f,b,d){tablevalues=b;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){timecounter=timeout;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){timecounter=timeout;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();timecounter=timeout;var a=getProductName(selectedproduct);$("#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(b){var d=null;for(var e=0;e<types.length;e++){var j=types[e];if(j.id==b){d=j;break}}if(d==null){return""}var a=j.hasprodimages;var f=false;var g='<ul data-role="listview" id="search-list" data-divider-theme="a" data-inset="true">';g+='<li data-role="list-divider" data-theme="b" data-role="heading">Produktauswahl</li>';for(var e=0;e<products.length;e++){var h=products[e];if(h.ref==b){f=true;var c=getProdDetails(h.id);g+=createProdListEntry(c,a,"")}}g+="</ul>";if(f){return g}else{return null}}function getProdDetails(e){for(var d=0;d<products.length;d++){var g=products[d];if(g.id==e){var f=g.price;f=f.replace(".",decpoint)+" "+currency;var c=Date.now();var a="php/ossystem.php?command=getprodimage&prodid="+g.id+"&t="+c;var b=toHtml(g.longname);return{id:e,prodname:b,imgurl:a,price:f}}}return null}function getProductName(b){for(var a=0;a<products.length;a++){if(products[a].id==b){return products[a].longname}}return""}function createProdListEntry(b,d,a){var c='<li data-theme="f" data-icon="false"><a href="#" id="type_'+b.id+'" class="product '+a+'">';if(d){c+='<img src="'+b.imgurl+'" class="centermobileimg" />'}c+=toHtml(b.prodname);c+=" <i>("+b.price+")</i></a></li>";return c}function bindProdConfirm(){$("#prodconfirmbackbtn").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();$("#prodconfirmdiv").hide();initProductsView()});$("#prodconfirmbtn").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();orders[orders.length]={prodid:selectedproduct};askForMore()})}function askForMore(){createOrdersList("#orderslist");$("#prodconfirmdiv").hide();$("#askformorediv").show();$("#askformoreyesno").show();timecounter=timeout;preventCollapsible();$("#askformorenobtn").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();$("#askformorediv").hide();getTables()});$("#askformoreyesbtn").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();$("#askformorediv").hide();initProductsView()});$("#sendordersbtn").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();putIntoQueue()})}function putIntoQueue(){if(orders.length==0){alert("Es sind keine Artikel in der Liste zur Bestellung vorgemerkt!");return}var b=Date.now();var a={ordertime:b,tableid:selectedTableid,dailycode:dailycode,tablecode:tablecode,orders:orders};doAjax("POST","php/queue.php?command=putintoqueue",a,startNewOrderingDueToServerAnswer,"Fehler beim Senden der Produktdaten",true)}function startNewOrderingDueToServerAnswer(a){if(a.status=="OK"){alert("Die Bestellung wurde abgeschickt!");$("#askformorediv").hide();orders=[];getTables()}else{alert("Es ist ein Fehler aufgetreten: "+a.msg)}}function createOrdersList(a){var d='<p><ul data-role="listview" id="search-list" data-divider-theme="a" data-inset="true">';d+='<li data-role="list-divider" data-theme="b" data-role="heading">Bestellte Produkte für den Tisch "'+toHtml(getNameOfSelectedTable())+'"</li>';for(var c=0;c<orders.length;c++){var f=orders[c];var e=f.prodid;var b=getProdDetails(e);d+=createProdListEntry(b,true,"orderedproduct")}d+="</ul>";$(a).html(d);$(a).trigger("create");bindProductEntryInOrdersListForDeletion(a)}function bindProductEntryInOrdersListForDeletion(a){$(".orderedproduct").off("click").on("click",function(g){g.stopImmediatePropagation();g.preventDefault();var b=this.id.split("_")[1];var h=null;for(var c=0;c<orders.length;c++){var f=orders[c];var d=f.prodid;if(d==b){h=c}}if(h!=null){orders.splice(h,1);createOrdersList(a)}})}function getNameOfSelectedTable(){for(var a=0;a<tablevalues.length;a++){var b=tablevalues[a];if(b.id==selectedTableid){return b.name}}return""}; |