text: /*! Tetra UI v1.2.9 | (MIT Licence) (c) Viadeo/APVO Corp - inspired by Bootstrap (c) Twitter, Inc. (Apache 2 Licence) */
  
  tetra.model.register("autocomplete",{scope:"generic_autocomplete",req:{fetch:{url:"{0}",uriParams:["url"],parser:function(a,b,c){return a.id=c.id,b[c.uriParams.url]={id:c.id,completion:a},b}}},attr:{completion:{}},methods:function(){return{validate:function(a,b){return b}}}}),tetra.controller.register("autocomplete",{scope:"generic_autocomplete",use:["autocomplete"],constr:function(a,b,c,d){"use strict";return{events:{model:{autocomplete:{append:function(a){b.notify("display suggestions",a[0].get("completion"))}}},view:{"do query":function(b){b.uriParams={url:b.url},a.methods.startCountDown(function(){d("autocomplete").fetch(b)},b)},"autocompleteGeneric : click on suggestion":function(a){c.notify("autocompleteGeneric : click on suggestion",a)}}},methods:{init:function(){a.defaultTypingDelay=150,a.countDown=null},startCountDown:function(b,c){a.countDown&&window.clearTimeout(a.countDown);var d="undefined"!=typeof c.typingDelay?c.typingDelay:a.defaultTypingDelay;a.countDown=window.setTimeout(b,d,c)}}}}}),tetra.view.register("autocomplete",{scope:"generic_autocomplete",use:["autocomplete"],constr:function(a,b,c){"use strict";return{events:{user:{keydown:{".autocomplete input":function(b,c){switch(a.methods.reinit(c),b.which){case 13:c=a._container.find(".autocomplete-menu li.active");var d=a._containerId;c.length&&(b.preventDefault(),a.methods.suggestions.clickOnSuggestion(c)),a.methods.suggestions.hide(d);break;case 38:case 40:b.preventDefault()}}},keyup:{".autocomplete input":function(b,c){switch(a.methods.reinit(c),b.which){case 37:case 39:a._container.hasClass("active")||a.methods.suggestions.doQuery(c,!1);break;case 13:break;case 27:a.methods.suggestions.hide(a._containerId);break;case 38:a.methods.suggestions.select("previous");break;case 40:a.methods.suggestions.select("next");break;default:c.val().length>=parseInt(a._container.attr("data-min-length"),10)&&(a._sts=a._sts>0?a._sts:(new Date).getTime(),a.methods.suggestions.doQuery(c,!0)),0===c.val().length&&(a._sts=0,a.methods.suggestions.hide(a._containerId))}}},focus:{".autocomplete input":function(b,c){a._containerId=null,a.methods.reinit(c),c.val().length>=parseInt(a._container.attr("data-min-length"),10)&&a.methods.suggestions.doQuery(c,!0)}},blur:{".autocomplete input":function(b,c){var d=a._containerId;a.methods.reinit(c),window.setTimeout(function(){a.methods.suggestions.hide(d)},200)}},mouseover:{".autocomplete .autocomplete-menu li":function(a,b){b.addClass("active").siblings().removeClass("active")}},click:{".autocomplete .autocomplete-menu li":function(b,c){var d=a._containerId;a.methods.suggestions.clickOnSuggestion(c),a.methods.suggestions.hide(d)}}},controller:{"display suggestions":function(d){var e=!1;for(var f in d.data.completion){e=!0;break}if(!e)return a._container.removeClass("active"),c(a._menu).empty(),void 0;var g={};g.data=d.data.completion,g.query=a._input.val(),a._boldifyTerms&&(g=a.methods.suggestions.boldify(g)),b.exec(a._templateRef,g,function(b){c(a._menu).html(b)}),a._container.attr("data-no-default")||a._menu.find("li:first-child").addClass("active"),a._container.addClass("active")},"display value":function(b){a._input.val(b.value),a.methods.suggestions.hide(a._containerId)}}},methods:{init:function(){a._param="%param%",a._containerId=null,a._sts=0},reinit:function(b){a._containerId||(a._containerId=c(b.parents(".autocomplete"))[0].id,a._container=c("#"+a._containerId),a._paramName=a._container.attr("data-param")||"param",a._input=a._container.find("input"),a._menu=a._container.find("#"+a._container.attr("data-suggest-container-id")),a._templateRef=a._container.attr("data-suggest-template-ref"),a._boldifyTerms=a._container.attr("data-boldify")?a._container.attr("data-boldify").split(","):0,0===c("#tmpl_"+a._templateRef).length&&(a._templateRef=a._templateRef.substring(0,a._templateRef.indexOf("_"))+"_1"))},suggestions:{select:function(b){var c,d=a._container.find(".autocomplete-menu li"),e=d.filter(".active").removeClass("active").index();e+="next"===b?1:-1,e>=d.length&&(e=0),c=d.eq(e),c.addClass("active"),c.hasClass("no-highlight")&&a.methods.suggestions.select(b)},boldify:function(b){var c,d,e,f,g=a._boldifyTerms.length,h=new RegExp("("+b.query+")","gi");for(e in b.data)for(c=b.data[e],f=0;g>f;f++)d=a._boldifyTerms[f],b.data[e][d]=c[d].replace(h,"<b>$1</b>");return b},hide:function(a){c("#"+a).removeClass("active")},replaceParam:function(b,c){return b.replace(a._param,c)},clickOnSuggestion:function(d){var e=c.trim(c(d.find(".value")).text());"undefined"!=typeof e&&e.length>0&&a._input.val(e),b.notify("autocompleteGeneric : click on suggestion",d[0]),a._containerId=null},doQuery:function(d,e){var f=d.val(),g=a.methods.suggestions.replaceParam(a._container.attr("data-url"),f),h={url:g,id:a._containerId};e&&(h.typingDelay=a._container.attr("data-typing-delay")||void 0),h[a._paramName]=f,"quicksearch-input"===d.prop("id")&&(d.attr("data-sts",a._sts),h.sts=a._sts);var i;if(d.hasClass("schoolDepartment")){if(i=c(d.parents(".core-form"))[0],c(i).find("#schoolId").val(""),h.itemName=c(i).find(".autocompleteSchool").val(),h.itemName.blank())return;h.town=c(i).find("input.town").val()}else d.hasClass("autocompleteSchool")&&(i=c(d.parents(".core-form"))[0],c(i).find("#schoolId").val(""),c(i).find("input.town").val(""));b.notify("do query",h)}}}}}});