var PageJs=new Class.create;
PageJs.prototype=Object.extend(new CRUDPageJs,{loadSelect2:function(){var b,d;jQuery("select.select2").each(function(){b={};if("Infinity"===$(this).readAttribute("data-minimum-results-for-search")||"infinity"===$(this).readAttribute("data-minimum-results-for-search")||-1==$(this).readAttribute("data-minimum-results-for-search"))b.minimumResultsForSearch="Infinity";jQuery(this).select2(b)});jQuery('[search_field="mat.ingredients"]').select2({allowClear:!0,multiple:!0,width:"100%",ajax:{delay:250,url:"/ajax/getAll",
type:"GET",data:function(a){return{searchTxt:"name like ?",searchParams:["%"+a+"%"],entityName:"Ingredient",pageNo:1}},results:function(a,b,e){d=[];a.resultData&&a.resultData.items&&a.resultData.items.each(function(a){d.push({id:a.id,text:a.name,data:a})});return{results:d}}},cache:!0,escapeMarkup:function(a){return a}});jQuery('[search_field="mat.nutritions"]').select2({allowClear:!0,multiple:!0,width:"100%",ajax:{delay:250,url:"/ajax/getAll",type:"GET",data:function(a){return{searchTxt:"name like ?",
searchParams:["%"+a+"%"],entityName:"Nutrition",pageNo:1}},results:function(a,b,e){d=[];a.resultData&&a.resultData.items&&a.resultData.items.each(function(a){d.push({id:a.id,text:a.name,data:a})});return{results:d}}},cache:!0,escapeMarkup:function(a){return a}})},_getNutritionNameString:function(b){var d,a,c;d="";a=[];b.infos.material_nutrition&&Array.isArray(b.infos.material_nutrition)&&0<b.infos.material_nutrition.length&&b.infos.material_nutrition.each(function(b){b.nutrition&&b.nutrition.name&&
(c=b.nutrition.name,b.qty&&b.serveMeasurement&&b.serveMeasurement.name&&(c+="("+b.qty+" "+b.serveMeasurement.name+")"),a.push(c))});0<a.length&&(d=a.join(", "));return d},_getResultRow:function(b,d){var a,c,e;a=this;c=d||!1;e=!0===c?"strong":"span";return(new Element("span",{"class":"row"})).store("data",b).addClassName(!1===b.active&&!1===c?"warning":"").addClassName("list-group-item").addClassName("item_row").writeAttribute("item_id",b.id).insert({bottom:(new Element(e,{"class":"name col-sm-4 col-xs-12"})).update(b.name)}).insert({bottom:(new Element(e,
{"class":"description col-sm-2 col-xs-12"})).update(b.description)}).insert({bottom:(new Element(e,{"class":"ingredients col-sm-2 col-xs-12"})).update(!0===c?"Ingredients":a._getNamesString(b.infos.ingredients))}).insert({bottom:(new Element(e,{"class":"nutritions col-sm-2 col-xs-12"})).update(!0===c?"Nutritions":a._getNutritionNameString(b))}).insert({bottom:(new Element(e,{"class":"text-right btns col-sm-2 col-xs-12"})).update(!0===c?(new Element("span",{"class":"btn btn-primary btn-xs",title:"New"})).insert({bottom:new Element("span",
{"class":"glyphicon glyphicon-plus"})}).insert({bottom:" NEW"}).observe("click",function(){a._openDetailsPage()}):(new Element("span",{"class":"btn-group btn-group-xs"})).insert({bottom:(new Element("span",{"class":"btn btn-primary",title:"Delete"})).insert({bottom:new Element("span",{"class":"glyphicon glyphicon-pencil"})}).observe("click",function(){a._openDetailsPage(b)})}).insert({bottom:(new Element("span")).addClassName(!1===b.active&&!1===c?"btn btn-success":"btn btn-danger").writeAttribute("title",
!1===b.active&&!1===c?"Re-activate":"De-activate").insert({bottom:(new Element("span")).addClassName(!1===b.active&&!1===c?"glyphicon glyphicon-repeat":"glyphicon glyphicon-trash")}).observe("click",function(){if(!confirm("Are you sure you want to "+(!0===b.active?"DE-ACTIVATE":"RE-ACTIVATE")+" this item?"))return!1;a._deleteItem(b,b.active)})}))})}});