/// var _T_Dishes = function() { this.arrDishesByOrder=[]; this.init=function() { var table = this.getTable(); for (var dish in table) { this.arrDishesByOrder.push(dish); } this.arrDishesByOrder.sort(function(l,r) { if (T_Dishes.getMenuDisplayOrder(l)>T_Dishes.getMenuDisplayOrder(r)) return 1; else return -1; }); }; this.getMenuDisplayOrder=function(sID) { return parseInt(this.getTable()[sID]["MenuDisplayOrder"]); }; this.getTable = function() { return MenuDB.getTable("T_Dishes"); }; this.getDishesForCategory = function(sCategoryID) { var table = this.getTable(); var ret = []; for ( var index in this.arrDishesByOrder) { var dish=this.arrDishesByOrder[index]; if (table[dish]["CategoryID"] == sCategoryID) ret.push(dish); } return ret; }; this.getThumbPath = function(sDishID) { var table = this.getTable(); var path = table[sDishID]["PictureName"]; if (path === undefined) path = null; else path = Common.getUrl("smartphones/menus/" + T_Sites.getMenuID() + "/thumbs/" + path); return path; }; this.getImagePath = function(sDishID) { var table = this.getTable(); var path = table[sDishID]["PictureName"]; if (path === undefined) path = null; else path = Common.getUrl("smartphones/menus/" + T_Sites.getMenuID() +"/" + path); return path; }; this.getName = function(sDishID) { currentLang = T_MenuLanguages.getCurrentLanguageId(); if (currentLang == "1") currentLang = ""; var ret = this.getTable()[sDishID]["Name" + currentLang]; if (ret==undefined || ret=="") ret=this.getTable()[sDishID]["Name"]; if (ret === undefined) ret = ""; return ret; }; this.getDescription = function(sDishID) { currentLang = T_MenuLanguages.getCurrentLanguageId(); if (currentLang == "1") currentLang = ""; ret = this.getTable()[sDishID]["Description" + currentLang]; if (ret==undefined || ret=="") ret=this.getTable()[sDishID]["Description"]; if (ret === undefined) ret = ""; return ret; }; this.getPrice = function(sDishID) { return this.getTable()[sDishID]["Price"]; }; this.searchDishes = function(sToken, startAfterDish) { sToken=sToken.toLowerCase(); // create the fields to search in var currentLang = T_MenuLanguages.getCurrentLanguageId(); if (currentLang == "1") currentLang = ""; var fieldName = "Name" + currentLang; var fieldDescription = "Description" + currentLang; // loop all dishes var table = this.getTable(); var ret = []; var iCount = 0; var bMatch; var bCheck = (startAfterDish == null || startAfterDish === undefined); for ( var index in this.arrDishesByOrder) { var dish =this.arrDishesByOrder[index]; if (!bCheck) {//check if arrived to the startDish, if (dish.equals(startAfterDish)) bCheck = true; } else { bMatch = false; var dishName=table[dish][fieldName]; if (dishName==undefined || dishName==null || dishName=="") dishName=table[dish]["Name"]; if (dishName != null && dishName!=undefined && dishName.toLowerCase().indexOf(sToken) != -1) bMatch = true; if (!bMatch) { var description = table[dish][fieldDescription]; if (fieldDescription != "Description" && (description==undefined || description==null || description=="")) description=table[dish]["Description"]; if (description != null && description!=undefined && description.toLowerCase().indexOf(sToken) != -1) bMatch = true; } if (bMatch) { iCount++; ret.push(dish); } if (iCount>=20) break; } } return ret; }; }; var T_Dishes=new _T_Dishes(); T_Dishes.init();