UNPKG

listojs

Version:

a package for restaurant management

1,106 lines (1,029 loc) 174 kB
/* listo_bl.js 14.11.2019 5:14:31,81 */ /*-----------------------------------*/ /* admin.js */ let softwareProduct = "Listorante Admin"; module = "admin.js"; release = "_d1a6f"; applicationID = 1; //setTexts(); getCustomerId(); function setTexts() { //setElemText(5); setElemText(8); setElemText(9); setElemText(10); setElemText(11); setElemText(12); setElemText(13); setElemText(14); setElemText(15); setElemText(16); setElemText(17); setElemText(18); setElemText(19); setElemText(20); /* setElemText(21); setElemText(22); setElemText(23); setElemText(24); setElemText(25);*/ setElemText(26); setElemText(39); setElemText(40); setElemText(41); // setElemText(104); setElemText(748); const moreInfoText = getTextById(225); assignInnerText("moreinfoText_Orders", moreInfoText); assignInnerText("moreinfoText_Bills", moreInfoText); assignInnerText("moreinfoText_Messages", moreInfoText); assignInnerText("moreinfoText_Guests", moreInfoText); assignInnerText("ordersText", getTextById(12)); assignInnerText("billsText", getTextById(9)); assignInnerText("messagesText", getTextById(13)); assignInnerText("guestsText", getTextById(8)); document.getElementById('loading').innerHTML = images.logosmall; console.log("Set load-image to: " + images.logosmall); } function assignInnerText(elementName, text) { try { const element = document.getElementById(elementName); if (element) { element.innerText = text; } } catch (err) { console.warn(err); } } function showShoppingPage() { getCustomerCredits(function (data) { const chargeTable = formRowDiw("chargesTableID", 6); getCreditCharges(function (data) { const chargesTableObject = { IDENTIFIER: "charges-data", jsonRMLData: data, header: ['#', getTextById(743)], columnIndices: [0, 1], actions: [], dataColumnIndices: [], dataColumnNames: [] }; listoHTML.createTable.call(chargesTableObject, "chargesTableID", false); }, function (err) { showHttpErrorMessage("main-content", err); }); let creditsObj = {}; creditsObj.amount = "n.n."; creditsObj.lastupdate = "n.n."; creditsObj.amount = data.rows[0].s[0]; creditsObj.lastupdate = data.rows[0].s[1]; ; const creditsAmount = formLabel(creditsObj.amount, ""); console.log("Credits retrieved successfully: " + JSON.stringify(data)); try { const buyButton = formButtonWithIconAndBadge(744, 'badgebutton', 'bg-green', creditsObj.amount, 'fa fa-battery-3', 'buyCredits'); const breaks = breakLines(2); const subscriptions = formButtonWithIcon(749, "subscriptionButtonID", "glyphicon glyphicon-certificate", "buySubscription"); // const endSubscription = formButtonWithIcon(750, "endSubscriptionButtonID", "glyphicon glyphicon-off", "endSubscription"); const creditsLastUpDated = formLabel(creditsObj.lastupdate + ")", ""); const labelCreditAmount = formLabel(getTextById(742) + "&nbsp;&nbsp;&nbsp;&nbsp;", ""); const labelCreditLastUpdated = formLabel("&nbsp;&nbsp;&nbsp;(" + getTextById(743) + "&nbsp;&nbsp;&nbsp;", ""); const buyForm = [labelCreditAmount, creditsAmount, labelCreditLastUpdated, creditsLastUpDated, breaks, buyButton, subscriptions, chargeTable]; listoHTML.buildForm("#main-content", 8, buyForm); } catch (err) { console.error(JSON.stringify(err)); } }, function (error) { const errJsonized = JSON.stringify(error); console.error("Credits could not be retrieved : " + errJsonized); showHttpErrorMessage("main-content", error); }); } /* * * * Admin-Menu/ Function 2/ Common function for all sub-functions: Show existing * tables */ function showTables() { apiCall_listorante_public_showtables(function (data) { const action1 = [ "edit_element_table", actionModifyStyle.elements[0] + getTextById(105) + actionModifyStyle.elements[1]]; const action2 = [ "delete_element_table", actionDeleteStyle.elements[0] + getTextById(106) + actionDeleteStyle.elements[1]]; // End of TODO const dataColumnNames1 = ["idcustomertable", "places", "isseat", "description", "description_locale"]; const dataColumnIndices1 = [0, 1, 2, 3, 4]; const dataColumnNames2 = ["idcustomertable"]; const dataColumnIndices2 = [0]; const tableObject = { IDENTIFIER: "admin-showTables", jsonRMLData: data, header: [getTextById(43), getTextById(42), getTextById(45), "", ""], columnIndices: [4, 3, 1], actions: [action1, action2], dataColumnIndices: [dataColumnIndices1, dataColumnIndices2], dataColumnNames: [dataColumnNames1, dataColumnNames2], rowFormat: function (rowIndex, sArray) { const transform = []; // transform = sArray; if (sArray[1] < 3) { for (let l = 0; l < sArray.length; l++) transform[l] = DataStyle.evidence2Open + sArray[l] + DataStyle.evidence2Close; //debug("sArray[1]<3:", release, sArray, // transform); return transform; } else if (rowIndex === 0) { for (let l = 0; l < sArray.length; l++) transform[l] = DataStyle.evidence3Open + sArray[l] + DataStyle.evidence3Close; //debug("rowindex 0 or 1:", release, sArray, //transform); return transform; } else { return sArray; } }, /*cellFormat: function (columnIndex, rowIndex, TDopen, data, TDclose) { if (columnIndex === 2 && data > 0) { return TDopen + DataStyle.evidence1Open + data + DataStyle.evidence1Close + TDclose; } else { return TDopen + data + TDclose; } },*/ }; listoHTML.createTable.call(tableObject, "main-content"); }, function (err) { showHttpErrorMessage("main-content", err); }); } $(document).on("click", ".table-list", function () { showTables(); }) /* * Admin-Menu/ Function 1 / Dashboard * * */ // 1. Table Overview for dashboard $(document) .on( 'click', '.table-overview', function () { apiCall_listorante_admin_admindash(function (data) { // If success const tableOverviewTableObject = { IDENTIFIER: "admin-dash-overview-table", jsonRMLData: data[2], header: [getTextById(28), getTextById(63), getTextById(97), getTextById(64), getTextById(65), getTextById(66), getTextById(67), getTextById(612), getTextById(613)], columnIndices: [1, 3, 4, 5, 7, 10, 11, 12, 13], actions: [], dataColumnIndices: [], dataColumnNames: [], cellFormat: function (c, r, o, cell, cl) { let currency; if (c === 4) currency = getCurrency(); else currency = ""; if (c === 0) return `${o}${cell}${cl}`; else if (c === 3 || c === 4 || c === 8) return `${o}${Number(cell).toFixed(2)}${currency}${cl}`; else return `${o}${parseInt(cell, 10)}${cl}`; } }; listoHTML.createTable.call( tableOverviewTableObject, "main-content"); }, function (err) { // If failed showHttpErrorMessage("main-content", err); }); }); // 2. Kitchen Overview for preparing items $(document) .on( 'click', '.kitchen-overview', function () { $("#main-content").html(""); $("#main-content").html(images.loading); apiCall_listorante_admin_orders( function (data) { // If success to get data // Create table Object const tableObject = { actions: [], IDENTIFIER: "admin-itemtable", jsonRMLData: data, header: [getTextById(68), getTextById(69), getTextById(36), getTextById(50), getTextById(70), getTextById(71), getTextById(72), getTextById(73), getTextById(74)], columnIndices: [1, 2, 4, 5, 6, 8, 10, 11, 12], dataColumnIndices: [], dataColumnNames: [], rowFormat: function (rowIndex, sArray) { const status = sArray[8]; if (sArray[9] === "1") { sArray[8] = DataStyle.statusOrderedStartTag + " id='orderStatus" + sArray[0] + "'>" + status + DataStyle.statusOrderedEndTag; } else if (sArray[9] === "2") { sArray[8] = DataStyle.statusPreparationOpenTag + " id='orderStatus" + sArray[0] + "'>" + status + DataStyle.statusPreparationEndTag; } else if (sArray[9] === "3") { sArray[8] = DataStyle.statusDeliveredStartTag + " id='orderStatus" + sArray[0] + "'>" + status + DataStyle.statusDeliveredEndTag; } return sArray; } }; listoHTML.createTable.call(tableObject, "main-content"); }, function (err) { // If failed to get data showHttpErrorMessage("main-content", err); }); }); // 3. Bills Overview for preparing items $(document).on( 'click', '.bills-overview', function () { apiCall_listorante_admin_admindash(function (data) { // If success to // get data // Create new action Objects const action1 = ["viewCart", '<i class="fa fa-search"></i>']; //console.log(data); // Create table Object const dataColumnNames1 = ["idcustomertable", "description_en", "totalbills", "minbillstatus", "maxbillstatus", "mintimestamp", "maxtimestamp", "idbill"]; const dataColumnIndices1 = [0, 1, 2, 3, 4, 5, 6, 2]; const billsTableObject = { IDENTIFIER: "admin-dash-bills-table", jsonRMLData: data[0], header: [getTextById(68), getTextById(93), getTextById(95), getTextById(35), getTextById(70), getTextById(36), getTextById(97), getTextById(98), ""], columnIndices: [2, 0, 3, 4, 5, 6, 8, 9], actions: [action1], dataColumnIndices: [dataColumnIndices1], dataColumnNames: [dataColumnNames1] }; listoHTML.createTable.call(billsTableObject, "main-content"); }, function (err) { // If failed to get data showHttpErrorMessage("main-content", err); }); }) /* SHOW BILL OVERVIEW ITEMS */ $(document).on('click', '.viewCart', function () { const billnumber = $(this).data('idbill'); apiCall_listorante_admin_showcart(billnumber, function (data) { //console.log(data); update2_Cart_Admin(data); }, function (err) { showHttpErrorMessage(err); }); }); let update2_Cart_Admin = function (data) { let rowCount = 0; let TOTAL; let sArr2; sArr2 = []; const cartObject = { actions: [], dataColumns: [], dataColumnNames: [], dataColumnIndices: [], IDENTIFIER: 'waiter-Box2-table', jsonRMLData: data, header: ['', '', ''], columnIndices: [0, 1, 2, 3, 4], rowFormat: function (rIdx, sArr) { rowCount++; if (sArr[1] !== 'TOTAL') { if (rowCount == parseInt(data.count, 10)) { sArr2[0] = cartCol1(sArr); sArr2[1] = cartCol2(sArr); sArr2[2] = cartLastRow(sArr, TOTAL); } else { sArr2[0] = cartCol1(sArr); sArr2[1] = cartCol2(sArr); sArr2[2] = cartCol3(sArr); } if (document.getElementById('box1ProdCount' + sArr[2])) { $("#box1ProdCount" + sArr[2]).html(parseInt(sArr[0]) + " x"); } return sArr2; } else if (sArr[1] === 'TOTAL') { TOTAL = sArr; } }, cellFormat: function (colIdx, rowIdx, TDo, cellData, TDc) { if (colIdx < 3) { return `${TDo}${cellData}${TDc}`; } else { return ``; } } }; listoHTML.createTable.call(cartObject, 'main-content', true); }; /* * Admin-Menu/ Function 2 / Add new restaurant-table * * */ // 1. Create form with editable data $(document) .on( 'click', '.add-new-table', function () { //const description = [FormTextArea, 42, // "table_add_description", "rows='1' required "]; const description = formTextInput(42, "table_add_description", "rows='1' required", ""); //const description_locale = [FormTextArea, 43, // "table_add_description_locale", "rows=2 required "]; const description_locale = formTextInput(43, "table_add_description_locale", "rows='2' required", ""); const places = formNumericInput(45, "table_add_places", "rows='1' required", ""); //const places = [FormTextArea, 45, "table_add_places", // 'cols="4" rows="1"']; //const isseat = [FormCheckBox, 44, "table_add_isseat", ""]; //const submitButton = [FormButton, 40, "add_table", "", // "add-table"]; //const isseat = FormCheckBox(44, "table_add_isseat","",""); const submitButton = FormButton(40, "add_table", "", "add-table"); // forms: array of objects const form1 = [description, description_locale, places, //isseat, submitButton]; listoHTML.buildForm("#main-content", 6, form1); }) // 2. Submit the form with the data of the new restaurant table $(document).on( 'click', '#add_table', function () { // TODOs 1: never use String literals! Use getTextById(<n>) or // getText(<mnemonic>) instead! // If no suitable textid exists, create one in localizedText.js // for your // language // TODOs 2: Do never use alert, but implement a modal instead // TODOs 3: Use best-practice equality comparator (In this case, // probably '===') // or implement a best-practice validation-approach const description = $("#table_add_description").val(); const description_locale = $("#table_add_description_locale").val(); const places = $("#table_add_places").val(); if (description == "" || description_locale == "" || places == "") { alert(getTextById(251)); return false; } if (!$.isNumeric(places)) { alert(getTextById(252)); return false; } // let isseat = 0; // if ($("#table_add_isseat").is(":checked")) { // isseat = 1; // } apiCall_listorante_admin_tableinsert(description, description_locale, 0, places, function (data) { const release = RELEASE; if (data._rc > 0) { //alert(getTextById(253) + data._rc); document.getElementById("main-content").innerText = getTextById(253); } else { for (let i = 1; i <= parseInt(places); i++) { let username = description_locale.replace(/[^a-zA-Z]/g, "") + i; debug("Try to create user '" + username + "'...:", release); apiCall_listorante_admin_newstaff("nomail@here", "" + getTextById(76), 1, 0, "" + getTextById(102), "public", username, function (data) { debug2(module, "data of new staff", release, [data]); if (data._rc > 0) { const respTxt = "Anonymous customer " + i + " for table '" + description + "' could not be created. "; debug("" + respTxt, "" + release); data.status = data._rc; data.responseText = respTxt; showHttpErrorMessage("main-content", data); } else { debug("Anonymous customer " + i + " for table '" + description + "' was created. Username: " + username, release); let userId; try { userId = data[1].rows[0].s[0]; } catch (err) { if (!userId) { debug("" + getTextById(254), "" + release); let errData = {}; errData.status = 1400; errData.responseText = getTextById(254); showHttpErrorMessage("main-content", errData); } else { showHttpErrorMessage("main-content", err); } return false; } apiCall_listorante_admin_editprofile("nomail@here", "" + getTextById(76), userId, images.missing_image, 1, 0, "" + getTextById(102), username, function (data) { if (data._rc > 0) { { const respTxt = "Anonymous customer " + i + " for table '" + description + "' was created, but could not be edited. "; debug("" + respTxt, "" + release); data.status = data._rc; data.responseText = respTxt; showHttpErrorMessage("main-content", data); } } else { debug("Anonymous customer " + i + " for table '" + description + "' was edited. Username: " + username, release); apiCall_listorante_admin_assignrole(5, userId, function (data) { if (data._rc > 0) { { const respTxt = "Anonymous customer " + i + " for table '" + description + "' was created and edited, but role could not be assigned. "; debug("" + respTxt, "" + release); data.status = data._rc; data.responseText = respTxt; showHttpErrorMessage("main-content", data); } } }, function (err) { showHttpErrorMessage("main-content", err); }); } }, function (err) { showHttpErrorMessage("main-content", err); }); } }, function (err) { showHttpErrorMessage("main-content", err); }); } showTables(); } }, function err() { showHttpErrorMessage("main-content", err); }); }); // End of Admin-Menu/ Function 2 / Add new restaurant-table /* * Admin-Menu/ Function 2 / Edit data of restaurant-table * * */ // 1. Create form with editable data $(document) .on( 'click', '.edit_element_table', function () { debug("Edit elements: description=" + $(this).data("description"), release); const table_id = $(this).data("idcustomertable"); const description = FormTextArea(42, "table_edit_description", "rows='1' required ", $(this).data("description")); const description_locale = formTextInput(43, "table_edit_description_locale", "rows=1 required ", $(this).data("description_locale")); const places = formNumericInput(45, "table_edit_places", 'cols="4" rows="1" required', $(this).data("places")); //const isSeat = FormCheckBox(44, "table_edit_isseat", "", // $(this).data("isseat")); const submitButton = FormButton(215, "", "data-idcustomertable=\"" + table_id + "\"", "edit_table"); const form1 = [description, description_locale, places, submitButton]; // TODO following approach can be used later for adding customer-accounts //const newPassValue=makeid(6); //const newPass = formTextInput( 250, // "table_edit_newPass", //"rows=1 required ", //newPassValue); //const form1 = [description, description_locale, places, // isSeat, newPass, submitButton]; listoHTML.buildForm("#main-content", 6, form1); }) // 2. Delete a restaurant-table directly from within the shown table-list $(document).on('click', '.delete_element_table', function () { const idcustomertable = $(this).data("idcustomertable"); if (idcustomertable == "") { debug("" + getTextById(254), "" + release); let errData = {}; errData.status = 1400; errData.responseText = getTextById(254); showHttpErrorMessage("main-content", errData); return false; } apiCall_listorante_admin_tabledelete(idcustomertable, function (data) { const release = RELEASE; if (data._rc > 0) { { const respTxt = "Table with id '" + idcustomertable + "' could not be deleted. "; debug("" + respTxt, "" + release); data.status = data._rc; data.responseText = respTxt; showHttpErrorMessage("main-content", data); } } else { showTables(); } }, function (err) { showHttpErrorMessage("main-content", err); }); }); // 3. Edit restaurant-table-data with the form and submit $(document) .on( 'click', '.edit_table', function () { const release = RELEASE; //console.log(".edit-table"); const idcustomertable = $(this).data("idcustomertable"); const description = document .getElementById("table_edit_description").value; const description_locale = document .getElementById("table_edit_description_locale").value; let places = document.getElementById("table_edit_places").value; if (idcustomertable == "") { alert(getTextById(254)); return false; } if (description == "" || description_locale == "" || places == "") { alert(getTextById(251)); return false; } if (!$.isNumeric(places)) { alert(getTextById(252)); return false; } let isseat = 0; if ($("#table_edit_isseat").is(":checked")) { isseat = 1; places = 1; $("#table_edit_places").value = 1; } debug("CHECK", release, description, description_locale, idcustomertable, isseat, places); apiCall_listorante_admin_tableedit(description, description_locale, idcustomertable, isseat, places, function (data) { if (data._rc > 0) { { const respTxt = "Data of table '" + description + "' could not be edited. "; debug("" + respTxt, "" + release); data.status = data._rc; data.responseText = respTxt; showHttpErrorMessage("main-content", data); } } showTables(); }, function (err) { showHttpErrorMessage("main-content", err); }); }); $(document).on('click', '.shopping', function () { showShoppingPage(); }); $(document).on('click', '.buyCredits', function () { const currentUrl = window.location.href; sessionStorage.setItem("payment_callingPage", currentUrl); setCustomerId(); window.open("buy.html?cust=" + customerID + "&lang=" + locale, "_self"); }); $(document).on('click', '.show-Info', function () { var softwareInfo = showInfo(); //const supportButton = [FormButton, 330, "support_button", "", "support-button"]; const form1 = []; listoHTML.createForm("#main-content", 6, form1, "supportButtonForm"); $('#main-content .box-primary').prepend(softwareInfo); }); $(document).on('click', '.fadeIn-languageList', function languageListFadeIn() { $("#languageList").fadeIn(1000); }); /* $(document).on('click', '.testSteps', function () { debug("testSteps", release) createSteps(); }); function createSteps() { apiCall_listorante_public_categories(function (data) { const tData = data; let stepsHtml = ''; for (let i = 0; i < 5; i++) { let rowArr = tData.rows[i].s; let imagePath = getImagePath() + '/' + rowArr[4]; stepsHtml += `${startHeadingTag('3', "", "", "")}${rowArr[3]}${endHeadingTag('3')}${startSection('', '', '')}${startHeadingTag('2', "", "", "")}${rowArr[10]}${endHeadingTag('2')}${startParagraph('', '', '')}${imageTag(imagePath, '', '', '')}${endParagraph()}${endSection()}`; } listoHTML.createTour('#main-content', stepsHtml); }, function (err) { showHttpErrorMessage("main-content", err); }) }*/ /*-----------------------------------*/ /* admin_category.js */ module = "admin_category.js"; // SHOW CATEGORIES TABLE function showcategories() { const action1 = ["create-editcategory-form", actionModifyStyle.elements[0] + getTextById(105) + actionModifyStyle.elements[1]]; const action2 = ["delete-category", actionDeleteStyle.elements[0] + getTextById(106) + actionDeleteStyle.elements[1]]; const dataColumnNames1 = ["category", "idproductcategory", "prodcatdesc", "prodcatname", "prodcatimage", "level", "position", "hierarchy_1", "hierarchy_2", "hierarchy_3", "prodcatname_locale", "idcatstyle"]; const dataColumnIndices1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12]; const dataColumnNames2 = ["idproductcategory"]; const dataColumnIndices2 = [1]; const filterArray = []; apiCall_listorante_public_categories(function (data) { const tData = data; for (let i = 0; i < tData.count; i++) { if (jQuery.inArray(tData.rows[i].s[1], filterArray) !== -1) { delete data.rows[i]; } else { filterArray.push(tData.rows[i].s[1]); } } const admin = { IDENTIFIER: "admin-edit-category", jsonRMLData: data, header: [getTextById(229), getTextById(228), "ID", getTextById(227), getTextById(230), getTextById(310), "", ""], columnIndices: [11, 3, 1, 2, 4, 10], actions: [action1, action2], dataColumnIndices: [dataColumnIndices1, dataColumnIndices2], dataColumnNames: [dataColumnNames1, dataColumnNames2], rowFormat: function (rowIndex, dataArray) { return dataArray; }, cellFormat: function (colIndex, rowIndex, TDopen, data, TDclose) { { if (colIndex === 4) { if (!data) data = images.missing_image_txt; return TDopen + "<img src='" + getImagePath() + "/" + data + "' " + ThumbStyle.default + ">" + TDclose; } else { return TDopen + data + TDclose; } } } }; listoHTML.createTable.call(admin, "main-content"); }, function (err) { showHttpErrorMessage("main-content", err); }) }; function setParentCategory(parent_ID) { document.getElementById("parentCategoryId").innerHTML = parent_ID; debug('checked parent:', 0, parent_ID); }; function unSetParentCategory(IDcategory) { document.getElementById('parentCategoryId').innerHTML = ''; debug('un-checked parent:', 0, IDcategory); }; function linkcategory(category, parent_category) { apiCall_listorante_admin_linkcategory(category, parent_category, function (data) { if (data._rc > 0) { alert(getTextById(260)); debug("Could not assign category", release, data); } else { debug("linkcategory", release, data); } }, function (err) { showHttpErrorMessage("main-content", err); debug("Error: could not assign category", 0, err); alert(getTextById(260)); }); } // 1. Create editable form with "add-category"-event $(document) .on( 'click', '.create-addcategory-form', function () { const idproductcategory = [FormSelectBox, 53, "category_add_idproductcategory", "rows='1' required ", ""]; const prodcatdesc_locale = [FormTextArea, 227, "category_add_prodcatdesc_locale", "rows=2 required ", ""]; const prodcatname = [formTextInput, 228, "category_add_prodcatname", "rows=\"1\" required style=\"text-transform:uppercase\"", ""]; const prodcatname_locale = [formTextInput, 229, "category_add_prodcatname_locale", "rows=\"1\" required ", ""]; const prodcatimage = [formImage, 230, "file_imagefield", "required", "", ""]; const submitButton = [FormButton, 215, "add_category", "", "add-category"]; const form1 = [prodcatname_locale, prodcatname, idproductcategory, prodcatdesc_locale, prodcatimage, submitButton]; listoHTML.createForm("#main-content", 8, form1, "add-category-form"); const categoriesData = []; const dupArray = []; apiCall_listorante_public_categories(function (response) { // sessionStorage.setItem('uniqueID', ''); const tree_root = { id: "root_0", parent: "#", text: "*", state: { "opened": true, "checked": false, "selected": false } } categoriesData.push(tree_root); for (let i = 0; i < response.count; i++) { const billdata = {}; /*if (sessionStorage.getItem('uniqueID') == response.rows[i].s[1]) { if ($.inArray(response.rows[i].s[1], dupArray) !== -1) { billdata.id = i + 'rep_' + response.rows[i].s[1]; dupArray.push(i + 'rep_' + response.rows[i].s[1]); } else { billdata.id = 'rep_' + response.rows[i].s[1]; } dupArray.push(response.rows[i].s[1]); } else { billdata.id = 'cat_' + response.rows[i].s[1]; }*/ billdata.id = 'cat_' + response.rows[i].s[1]; if (response.rows[i].s[0] == 0) { billdata.parent = 'root_0'; } else { if ($.inArray(response.rows[i].s[0], dupArray) !== -1) { billdata.parent = 'rep_' + response.rows[i].s[0]; } else if ($.inArray(i + 'rep_' + response.rows[i].s[0], dupArray) !== -1) { billdata.parent = i + 'rep_' + response.rows[i].s[0]; } else { billdata.parent = 'cat_' + response.rows[i].s[0]; } } billdata.text = response.rows[i].s[11] + " [" + response.rows[i].s[1] + ": " + response.rows[i].s[3] + " ]"; debug("response.rows[" + i + "].s: " + response.rows[i].s); billdata.state = { "opened": true, "checked": false, "selected": false }; categoriesData.push(billdata); //sessionStorage.setItem('uniqueID', response.rows[i].s[1]); } $('#jstree').jstree({ 'core': { 'multiple': false, 'data': categoriesData, 'check_callback': false }, types: { "root": { "icon": "glyphicon glyphicon-record" }, "child": { "icon": "glyphicon glyphicon-minus" }, "default": { "icon": "glyphicon glyphicon-cutlery" } }, "checkbox": { 'deselect_all': true, "three_state": false }, plugins: ["types", "data", "checkbox"] }).on('open_node.jstree', function (e, data) { data.instance.set_icon(data.node, "glyphicon glyphicon-minus"); }).on('close_node.jstree', function (e, data) { data.instance.set_icon(data.node, "glyphicon glyphicon-cutlery"); }).on('loaded.jstree', function () { $("#jstree").jstree().select_node('cat_0'); $("#jstree").jstree().check_node('cat_0'); $('#product_category').val('0'); }).on("select_node.jstree unselect_node.jstree", function (e, data) { const cNode = "" + data.node.id; const underlineIdx = cNode.indexOf("_") + 1; const idcategory = cNode.substring(underlineIdx, cNode.length); $('#product_category').val(idcategory); (data.node.state.selected ? setParentCategory(idcategory) : unSetParentCategory(idcategory)) }).on("check_node.jstree uncheck_node.jstree", function (e, data) { const cNode = "" + data.node.id; const underlineIdx = cNode.indexOf("_") + 1; const idcategory = cNode.substring(underlineIdx, cNode.length); $('#product_category').val(idcategory); debug('data.node.state:', 0, data.node.state); (data.node.state.checked ? setParentCategory(idcategory) : unSetParentCategory(idcategory)); }); }, function (err) { showHttpErrorMessage("main-content", err); }); }); // 2. Add new category by submitting the form $(document).on('click', '.add-category', function () { if ($("#add-category-form").valid()) { const idproductcategory = document.getElementById('parentCategoryId').innerHTML; if (parseInt(idproductcategory, 10) >= 0) { const prodcatdesc_locale = $('#category_add_prodcatdesc_locale').val(); const prodcatname = $('#category_add_prodcatname').val().toUpperCase().replace(/[^A-Z0-9]/gmi, "_"); const prodcatname_locale = $('#category_add_prodcatname_locale').val(); const custID = getCustomerId(); if (document.getElementById('file_imagefield').value) { upload(custID, 'add-category-form', function (data) { debug("upload-data:", release, data); const imageNew = "" + data.rows[0].s[2]; const image_thumbNew = imageNew; alert(getTextById(255) + document.getElementById('file_imagefield').value + getTextById(256) + imageNew + "'"); apiCall_listorante_admin_newcategory('0', '0', '0', '0', '0', idproductcategory, -1, -1, prodcatdesc_locale, prodcatdesc_locale, imageNew, prodcatname, prodcatname_locale, function (response) { debug('response from new category:', 0, response); showcategories(); }, function (err) { showHttpErrorMessage("main-content", err); }); }, function (error) { alert(getTextById(257) + document.getElementById('file_imagefield').value + getTextById(258) + error.status); }); } else { const noImage = images.missing_image_txt; apiCall_listorante_admin_newcategory('0', '0', '0', '0', '0', idproductcategory, -1, -1, prodcatdesc_locale, prodcatdesc_locale, noImage, prodcatname, prodcatname_locale, function (response) { debug('response from new category:', 0, response); }, function (err) { showHttpErrorMessage("main-content", err); }); } document.getElementById('parentCategoryId').innerHTML = ''; } else { alert("Please select a parent category."); return; } } else { debug('Not Valid'); return; } }); /* * Admin-Menu / Edit Category * * */ // 1. Select categories-data and create table $(document).on( 'click', '.edit-category', function () { showcategories(); } ); // 2. Create editable form to change one single category $(document).on( 'click', '.create-editcategory-form', function () { release = RELEASE; debug("this.data:", release, $(this).data()); const idCatStyle = $(this).data("idcatstyle"); const category = $(this).data("category"); const idproductcategory = [FormSelectBox, 53, "category_add_idcategory", "rows='1' required ", category]; const idproductcategoryID = $(this).data("idproductcategory"); const prodcatdesc = $(this).data("prodcatdesc"); debug("create Edit category form", release, category, idproductcategoryID); if ($(this).data("prodcatimage")) { var prodcatimage = [formImage, 230, "file_imagefield", "required", $(this).data("prodcatimage"), $(this).data("prodcatimage")]; } else { var prodcatimage = [formImage, 230, "file_imagefield", "required", "", ""]; } const uploadButton = [FormButton, 17, "file_imagefield", "", "file_imagefield"]; const prodcatdesc_locale = [FormTextArea, 227, "category_add_prodcatdesc_locale", "rows=2 required ", prodcatdesc]; const prodcatname = [formTextInput, 228, "category_add_prodcatname", 'rows="1" required style="text-transform: uppercase"', $(this).data("prodcatname")]; const idStyle = [formNumericInput, 262, "product_edit_style", "required step='1'", idCatStyle]; //const idStyle = formNumericInput(262,"product_edit_style", "required step='1'",idCatStyle ); const prodcatname_locale = [formTextInput, 229, "category_add_prodcatname_locale", "rows=\"1\" required", $(this).data("prodcatname_locale")]; const submitButton = [FormButton, 215, "update_category", "", "update-category"]; const hidden_category_id = [formHiddenInput, "", idproductcategoryID, "id_of_edited_category"]; const productsDiv = [formRowDiw, "productsBox", 10]; debug("productsDiv", 0, productsDiv); const form1 = [prodcatname_locale, prodcatname, idStyle, idproductcategory, prodcatdesc_locale, prodcatimage, hidden_category_id, submitButton, productsDiv]; const productListOfCategory = []; apiCall_listorante_public_product(idproductcategoryID, function (data) { for (let i = 0; i < data.count; i++) { productListOfCategory.push(data.rows[i].s[0]); } debug("productListOfCategory", 0, productListOfCategory); apiCall_listorante_public_products(function (products) { const action_edit = ["edit_element_product", actionModifyStyle.elements[0] + getTextById(105) + actionModifyStyle.elements[1]]; const dataColumnNames1 = ["idproduct", "idlabel", "prodname_en", "image_thumb", "prodname", "price", "image", "prodinfo_en", "proddesc_en", "position", "qty_in_stock", "qty_unit", "threshold_qty"]; const dataColumnIndices1 = [0, 12, 5, 4, 1, 2, 3, 6, 7, 8, 9, 10, 11]; const products_of_category = { IDENTIFIER: "admin-edit-products_of_category", jsonRMLData: products, header: [getTextById(71), getTextById(733), getTextById(205), getTextById(61), "", ""], columnIndices: [12, 5, 4], actions: [action_edit], dataColumnIndices: [dataColumnIndices1], dataColumnNames: [dataColumnNames1], rowFormat: function (rowIndex, dataArray) { return dataArray; }, cellFormat: function (colIndex, rowIndex, TDopen, data, TDclose) { { if (colIndex === 0) { if (productListOfCategory.includes(products.rows[rowIndex].s[0])) { return TDopen + "*" + TDclose + TDopen + FormCheckBox(105, "checkProd" + products.rows[rowIndex].s[0], "class=checkProduct data-product='" + products.rows[rowIndex].s[0] + "' data-category='" + idproductcategoryID + "'", true) + TDclose + TDclose + TDopen + data + TDclose; } else return TDopen + "" + TDclose + TDopen + FormCheckBox(105, "checkProd" + products.rows[rowIndex].s[0], "class=checkProduct data-product='" + products.rows[rowIndex].s[0] + "' data-category='" + idproductcategoryID + "'", false) + TDclose + TDclose + TDopen + data + TDclose } if (colIndex === 2) return TDopen + "<img src='" + getImagePath() + "/" + data + "' width='35'>" + TDclose; else return TDopen + data + TDclose } } }; listoHTML.createTable.call(products_of_category, "productsBox", false); }, function (err) { showHttpErrorMessage("main-content", err); }); }, function (err) { showHttpErrorMessage("main-content", err); }); listoHTML.createForm("#main-content", 8, form1, 'category-edit-form'); const categoriesData = []; const dupArray = []; apiCall_listorante_public_categories(function (response) { // sessionStorage.setItem('uniqueID', ''); const tree_root = { id: "0", parent: "#", text: "", icon:"glyphicon glyphicon-cutlery", state: { opened: false, checked: false, selected: false } } categoriesData.push(tree_root); for (let i = 0; i < response.count; i++) { const billdata = {}; /* if (sessionStorage.getItem('uniqueID') == response.rows[i].s[3]) { if ($.inArray(response.rows[i].s[1], dupArray) !== -1) { billdata.id = i + 'rep_' + response.rows[i].s[1]; dupArray.push(i + 'rep_' + response.rows[i].s[1]); } else { billdata.id = 'rep_' + response.rows[i].s[1]; } dupArray.push(response.rows[i].s[1]); } else { billdata.id = 'cat_' + response.rows[i].s[1]; }*/ //billdata.id = 'cat_' + response.rows[i].s[1]; billdata.id = response.rows[i].s[1]; billdata.parent=response.rows[i].s[0]; /*if (response.rows[i].s[0] == 0) { billdata.parent = 'root_0'; } else { if ($.inArray(response.rows[i].s[0], dupArray) !== -1) { billdata.parent = 'rep_' + response.rows[i].s[0]; } else if ($.inArray(i + 'rep_' + response.rows[i].s[0], dupArray) !== -1) { billdata.parent = i + 'rep_' + response.rows[i].s[0]; } else { billdata.parent = 'cat_' + response.rows[i].s[0]; } }*/ billdata.text = response.rows[i].s[11] + " [" + response.rows[i].s[1] + ": " + response.rows[i].s[3] + " ]"; //if (billdata.id === 'cat_' + idproductcategoryID || billdata.id === 'rep_' + idproductcategoryID || billdata.id === i + 'rep_' + idproductcategoryID) // { if (parseInt(response.rows[i].s[1], 10) === parseInt(idproductcategoryID, 10)) { const release = RELEASE; const nodeState = {"disabled": true, "opened": true, "checked": false, "selected": false}; billdata.state = nodeState; //$("#"+billdata.id+"_anchor >a").css("color","red"); //console.log("Try to set color of " + "#" + billdata.id + "_anchor to red"); // console.log("parent of category " + billdata.id + "=" + billdata.parent); debug2(module, ">>>>> disable category ", release, [idproductcategoryID, billdata.parent, billdata]); } /*if (category === billdata.parent) { // I think this never occurs... const nodeState = {"opened": true, "checked": true, "selected": true}; billdata.state = nodeState; console.log(" ---- WHERE ARE WE??? "); debug2(module, " ---- WHERE ARE WE??? ", release, [category, response.rows[i].s[1], billdata]); }*/ else if (parseInt(response.rows[i].s[1], 10) === parseInt(category,10)) { const nodeState = {"opened": true, "checked": true, "selected": tru