ordersprinter/gastsystem/js/ordering.js

1 line
9.2 KiB
JavaScript
Raw Normal View History

2020-11-19 23:12:46 +01:00
$(document).on("pageinit","#guest-page",function(){var a=Date.now();$("#logoarea").html('<img src="php/ossystem.php?command=getlogo&t='+a+'" style="max-height:300px;"/>');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;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+"&nbsp;&nbsp;"}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 getTables(){orders=[];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;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)&&(asktablecode==0)){tablecode="empty";dailycode="empty";timecounter=timeout;initProductsView();return}$("#tablecodediv").show();preventCollapsible();if(askdaycode==1){tablecode="empty";$("#daycodearea").show()}if(asktablecode==1){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(b){b.stopImmediatePropagation();b.preventDefault();tablecode=$("#tablecodefield").val().trim();dailycode=$("#dailycodefield").val().trim();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 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