/**
* Copyright 2014 Telerik AD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
!function(e,define){define(["./kendo.data.min","./kendo.popup.min"],e)}(function(){return function(e,t){function n(t,i){t.filters&&(t.filters=e.grep(t.filters,function(e){return n(e,i),e.filters?e.filters.length:e.field!=i}))}var i=window.kendo,r=i.ui,o=r.Widget,a=i.keys,s=i.support,l=i.htmlEncode,u=i._activeElement,d="id",c="li",f="change",h="k-state-focused",p="k-state-hover",g="k-loading",m="open",v="close",_="select",y="selected",b="progress",w="requestEnd",x="width",k=e.extend,T=e.proxy,C=s.browser,S=C.msie&&9>C.version,F=/"/g,D={ComboBox:"DropDownList",DropDownList:"ComboBox"},M=i.ui.DataBoundWidget.extend({init:function(t,n){var i,r=this,a=r.ns;o.fn.init.call(r,t,n),t=r.element,r._isSelect=t.is(_),r._template(),r.ul=e('
').css({overflow:s.kineticScrollNeeded?"":"auto"}).on("mouseenter"+a,c,function(){e(this).addClass(p)}).on("mouseleave"+a,c,function(){e(this).removeClass(p)}).on("click"+a,c,T(r._click,r)).attr({tabIndex:-1,role:"listbox","aria-hidden":!0}),r.list=e("
").append(r.ul).on("mousedown"+a,function(e){r.filterInput&&r.filterInput[0]===e.target||e.preventDefault()}),i=t.attr(d),i&&(r.list.attr(d,i+"-list"),r.ul.attr(d,i+"_listbox"),r._optionID=i+"_option_selected"),r._header(),r._accessors(),r._initValue()},options:{valuePrimitive:!1,headerTemplate:""},setOptions:function(e){o.fn.setOptions.call(this,e),e&&e.enable!==t&&(e.enabled=e.enable)},focus:function(){this._focused.focus()},readonly:function(e){this._editable({readonly:e===t?!0:e,disable:!1})},enable:function(e){this._editable({readonly:!1,disable:!(e=e===t?!0:e)})},_filterSource:function(e){var t=this,i=t.options,r=t.dataSource,o=r.filter()||{};n(o,i.dataTextField),e&&(o=o.filters||[],o.push(e)),r.filter(o)},_header:function(){var t,n=this.options.headerTemplate;e.isFunction(n)&&(n=n({})),n&&(this.list.prepend(n),t=this.ul.prev(),this.header=t[0]?t:null)},_initValue:function(){var e=this,t=e.options.value;null!==t?e.element.val(t):(t=e._accessor(),e.options.value=t),e._old=t},_ignoreCase:function(){var e,t=this,n=t.dataSource.reader.model;n&&n.fields&&(e=n.fields[t.options.dataTextField],e&&e.type&&"string"!==e.type&&(t.options.ignoreCase=!1))},items:function(){return this.ul[0].children},current:function(e){var n=this,i=n._focused.add(n.filterInput),r=n._optionID;return e===t?n._current:(n._current&&(n._current.removeClass(h).removeAttr("aria-selected").removeAttr(d),i.removeAttr("aria-activedescendant")),e&&(e.addClass(h),n._scroll(e),r&&(e.attr("id",r),i.attr("aria-activedescendant",r))),n._current=e,t)},destroy:function(){var e=this,t=e.ns;o.fn.destroy.call(e),e._unbindDataSource(),e.ul.off(t),e.list.off(t),e._touchScroller&&e._touchScroller.destroy(),e.popup.destroy(),e._form&&e._form.off("reset",e._resetHandler)},dataItem:function(n){var i=this;return n===t?n=i.selectedIndex:"number"!=typeof n&&(n=e(i.items()).index(n)),i._data()[n]},_accessors:function(){var e=this,t=e.element,n=e.options,r=i.getter,o=t.attr(i.attr("text-field")),a=t.attr(i.attr("value-field"));o&&(n.dataTextField=o),a&&(n.dataValueField=a),e._text=r(n.dataTextField),e._value=r(n.dataValueField)},_aria:function(e){var n=this,i=n.options,r=n._focused.add(n.filterInput);i.suggest!==t&&r.attr("aria-autocomplete",i.suggest?"both":"list"),e=e?e+" "+n.ul[0].id:n.ul[0].id,r.attr("aria-owns",e),n.ul.attr("aria-live",i.filter&&"none"!==i.filter?"polite":"off")},_blur:function(){var e=this;e._change(),e.close()},_change:function(){var e,n=this,i=n.selectedIndex,r=n.options.value,o=n.value();n._isSelect&&!n._bound&&r&&(o=r),o!==n._old?e=!0:i!==t&&i!==n._oldIndex&&(e=!0),e&&(n._old=o,n._oldIndex=i,n.trigger(f),n.element.trigger(f))},_click:function(t){t.isDefaultPrevented()||this._accept(e(t.currentTarget))},_data:function(){return this.dataSource.view()},_enable:function(){var e=this,n=e.options,i=e.element.is("[disabled]");n.enable!==t&&(n.enabled=n.enable),!n.enabled||i?e.enable(!1):e.readonly(e.element.is("[readonly]"))},_focus:function(e){var n=this,i=!0;return n.popup.visible()&&e&&n.trigger(_,{item:e})?(n.close(),t):(n._select(e),n._triggerCascade(i),n._blur(),t)},_index:function(e){var t,n,i=this,r=i._data();for(t=0,n=r.length;n>t;t++)if(i._dataValue(r[t])==e)return t;return-1},_dataValue:function(e){var n=this._value(e);return n===t&&(n=this._text(e)),n},_height:function(e){if(e){var t,n=this,i=n.list,r=n.options.height,o=n.popup.visible(),a=n.filterInput,s=n.header,l=0;t=i.add(i.parent(".k-animation-container")).show(),r=n.ul[0].scrollHeight>r?r:"auto",t.height(r),"auto"!==r&&(a&&(l+=a.outerHeight()),s&&(l+=s.outerHeight())),l&&(r=i.height()-l),n.ul.height(r),o||t.hide()}},_adjustListWidth:function(){var e,t,n=this.list,i=n[0].style.width,r=this.wrapper;if(n.data(x)||!i)return e=window.getComputedStyle?window.getComputedStyle(r[0],null):0,t=e?parseFloat(e.width):r.outerWidth(),e&&(C.mozilla||C.msie)&&(t+=parseFloat(e.paddingLeft)+parseFloat(e.paddingRight)+parseFloat(e.borderLeftWidth)+parseFloat(e.borderRightWidth)),i="border-box"!==n.css("box-sizing")?t-(n.outerWidth()-n.width()):t,n.css({fontFamily:r.css("font-family"),width:i}).data(x,i),!0},_popup:function(){var e=this,t=e.list,n=e._focused,o=e.options,a=e.wrapper;e.popup=new r.Popup(t,k({},o.popup,{anchor:a,open:function(t){e._adjustListWidth(),e.trigger(m)?t.preventDefault():(n.attr("aria-expanded",!0),e.ul.attr("aria-hidden",!1))},close:function(t){e.trigger(v)?t.preventDefault():(n.attr("aria-expanded",!1),e.ul.attr("aria-hidden",!0))},animation:o.animation,isRtl:s.isRtl(a)})),e.popup.one(m,function(){e._height(e._data().length)}),e._touchScroller=i.touchScroller(e.popup.element)},_makeUnselectable:function(){S&&this.list.find("*").attr("unselectable","on")},_toggleHover:function(t){e(t.currentTarget).toggleClass(p,"mouseenter"===t.type)},_toggle:function(e,n){var i=this,r=s.touch&&s.MSPointers&&s.pointers;e=e!==t?e:!i.popup.visible(),n||r||i._focused[0]===u()||i._focused.focus(),i[e?m:v]()},_scroll:function(e){if(e){e[0]&&(e=e[0]);var t,n,i=this.ul[0],r=e.offsetTop,o=e.offsetHeight,a=i.scrollTop,s=i.clientHeight,l=r+o,u=this._touchScroller;u?(t=u.dimensions.y,t.enabled&&r>t.size&&(r=r-t.size+o+4,u.scrollTo(0,-r))):(n=this.header?this.header.outerHeight():0,n+=this.filterInput?this.filterInput.outerHeight():0,i.scrollTop=a>r?r-n:l>a+s?l-s-n:a)}},_template:function(){var e=this,t=e.options,n=t.template,r=t.dataSource;e._isSelect&&e.element[0].length&&(r||(t.dataTextField=t.dataTextField||"text",t.dataValueField=t.dataValueField||"value")),n?(n=i.template(n),e.template=function(e){return''+n(e)+" "}):e.template=i.template('${'+i.expr(t.dataTextField,"data")+"} ",{useWithBlock:!1})},_triggerCascade:function(e){var t=this,n=t.value();(!t._bound&&n||t._old!==n)&&t.trigger("cascade",{userTriggered:e})},_unbindDataSource:function(){var e=this;e.dataSource.unbind(f,e._refreshHandler).unbind(b,e._progressHandler).unbind(w,e._requestEndHandler).unbind("error",e._errorHandler)}});k(M,{inArray:function(e,t){var n,i,r=t.children;if(!e||e.parentNode!==t)return-1;for(n=0,i=r.length;i>n;n++)if(e===r[n])return n;return-1}}),i.ui.List=M,r.Select=M.extend({init:function(e,t){M.fn.init.call(this,e,t),this._initial=this.element.val()},setDataSource:function(e){this.options.dataSource=e,this._dataSource(),this._bound=!1,this.options.autoBind&&this.dataSource.fetch()},close:function(){this.popup.close()},select:function(e){var n=this;return e===t?n.selectedIndex:(n._select(e),n._triggerCascade(),n._old=n._accessor(),n._oldIndex=n.selectedIndex,t)},search:function(e){var t,n,i,r,o,a;e="string"==typeof e?e:this.text(),t=this,n=e.length,i=t.options,r=i.ignoreCase,o=i.filter,a=i.dataTextField,clearTimeout(t._typing),(!n||n>=i.minLength)&&(t._state="filter","none"===o?t._filter(e):(t._open=!0,t._filterSource({value:r?e.toLowerCase():e,field:a,operator:o,ignoreCase:r})))},_accessor:function(e,n){var i,r=this.element[0],o=this._isSelect,a=r.selectedIndex;return e===t?(o?a>-1&&(i=r.options[a],i&&(e=i.value)):e=r.value,e):(o?(a>-1&&r.options[a].removeAttribute(y),r.selectedIndex=n,i=r.options[n],i&&i.setAttribute(y,y)):r.value=e,t)},_hideBusy:function(){var e=this;clearTimeout(e._busy),e._arrow.removeClass(g),e._focused.attr("aria-busy",!1),e._busy=null},_showBusy:function(){var e=this;e._request=!0,e._busy||(e._busy=setTimeout(function(){e._focused.attr("aria-busy",!0),e._arrow.addClass(g)},100))},_requestEnd:function(){this._request=!1},_dataSource:function(){var t,n=this,r=n.element,o=n.options,a=o.dataSource||{};a=e.isArray(a)?{data:a}:a,n._isSelect&&(t=r[0].selectedIndex,t>-1&&(o.index=t),a.select=r,a.fields=[{field:o.dataTextField},{field:o.dataValueField}]),n.dataSource&&n._refreshHandler?n._unbindDataSource():(n._refreshHandler=T(n.refresh,n),n._progressHandler=T(n._showBusy,n),n._requestEndHandler=T(n._requestEnd,n),n._errorHandler=T(n._hideBusy,n)),n.dataSource=i.data.DataSource.create(a).bind(f,n._refreshHandler).bind(b,n._progressHandler).bind(w,n._requestEndHandler).bind("error",n._errorHandler)},_get:function(t){var n,i,r=this,o=r._data();if("function"==typeof t)for(n=0,i=o.length;i>n;n++)if(t(o[n])){t=n;break}if("number"==typeof t){if(0>t)return e();t=e(r.ul[0].children[t])}return t&&t.nodeType&&(t=e(t)),t},_move:function(e){var t,n,i=this,r=e.keyCode,o=i.ul[0],s=i.popup.visible()?"_select":"_accept",l=i._current,u=r===a.DOWN;if(r===a.UP||u){if(e.altKey)i.toggle(u);else{if(t=o.firstChild,!t&&!i._accessor()&&"filter"!==i._state)return i._fetch||(i.dataSource.one(f,function(){i._move(e),i._fetch=!1}),i._fetch=!0,i._filterSource()),e.preventDefault(),!0;u?(!l||-1===i.selectedIndex&&!i.value()&&l[0]===t?l=t:(l=l[0].nextSibling,l||t!==o.lastChild||(l=t)),i[s](l)):(l=l?l[0].previousSibling:o.lastChild,l||t!==o.lastChild||(l=t),i[s](l))}e.preventDefault(),n=!0}else r===a.ENTER||r===a.TAB?(i.popup.visible()&&e.preventDefault(),i.popup.visible()||l&&l.hasClass("k-state-selected")||(l=null),i._accept(l,r),n=!0):r===a.ESC&&(i.popup.visible()&&e.preventDefault(),i.close(),n=!0);return n},_selectItem:function(){var e,n,i=this,r=i._bound===t,o=i.options;e=i._isSelect&&!i._initial&&!o.value&&o.index&&!i._bound,e||(n=i._selectedValue||r&&o.value||i._accessor()),n?i.value(n):r&&i.select(o.index)},_fetchItems:function(e){var n=this,i=n.ul[0].firstChild;return n._request?!0:n._bound||n._fetch||i?t:n.options.cascadeFrom?!i:(n.dataSource.one(f,function(){n._old=t,n.value(e),n._fetch=!1}),n._fetch=!0,n.dataSource.fetch(),!0)},_options:function(e,n){var i,r,o,a,s=this,u=s.element,d=e.length,c="",f=0;for(n&&(f=1,c=n);d>f;f++)i="",o!==t&&(i+=l(o)),i+=" ",c+=i;u.html(c)},_reset:function(){var t=this,n=t.element,i=n.attr("form"),r=i?e("#"+i):n.closest("form");r[0]&&(t._resetHandler=function(){setTimeout(function(){t.value(t._initial)})},t._form=r.on("reset",t._resetHandler))},_cascade:function(){var t,i,r,o,a,s=this,l=s.options,u=l.cascadeFrom;if(u){if(s._selectedValue=l.value||s._accessor(),i=e("#"+u),t=i.data("kendo"+l.name),t||(t=i.data("kendo"+D[l.name])),!t)return;l.autoBind=!1,o=l.cascadeFromField||t.options.dataValueField,a=function(){s.dataSource.unbind(f,a);var e=s._selectedValue||s.value();s._userTriggered?s._clearSelection(t,!0):e?(s.value(e),s.dataSource.view()[0]&&-1!==s.selectedIndex||s._clearSelection(t,!0)):s.select(l.index),s.enable(),s._triggerCascade(s._userTriggered),s._userTriggered=!1},r=function(){var e,i,r,l=t.dataItem(),u=l?t._value(l):null;u||0===u?(e=s.dataSource.filter()||{},n(e,o),i=e.filters||[],i.push({field:o,operator:"eq",value:u}),r=function(){s.unbind("dataBound",r),a.apply(s,arguments)},s.first("dataBound",r),s.dataSource.filter(i)):(s.enable(!1),s._clearSelection(t),s._triggerCascade(s._userTriggered),s._userTriggered=!1)},t.first("cascade",function(e){s._userTriggered=e.userTriggered,r()}),t._bound?r():t.value()||s.enable(!1)}}})}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()});