1 line
3.0 KiB
JavaScript
1 line
3.0 KiB
JavaScript
function newExtra(e,c,d,b){var a={id:e,name:c,price:d,maxamount:b,createTableStructureLine:function(g,f){if(e!=null){var h="<tr id='extra_"+e+"'><td><input id='extraname_"+e+"' type='text' class='extraname'></input><td><input id='extraprice_"+e+"' type='text' class='extraprice'></input><td><input id='extramaxamount_"+e+"' type='text' class='extramaxamount'></input><td><button id='delextra_"+e+"' class='extracmd'>−</button><td><button id='applyextra_"+e+"' class='extracmd'>↵</button><td><button id='upextra_"+e+"' class='extracmd'>↑</button></tr>";return h}else{var h="<tr id='extra_new_"+e+"'><td><input id='newextraname' type='text' class='extraname'></input><td><input id='newextraprice' type='text' class='extraprice'></input><td><input id='newextramaxamount' type='text' class='extramaxamount'></input><td><button id='newextra_0' class='extracmd'>+</button></tr>";return h}},insertValuesIntoMenuTable:function(){$("#extra_"+this.id+" input.extraname").val(this.name);$("#extra_"+this.id+" input.extramaxamount").val(this.maxamount);if(this.price!=null){$("#extra_"+this.id+" input.extraprice").val(this.price)}},createApplyArea:function(g){var f='<p><fieldset><div><button id="'+g+'" type="submit" data-theme="b" class="extracmd" data-icon="check">'+PROD_APPLY[lang]+"</button></div></fieldset></p>";return f}};return a}function ExtrasManagement(){this.assignedextras=[];this.allextras=[];this.initAllExtras=function(){this.allextras.forEach(function(b,a){b.amount=0})};this.setAllExtras=function(a){if((a!=null)&&(a.length>0)){this.allextras=a}else{this.allextras=[]}this.initAllExtras()};this._renderMobile=function(d,i,a,f,b,g){var e='<span id="extraamount_'+a+'" class="extraamount">';var c=e+toHtml(f)+"</span>";var h='<li data-theme="'+b+'" data-icon="'+g+'"><a href="#" id="extra_'+a+"_"+d+'" class="extrasel '+i+'">'+c+"</a></li>";return h};this.renderExtras=function(e,n,a){var m="";for(var g=0;g<this.allextras.length;g++){var f=this.allextras[g];var b=f.extraid;var j=f.name;var c="d";var k="delete";var h=f.amount;var l="";if(h>0){c="f";k="check";l='<span id="extraamount_'+b+'" class="extraamount">'+h+"x </span>"}var d=l+toHtml(j);if(a){m+='<li data-theme="'+c+'" data-icon="'+k+'"><a href="#" id="extra_'+b+"_"+e+'" class="extrasel '+n+'">'+d+"</a></li>"}else{if(h==0){m+="<li id='extra_"+b+"_"+g+"' class='extraitem' >"+d+"</li>"}else{m+="<li id='extra_"+b+"_"+g+"' class='extraitemselected' >"+d+"</li>"}}}return m};this.extraClicked=function(a){for(var c=0;c<this.allextras.length;c++){var d=this.allextras[c];if(d.extraid==a){var b=parseInt(d.amount);if(b>=parseInt(d.maxamount)){d.amount=0}else{d.amount++}}}};this.getAssignedExtras=function(){var b=[];for(var e=0;e<this.allextras.length;e++){var f=this.allextras[e];var a=f.extraid;var d=f.name;var c=f.amount;if(c>0){b[b.length]={id:a,name:d,price:f.price,amount:c}}}return b};this.calcPriceOfAssignedExtras=function(b){var c=0;if(b!=null){for(var a=0;a<b.length;a++){var d=b[a];c+=parseFloat(d.price*d.amount)}}return c}}; |