ordersprinter/webapp/elements/product.js

384 lines
18 KiB
JavaScript

/**
*
*/
function createProdTableHeaderLine() {
var txt = "<tr><th>Name"
+ "<th>Typ&nbsp;&nbsp;"
+ "<th>Durchlauf Küche"
+ "<th>Durchlauf Bereitst."
+ "<th>Drucker" +
"<th id=shortnameheader class='prodheader'>Kurzname<th>Preis (A)" +
"<th class='prodheader'>Preis (B)" +
"<th class='prodheader'>Preis (C)" +
"<th class='prodheader'>Steuersatz" +
"<th class='prodheader'>Steuersatz Österreich" +
"<th class='prodheader'>Audio" +
"<th class='prodheader'>Verfügbar";
return txt;
}
function ident(depth) {
var txt = "";
var i=0;
for (i=0;i<depth;i++) {
txt += "&#9658;";
}
return txt;
}
function newProduct(id, longname, shortname,priceA,priceB,priceC,tax,taxaustria,amount,available,audio,favorite) {
var product = {
id:id,
longname:longname,
shortname:shortname,
priceA: priceA,
priceB: priceB,
priceC: priceC,
tax: tax,
taxaustria: taxaustria,
amount: amount,
available: available,
audio: audio,
favorite: favorite,
createTableStructureLine:function (depth,audiofiles) {
//var depthstr = " ".substring(0, depth);
var depthstr = ident(depth);
var trline = "<tr id='prodleaf_" + this.id + "'>"
+ "<td>" + depthstr + "<input type='text' class='prodlongname'></input>"
+ "<td colspan=3>"
+ "<td><input type='text' class='prodshortname'></input>"
+ "<td><input type='text' class='prodpriceA'></input>"
+ "<td><input type='text' class='prodpriceB'></input>"
+ "<td><input type='text' class='prodpriceC'></input>"
+ "<td><input type='text' class='prodtax'></input>"
+ "<td>" + this.createTaxAustriaSelection("prodtaxaustriasel_" + this.id)
+ "<td><input type='text' class='prodamount'></input>"
+ "<td>" + this.createAudioSelection(audiofiles,"audiosel_" + this.id)
+ "<td>" + this.createAvailSelection("prodavail_" + this.id,PROD_NO,PROD_YES)
+ "<td>" + this.createAvailSelection("prodfav_" + this.id,PROD_NO,PROD_YES)
+ "</tr>";
return trline;
},
insertValuesIntoMenuTable:function() {
$("#prodleaf_" + this.id + " input.prodlongname").val(this.longname);
$("#prodleaf_" + this.id + " input.prodshortname").val(this.shortname);
$("#prodleaf_" + this.id + " input.prodpriceA").val(this.priceA);
$("#prodleaf_" + this.id + " input.prodpriceB").val(this.priceB);
$("#prodleaf_" + this.id + " input.prodpriceC").val(this.priceC);
$("#prodleaf_" + this.id + " input.prodtax").val(this.tax);
$("#prodleaf_" + this.id + " input.prodamount").val(this.amount);
},
createAudioSelection:function(audiofiles,id) {
var txt = "<select id='" + id + "'><option></option>";
var i=0;
for (i=0;i<audiofiles.length;i++) {
var audiofile = audiofiles[i];
if (this.audio == audiofile) {
txt += "<option selected>" + audiofile + "</option>";
} else {
txt += "<option>" + audiofile + "</option>";
}
}
txt += "</select>";
return txt;
},
createAvailSelection:function(id,text0,text1) {
if (this.available == 1) {
return "<select id=" + id + "><option value=0>" + text0[lang] + "</option><option value=1 selected>" + text1[lang] + "</option></select>";
} else {
return "<select id=" + id + "><option value=0 selected>" + text0[lang] + "</option><option value=1>" + text1[lang] + "</option></select>";
}
},
createOption:function(value,selected,txt) {
if (value == selected) {
return "<option value='" +value + "' selected>" + txt + "</option>";
} else {
return "<option value='" +value + "'>" + txt + "</option>";
}
},
createTaxAustriaSelection:function(id) {
var txt = "<select id='" + id + "'>";
if ((this.taxaustria == 0) || (this.taxaustria == 'null')) {
this.taxaustria = 1;
}
txt += this.createOption(1,this.taxaustria,"Steuersatz 'Normal'");
txt += this.createOption(2,this.taxaustria,"Steuersatz 'Ermäßigt 1'");
txt += this.createOption(3,this.taxaustria,"Steuersatz 'Ermäßigt 2'");
txt += this.createOption(4,this.taxaustria,"Steuersatz 'Besonders'");
txt += "</select>";
return txt;
},
createTaxAustriaSel:function(id) {
var visi = ""
if (austria == 0) {
visi = " style='display:none;' ";
}
var txt = '<p><div data-role="fieldcontain" ' + visi + '>'
+ '<label for="' + id + '">Steuersatz Österreich:</label>'
+ this.createTaxAustriaSelection(id)
+ '</div></p>';
return txt;
},
createFavoriteSelection:function(id,text0,text1) {
if (this.favorite == 1) {
return "<select id=" + id + "><option value=0>" + text0[lang] + "</option><option value=1 selected>" + text1[lang] + "</option></select>";
} else {
return "<select id=" + id + "><option value=0 selected>" + text0[lang] + "</option><option value=1>" + text1[lang] + "</option></select>";
}
},
createMobileAudioSel:function(audiofiles,id) {
var txt = '<p><div data-role="fieldcontain">'
+ '<label for="' + id + '">Audiofile:</label>'
+ this.createAudioSelection(audiofiles,id)
+ '</div></p>';
return txt;
},
createMobileAvail:function(id,label) {
var txt = '<p><div data-role="fieldcontain">'
+ '<label for="' + id + '">' + label + '</label>'
+ this.createAvailSelection(id,PROD_NO,PROD_YES)
+ '</div></p>';
return txt;
},
createMobileFavorite:function(id,label) {
var txt = '<p><div data-role="fieldcontain">'
+ '<label for="' + id + '">' + label + '</label>'
+ this.createFavoriteSelection(id,PROD_NO,PROD_YES)
+ '</div></p>';
return txt;
},
createListStructureLine:function (audiofiles) {
var theme="e";
if (this.id.indexOf("n") == 0) {
theme="f";
}
var line = '<div id="cont_' + this.id + '" data-role="collapsible" data-content-theme="a" data-theme="' + theme + '">'
+'<h3><span id=prodheader_' + this.id + '>Test</span></h3>'
+ '<p><input type="hidden" name="prodid" value="' + this.id + '"></input></p>'
+ createInputField("prodlong_" + this.id,"prodlong_input_" + this.id,"longname")
+ createInputField("prodshort_" + this.id,"prodshort_input_" + this.id,"shortname")
+ '<p><div data-role="fieldcontain">'
+ createInputField("prodpriceA_" + this.id,"prodpriceA_input_" + this.id,"priceA")
+ createInputField("prodpriceB_" + this.id,"prodpriceB_input_" + this.id,"priceB")
+ createInputField("prodpriceC_" + this.id,"prodpriceC_input_" + this.id,"priceC")
+ createInputField("prodtax_" + this.id,"prodtax_input_" + this.id,"tax")
+ '</div></p>'
+ createInputField("prodamount_" + this.id,"prodamount_input_" + this.id,"amount")
+ "<div id=prodtaxaustriadiv_" + this.id + ">"
+ this.createTaxAustriaSel("taxaustriasel_" + this.id)
+ "</div>"
+ "<div id=audiocont_" + this.id + ">"
+ this.createMobileAudioSel(audiofiles,"audiosel_" + this.id)
+ "</div>"
+ "<div id=availcont_" + this.id + ">"
+ this.createMobileAvail("prodavail_" + this.id,PROD_AVAILABLE[lang])
+ "</div>"
+ "<div id=favcont_" + this.id + ">"
+ this.createMobileFavorite("prodfav_" + this.id,PROD_FAVORITE[lang])
+ "</div>"
if (theme != "f") {
line += this.createProdNavArea();
line += createInputOsCmdField("prodextra_" + this.id,"prodextrainput_" + this.id,"extra");
line += "<div id=assextralist_" + this.id + " class='assextralist'></div>";
line += createResetApplyArea("prodapply_" + this.id,"prodcancel_" + this.id,null) + '</div>';
} else {
line += this.createApplyArea("prodnew_" + this.id) + '</div>';
}
return line;
},
insertValuesIntoMenuList:function() {
if (this.id.indexOf("n") != 0) {
$("#prodheader_" + this.id).html(toHtml(this.longname));
} else {
$("#prodheader_" + this.id).html(PROD_NEW_PROD[lang]);
}
$("#prodlong_" + this.id).html(PROD_LONG_NAME[lang]);
$("#prodlong_input_" + this.id).val(this.longname);
$("#prodshort_" + this.id).html(PROD_SHORTNAME[lang]);
$("#prodshort_input_" + this.id).val(this.shortname);
$("#prodpriceA_" + this.id).html(PROD_PRICE[lang] + ' (A)');
$("#prodpriceB_" + this.id).html(PROD_PRICE[lang] + ' (B)');
$("#prodpriceC_" + this.id).html(PROD_PRICE[lang] + ' (C)');
$("#prodtax_" + this.id).html(PROD_TAX[lang]);
$("#prodtaxaustria_" + this.id).html(PROD_TAXAUSTRIA[lang]);
$("#prodamount_" + this.id).html(PROD_AMOUNT[lang]);
$("#prodpriceA_input_" + this.id).val(this.priceA.toString().replace(".",decpoint));
$("#prodpriceB_input_" + this.id).val(this.priceB.toString().replace(".",decpoint));
$("#prodpriceC_input_" + this.id).val(this.priceC.toString().replace(".",decpoint));
if (this.tax != "null") {
$("#prodtax_input_" + this.id).val(this.tax.toString().replace(".",decpoint));
}
if (this.amount != "null") {
$("#prodamount_input_" + this.id).val(this.amount.toString().replace(".",decpoint));
}
$("#availcont_" + this.id).html(this.createMobileAvail("prodavail_" + this.id,PROD_AVAILABLE[lang]));
$("#favcont_" + this.id).html(this.createMobileFavorite("prodfav_" + this.id,PROD_FAVORITE[lang]));
$("#audiocont_" + this.id).html(this.createMobileAudioSel(audiofiles,"audiosel_" + this.id));
$("#prodextra_" + this.id).html(PROD_ASS_EXTRAS[lang]);
$("#prodextra_" + this.id).data("orig_assignedextras",null);
$("#prodextra_" + this.id).data("assignedextras",null);
},
createApplyArea:function(idApply) {
var txt = '<p><fieldset>'
+ '<div><button id="' + idApply + '" type="submit" data-theme="b" class="oscmd" data-icon="check">' + PROD_APPLY[lang] + '</button></div>'
+ '</fieldset></p>';
return txt;
},
createProdNavArea:function() {
var buttonUp = '<button id="produp_' + this.id + '" type="submit" data-theme="c" class="oscmd">&uarr;</button>';
var buttonDown = '<button id="proddown_' + this.id + '" type="submit" data-theme="c" class="oscmd">&darr;</button>';
var buttonDel = '<button id="proddel_' + this.id + '" type="submit" data-theme="c" class="oscmd">' + PROD_DEL[lang] + '</button>';
var aText = '';
aText += '<p><fieldset class="ui-grid-b">';
aText += ' <div class="ui-block-a delProd">' + buttonDel + '</div>';
aText += ' <div class="ui-block-b prodUp">' + buttonUp + '</div>';
aText += ' <div class="ui-block-c prodDown">' + buttonDown + '</div>';
aText += '</fieldset></p>';
return aText;
}
};
return product;
}
function createInputField(idForNameOfField,idForInputField,nameOfInputField) {
var txt = '<p><div data-role="fieldcontain">'
+ '<label for="' + idForInputField + '"><span id="' + idForNameOfField + '"></span></label>'
+ '<input type="text" name="' + nameOfInputField + '" id="' + idForInputField + '" /></div></p>';
return txt;
}
function createInputOsCmdField(idForNameOfField,idForInputField,nameOfInputField) {
var txt = '<p><div data-role="fieldcontain">'
+ '<label for="' + idForInputField + '"><span id="' + idForNameOfField + '"></span></label>'
+ '<input type="button" name="' + nameOfInputField + '" id="' + idForInputField + '" class="oscmd" value="' + PROD_DO_ASS[lang] + '" data-theme="c" /></div></p>';
return txt;
}
function createResetApplyArea(idApply,idCancel,idDel) {
var txt = '<p><fieldset class="ui-grid-';
if (idDel == null) {
txt += 'a">'
+ '<div class="ui-block-a"><button id="' + idCancel + '" type="submit" data-theme="c" class="oscmd" data-icon="back">' + PROD_CANCEL[lang] + '</button></div>'
+ '<div class="ui-block-b"><button id="' + idApply + '" type="submit" data-theme="b" class="oscmd" data-icon="check">' + PROD_APPLY[lang] + '</button></div>'
+ '</fieldset></p>';
} else {
txt += 'b">'
+ '<div class="ui-block-a"><button id="' + idCancel + '" type="submit" data-theme="c" class="oscmd" data-icon="back">' + PROD_CANCEL[lang] + '</button></div>'
+ '<div class="ui-block-b"><button id="' + idApply + '" type="submit" data-theme="b" class="oscmd" data-icon="check">' + PROD_APPLY[lang] + '</button></div>'
+ '<div class="ui-block-c"><button id="' + idDel + '" type="submit" data-theme="d" class="oscmd" data-icon="delete">' + PROD_DEL[lang] + '</button></div>'
+ '</fieldset></p>';
}
return txt;
}
function createProdType(id,name,kind,usekitchen,usesupplydesk,printer) {
var prodtype = {
id:id,
name: name,
usekitchen:usekitchen,
usesupplydesk:usesupplydesk,
kind:kind,
printer:printer,
createTableStructureLine: function (depth) {
var depthstr = ident(depth);
var trline = "<tr class='prodtype' id='prodtype_" + this.id + "'>"
+ "<td>" + depthstr + "<input type='text' class='typename'></input>"
+ "<td class='type_kind'>" + this.createTwoValSelection(kind,PROD_FOOD,PROD_DRINKS)
+ "<td class='type_usekitchen'>" + this.createTwoValSelection(usekitchen,PROD_NO,PROD_YES)
+ "<td class='type_usesupply'>" + this.createTwoValSelection(usesupplydesk,PROD_NO,PROD_YES)
+ "<td class='type_printer'>" + this.createTwoValSelection(printer,PROD_PRINTER_1,PROD_PRINTER_2)
+ "<td colspan=6>"
+ "</tr>";
return trline;
},
insertValuesIntoMenuTable:function() {
$("#prodtype_" + id + " input.typename").val(name);
},
createTwoValSelection:function(theVal,text0,text1) {
if (theVal == 1) {
return "<select><option val=0 class='no'>" + text0[lang] + "</option><option val=1 selected class='yes'>" + text1[lang] + "</option></selected>";
} else {
return "<select><option val=0 selected>" + text0[lang] + "</option><option val=1>" + text1[lang] + "</option></selected>";
}
},
createUpperMenuTypeStructure: function() {
var txt = '<h3>' + this.name + '</h3><p>'
+ "<div id=dtypekind_" + this.id + "></div>"
+ "<div id=dtypeuk_" + this.id + "></div>"
+ "<div id=dtypeus_" + this.id + "></div>"
+ "<div id=dtypeprinter_" + this.id + "></div>"
+ createInputField("typename_" + this.id,"typename_input_" + this.id,"typename_input_" + this.id)
+ createResetApplyArea("typeapply_" + this.id,"typecancel_" + this.id,"typedel_" + this.id)
+ '</p>';
return txt;
},
createLowerMenuTypeStructure: function() {
var style = ' style="background-color: white;" ';
var newTypeName = '<p><input type="text" name="newtypename" id="newtypename_' + this.id + '" placeholder="' + PROD_PLACEHOLDER_NEW_PRODTYPE[lang] + '"' + style + '/></p>';
var newTypeBtn = '<p><button id="newtype_' + this.id + '" type="submit" data-theme="c" class="oscmd">' + PROD_NEW_CAT[lang] + '</button></p>';
var assignBtn = '<p><button id="assignprod_' + this.id + '" type="submit" data-theme="c" class="oscmd">' + PROD_ASSIGN[lang] + ' &#10155; </button></p>';
return newTypeName + newTypeBtn + assignBtn;
},
insertValuesIntoMenuList:function() {
$("#typename_" + this.id).html(PROD_NAME[lang]);
$("#typename_input_" + this.id).val(this.name);
$("#dtypekind_" + this.id).html(this.createMobileSel("kind_" + this.id,this.kind,PROD_TYPE,PROD_FOOD,PROD_DRINKS));
$("#dtypeuk_" + this.id).html(this.createMobileSel("usekitchen_" + this.id,this.usekitchen,PROD_KITCHEN_BAR,PROD_NO_PASS_KITCHEN,PROD_PASS_KITCHEN));
$("#dtypeus_" + this.id).html(this.createMobileSel("usesupply_" + this.id,this.usesupplydesk,PROD_SUPPLY,PROD_NO_PASS_SUPPLY,PROD_PASS_SUPPLY));
$("#dtypeprinter_" + this.id).html(this.createMobileSel("printer_" + this.id,this.printer-1,PROD_PRINTER,PROD_PRINTER_1,PROD_PRINTER_2));
},
createMobileSel:function(id,theVal,label,text0,text1) {
var txt = '<p><div data-role="fieldcontain">'
+ '<label for="' + id + '">' + label[lang] + '</label>'
+ this.createSelection(id,theVal,text0,text1)
+ '</div></p>';
return txt;
},
createSelection:function(id,theVal,text0,text1) {
if (theVal == 1) {
return "<select id=" + id + "><option value=0>" + text0[lang] + "</option><option value=1 selected>" + text1[lang] + "</option></select>";
} else {
return "<select id=" + id + "><option value=0 selected>" + text0[lang] + "</option><option value=1>" + text1[lang] + "</option></select>";
}
}
};
return prodtype;
}