/*
    *
    * Wijmo Library 5.20173.409
    * http://wijmo.com/
    *
    * Copyright(c) GrapeCity, Inc.  All rights reserved.
    *
    * Licensed under the GrapeCity Commercial License.
    * sales@wijmo.com
    * wijmo.com/products/wijmo-5/license/
    *
    */
System.register(["wijmo/wijmo.grid","wijmo/wijmo","wijmo/wijmo.input","wijmo/wijmo.grid.filter"],function(t,e){"use strict";var i,n,r,l,o,a,s,c,u,d,p,h,f,_,v=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();e&&e.id;return{setters:[function(t){i=t},function(t){n=t},function(t){r=t},function(t){l=t}],execute:function(){window.wijmo=window.wijmo||{},window.wijmo.grid=window.wijmo.grid||{},window.wijmo.grid.filter=l,o=function(){function t(t){this._maxValues=250,this._sortValues=!0,this._col=t,this._bnd=t.binding?new n.Binding(t.binding):null}return Object.defineProperty(t.prototype,"showValues",{get:function(){return this._values},set:function(t){this._values=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"filterText",{get:function(){return this._filterText},set:function(t){this._filterText=n.asString(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxValues",{get:function(){return this._maxValues},set:function(t){this._maxValues=n.asNumber(t,!1,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"uniqueValues",{get:function(){return this._uniqueValues},set:function(t){this._uniqueValues=n.asArray(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"sortValues",{get:function(){return this._sortValues},set:function(t){this._sortValues=n.asBoolean(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dataMap",{get:function(){return this._map},set:function(t){this._map=n.asType(t,i.DataMap,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"column",{get:function(){return this._col},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isActive",{get:function(){return null!=this._values&&Object.keys(this._values).length>0},enumerable:!0,configurable:!0}),t.prototype.apply=function(t){var e=this.column;return!(this._bnd&&this._values&&Object.keys(this._values).length)||(t=this._bnd.getValue(t),t=this.dataMap?this.dataMap.getDisplayValue(t):e.dataMap?e.dataMap.getDisplayValue(t):n.Globalize.format(t,e.format),void 0!=this._values[t])},t.prototype.clear=function(){this.showValues=null,this.filterText=null},t.prototype.implementsInterface=function(t){return"IColumnFilter"==t},t.prototype._getUniqueValues=function(t,e){var i=[];if(this.uniqueValues){for(var r=this.uniqueValues,l=0;l<r.length;l++){d=r[l];i.push({value:d,text:d.toString()})}return i}var o={},a=t.collectionView,s=a?a.sourceCollection:[];if(e&&a&&a.sourceCollection&&a.filter){var c=this.showValues;this.showValues=null;for(var u=[],l=0;l<s.length;l++)a.filter(s[l])&&u.push(s[l]);s=u,this.showValues=c}for(l=0;l<s.length;l++){var d=t._binding.getValue(s[l]),p=this.dataMap?this.dataMap.getDisplayValue(d):t.dataMap?t.dataMap.getDisplayValue(d):n.Globalize.format(d,t.format);o[p]||(o[p]=!0,i.push({value:d,text:p}))}return i},t}(),t("ValueFilter",o),a=function(t){function e(e,i){var l=t.call(this,e)||this;l._filter=n.asType(i,o,!1);var a=l.getTemplate();if(l.applyTemplate("wj-control",a,{_divFilter:"div-filter",_cbSelectAll:"cb-select-all",_spSelectAll:"sp-select-all",_divValues:"div-values"}),n.setText(l._spSelectAll,n.culture.FlexGridFilter.selectAll),l._view=new n.CollectionView,i.sortValues){var s=i.column.dataMap||i.dataMap?"text":"value",c=i.column.dataType!=n.DataType.Boolean;l._view.sortDescriptions.push(new n.SortDescription(s,c))}return l._view.filter=l._filterValues.bind(l),l._view.collectionChanged.addHandler(l._updateSelectAllCheck,l),l._filterText="",l._cmbFilter=new r.ComboBox(l._divFilter,{placeholder:n.culture.FlexGridFilter.search}),l._lbValues=new r.ListBox(l._divValues,{displayMemberPath:"text",checkedMemberPath:"show",itemsSource:l._view,itemFormatter:function(t,e){return e||n.culture.FlexGridFilter.null}}),l._cmbFilter.textChanged.addHandler(l._filterTextChanged,l),l._cbSelectAll.addEventListener("click",l._cbSelectAllClicked.bind(l)),l.updateEditor(),l}return v(e,t),Object.defineProperty(e.prototype,"filter",{get:function(){return this._filter},enumerable:!0,configurable:!0}),e.prototype.updateEditor=function(){var t=this;setTimeout(function(){t._updateEditor()})},e.prototype._updateEditor=function(){var t=this,e=this._filter.column,i=this._filter._getUniqueValues(e,!0);this._lbValues.isContentHtml=e.isContentHtml;var n=this._filter.showValues;if(n&&0!=Object.keys(n).length){for(var r in n)for(l=0;l<i.length;l++)if(i[l].text==r){i[l].show=!0;break}}else for(var l=0;l<i.length;l++)i[l].show=!0;this._view.pageSize=20,this._view.sourceCollection=i,this._view.moveCurrentTo(null),setTimeout(function(){t._view.pageSize=t._filter.maxValues,t._cmbFilter.text=t._filter.filterText,t._filterText=t._cmbFilter.text.toLowerCase()})},e.prototype.clearEditor=function(){this._cmbFilter.text="",this._filterText="",this._view.pageSize=0,this._view.refresh();for(var t=this._view.items,e=0;e<t.length;e++)t[e].show=!1;this._view.pageSize=this._filter.maxValues},e.prototype.updateFilter=function(){var t=null,e=this._view.items;if(this._filterText||this._cbSelectAll.indeterminate){t={};for(var i=0;i<e.length;i++){var n=e[i];n.show&&(t[n.text]=!0)}}this._filter.showValues=t,this._filter.filterText=this._filterText},e.prototype._filterTextChanged=function(){var t=this;this._toText&&clearTimeout(this._toText),this._toText=setTimeout(function(){var e=t._cmbFilter.text.toLowerCase();e!=t._filterText&&(t._filterText=e,t._view.refresh(),t._cbSelectAll.checked=!0,t._cbSelectAllClicked())},500)},e.prototype._filterValues=function(t){return!this._filterText||!(!t||!t.text)&&t.text.toLowerCase().indexOf(this._filterText)>-1},e.prototype._cbSelectAllClicked=function(){for(var t=this._cbSelectAll.checked,e=this._view.items,i=0;i<e.length;i++)e[i].show=t;this._view.refresh()},e.prototype._updateSelectAllCheck=function(){for(var t=0,e=this._view.items,i=0;i<e.length;i++)e[i].show&&t++;0==t?(this._cbSelectAll.checked=!1,this._cbSelectAll.indeterminate=!1):t==e.length?(this._cbSelectAll.checked=!0,this._cbSelectAll.indeterminate=!1):this._cbSelectAll.indeterminate=!0},e.controlTemplate='<div><div wj-part="div-filter"></div><div class="wj-listbox-item"><label><input wj-part="cb-select-all" type="checkbox"> <span wj-part="sp-select-all"></span></label></div><div wj-part="div-values" style="height:150px"></div></div>',e}(n.Control),t("ValueFilterEditor",a),s=function(){function t(t){this._c1=new u,this._c2=new u,this._and=!0,this._col=t,this._bnd=t.binding?new n.Binding(t.binding):null}return Object.defineProperty(t.prototype,"condition1",{get:function(){return this._c1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"condition2",{get:function(){return this._c2},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"and",{get:function(){return this._and},set:function(t){this._and=n.asBoolean(t),this._bnd=this._col&&this._col.binding?new n.Binding(this._col.binding):null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dataMap",{get:function(){return this._map},set:function(t){this._map=n.asType(t,i.DataMap,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"column",{get:function(){return this._col},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isActive",{get:function(){return this._c1.isActive||this._c2.isActive},enumerable:!0,configurable:!0}),t.prototype.apply=function(t){var e=this._col,i=this._c1,r=this._c2;if(!this._bnd||!this.isActive)return!0;t=this._bnd.getValue(t),e.dataMap?t=e.dataMap.getDisplayValue(t):n.isDate(t)?(n.isString(i.value)||n.isString(r.value))&&(t=n.Globalize.format(t,e.format)):n.isNumber(t)&&(t=n.Globalize.parseFloat(n.Globalize.format(t,e.format)));var l=i.apply(t),o=r.apply(t);return i.isActive&&r.isActive?this._and?l&&o:l||o:i.isActive?l:!r.isActive||o},t.prototype.clear=function(){this._c1.clear(),this._c2.clear(),this.and=!0},t.prototype.implementsInterface=function(t){return"IColumnFilter"==t},t}(),t("ConditionFilter",s),c=function(t){function e(e,i){var r=t.call(this,e)||this;r._filter=n.asType(i,s,!1);var l=r.getTemplate();r.applyTemplate("wj-control",l,{_divHdr:"div-hdr",_divCmb1:"div-cmb1",_divVal1:"div-val1",_btnAnd:"btn-and",_btnOr:"btn-or",_spAnd:"sp-and",_spOr:"sp-or",_divCmb2:"div-cmb2",_divVal2:"div-val2"});var o=n.culture.FlexGridFilter;n.setText(r._divHdr,o.header),n.setText(r._spAnd,o.and),n.setText(r._spOr,o.or),r._cmb1=r._createOperatorCombo(r._divCmb1),r._cmb2=r._createOperatorCombo(r._divCmb2),r._val1=r._createValueInput(r._divVal1),r._val2=r._createValueInput(r._divVal2);var a=r._btnAndOrChanged.bind(r);return r._btnAnd.addEventListener("change",a),r._btnOr.addEventListener("change",a),r.updateEditor(),r}return v(e,t),Object.defineProperty(e.prototype,"filter",{get:function(){return this._filter},enumerable:!0,configurable:!0}),e.prototype.updateEditor=function(){var t=this._filter.condition1,e=this._filter.condition2;this._cmb1.selectedValue=t.operator,this._cmb2.selectedValue=e.operator,this._val1 instanceof r.ComboBox?(this._val1.text=n.changeType(t.value,n.DataType.String,null),this._val2.text=n.changeType(e.value,n.DataType.String,null)):(this._val1.value=t.value,this._val2.value=e.value),this._btnAnd.checked=this._filter.and,this._btnOr.checked=!this._filter.and},e.prototype.clearEditor=function(){this._cmb1.selectedValue=this._cmb2.selectedValue=null,this._val1.text=this._val2.text=null,this._btnAnd.checked=!0,this._btnOr.checked=!1},e.prototype.updateFilter=function(){var t=this._filter.column,e=this._filter.condition1,i=this._filter.condition2;if(e.operator=this._cmb1.selectedValue,i.operator=this._cmb2.selectedValue,this._val1 instanceof r.ComboBox){var l=t.dataType==n.DataType.Date?n.DataType.String:t.dataType;e.value=n.changeType(this._val1.text,l,t.format),i.value=n.changeType(this._val2.text,l,t.format)}else e.value=this._val1.value,i.value=this._val2.value;this._filter.and=this._btnAnd.checked},e.prototype._createOperatorCombo=function(t){var e=this._filter.column,i=n.culture.FlexGridFilter.stringOperators;e.dataType!=n.DataType.Date||this._isTimeFormat(e.format)?e.dataType!=n.DataType.Number||e.dataMap?e.dataType!=n.DataType.Boolean||e.dataMap||(i=n.culture.FlexGridFilter.booleanOperators):i=n.culture.FlexGridFilter.numberOperators:i=n.culture.FlexGridFilter.dateOperators;var l=new r.ComboBox(t);return l.itemsSource=i,l.displayMemberPath="name",l.selectedValuePath="op",l},e.prototype._createValueInput=function(t){var e=this._filter.column,i=null;return e.dataType!=n.DataType.Date||this._isTimeFormat(e.format)?e.dataType!=n.DataType.Number||e.dataMap?(i=new r.ComboBox(t)).itemsSource=this._filter.dataMap?this._filter.dataMap.getDisplayValues():e.dataMap?e.dataMap.getDisplayValues():e.dataType==n.DataType.Boolean?[!0,!1]:null:(i=new r.InputNumber(t)).format=e.format:(i=new r.InputDate(t)).format=e.format,i.isRequired=!1,i},e.prototype._isTimeFormat=function(t){return!!t&&(t=n.culture.Globalize.calendar.patterns[t]||t,/[Hmst]+/.test(t))},e.prototype._btnAndOrChanged=function(t){this._btnAnd.checked=t.target==this._btnAnd,this._btnOr.checked=t.target==this._btnOr},e.controlTemplate='<div><div wj-part="div-hdr"></div><div wj-part="div-cmb1"></div><br/><div wj-part="div-val1"></div><br/><div style="text-align:center"><label><input wj-part="btn-and" type="radio"> <span wj-part="sp-and"></span> </label>&nbsp;&nbsp;&nbsp;<label><input wj-part="btn-or" type="radio"> <span wj-part="sp-or"></span> </label></div><div wj-part="div-cmb2"></div><br/><div wj-part="div-val2"></div><br/></div>',e}(n.Control),t("ConditionFilterEditor",c),u=function(){function t(){this._op=null}return Object.defineProperty(t.prototype,"operator",{get:function(){return this._op},set:function(t){this._op=n.asEnum(t,d,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"value",{get:function(){return this._val},set:function(t){this._val=t,this._strVal=n.isString(t)?t.toString().toLowerCase():null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isActive",{get:function(){switch(this._op){case null:return!1;case d.EQ:case d.NE:return!0;default:return null!=this._val||null!=this._strVal}},enumerable:!0,configurable:!0}),t.prototype.clear=function(){this.operator=null,this.value=null},t.prototype.apply=function(t){var e=this._strVal||this._val;switch(n.isString(t)&&(t=t.toLowerCase()),n.isString(e)&&null==t&&(t=""),this._op){case null:return!0;case d.EQ:return n.isDate(t)&&n.isDate(e)?n.DateTime.sameDate(t,e):t==e;case d.NE:return t!=e;case d.GT:return t>e;case d.GE:return t>=e;case d.LT:return t<e;case d.LE:return t<=e;case d.BW:return!(!this._strVal||!n.isString(t))&&0==t.indexOf(this._strVal);case d.EW:return!!(this._strVal&&n.isString(t)&&t.length>=this._strVal.length)&&t.substr(t.length-this._strVal.length)==e;case d.CT:return!(!this._strVal||!n.isString(t))&&t.indexOf(this._strVal)>-1;case d.NC:return!(!this._strVal||!n.isString(t))&&t.indexOf(this._strVal)<0}throw"Unknown operator"},t}(),t("FilterCondition",u),function(t){t[t.EQ=0]="EQ",t[t.NE=1]="NE",t[t.GT=2]="GT",t[t.GE=3]="GE",t[t.LT=4]="LT",t[t.LE=5]="LE",t[t.BW=6]="BW",t[t.EW=7]="EW",t[t.CT=8]="CT",t[t.NC=9]="NC"}(d||(d={})),t("Operator",d),p=function(){function t(t,e){this._owner=t,this._col=e,this._valueFilter=new o(e),this._conditionFilter=new s(e)}return Object.defineProperty(t.prototype,"filterType",{get:function(){return null!=this._filterType?this._filterType:this._owner.defaultFilterType},set:function(t){if(t!=this._filterType){var e=this.isActive;this.clear(),this._filterType=n.asEnum(t,f,!0),e?this._owner.apply():this._col.grid&&this._col.grid.invalidate()}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dataMap",{get:function(){return this.conditionFilter.dataMap||this.valueFilter.dataMap},set:function(t){this.conditionFilter.dataMap=t,this.valueFilter.dataMap=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"valueFilter",{get:function(){return this._valueFilter},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"conditionFilter",{get:function(){return this._conditionFilter},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"column",{get:function(){return this._col},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isActive",{get:function(){return this._conditionFilter.isActive||this._valueFilter.isActive},enumerable:!0,configurable:!0}),t.prototype.apply=function(t){return this._conditionFilter.apply(t)&&this._valueFilter.apply(t)},t.prototype.clear=function(){this._valueFilter.clear(),this._conditionFilter.clear()},t.prototype.implementsInterface=function(t){return"IColumnFilter"==t},t}(),t("ColumnFilter",p),n.culture.FlexGridFilter=window.wijmo.culture.FlexGridFilter||{ascending:"↑ Ascending",descending:"↓ Descending",apply:"Apply",cancel:"Cancel",clear:"Clear",conditions:"Filter by Condition",values:"Filter by Value",search:"Search",selectAll:"Select All",null:"(nothing)",header:"Show items where the value",and:"And",or:"Or",stringOperators:[{name:"(not set)",op:null},{name:"Equals",op:d.EQ},{name:"Does not equal",op:d.NE},{name:"Begins with",op:d.BW},{name:"Ends with",op:d.EW},{name:"Contains",op:d.CT},{name:"Does not contain",op:d.NC}],numberOperators:[{name:"(not set)",op:null},{name:"Equals",op:d.EQ},{name:"Does not equal",op:d.NE},{name:"Is Greater than",op:d.GT},{name:"Is Greater than or equal to",op:d.GE},{name:"Is Less than",op:d.LT},{name:"Is Less than or equal to",op:d.LE}],dateOperators:[{name:"(not set)",op:null},{name:"Equals",op:d.EQ},{name:"Is Before",op:d.LT},{name:"Is After",op:d.GT}],booleanOperators:[{name:"(not set)",op:null},{name:"Equals",op:d.EQ},{name:"Does not equal",op:d.NE}]},h=function(t){function e(e,i,r){void 0===r&&(r=!0);var l=t.call(this,e,null,!0)||this;l.filterChanged=new n.Event,l.buttonClicked=new n.Event,l._filter=n.asType(i,p);var o=l.getTemplate();l.applyTemplate("wj-control wj-columnfiltereditor wj-content",o,{_divSort:"div-sort",_btnAsc:"btn-asc",_btnDsc:"btn-dsc",_divType:"div-type",_aVal:"a-val",_aCnd:"a-cnd",_divEdtVal:"div-edt-val",_divEdtCnd:"div-edt-cnd",_btnApply:"btn-apply",_btnCancel:"btn-cancel",_btnClear:"btn-clear"});var a=n.culture.FlexGridFilter;n.setText(l._btnAsc,a.ascending),n.setText(l._btnDsc,a.descending),n.setText(l._aVal,a.values),n.setText(l._aCnd,a.conditions),n.setText(l._btnApply,a.apply),n.setText(l._btnCancel,a.cancel),n.setText(l._btnClear,a.clear);var s=l.filter.conditionFilter.isActive||0==(i.filterType&f.Value)?f.Condition:f.Value;l._showFilter(s);var c=l.filter.column.grid.collectionView;r&&c&&c.canSort||(l._divSort.style.display="none");var u=l._btnClicked.bind(l);return l._btnApply.addEventListener("click",u),l._btnCancel.addEventListener("click",u),l._btnClear.addEventListener("click",u),l._btnAsc.addEventListener("click",u),l._btnDsc.addEventListener("click",u),l._aVal.addEventListener("click",u),l._aCnd.addEventListener("click",u),l.hostElement.addEventListener("keydown",function(t){if(!t.defaultPrevented)switch(t.keyCode){case n.Key.Enter:switch(t.target.tagName){case"A":case"BUTTON":l._btnClicked(t);break;default:l.updateFilter(),l.onFilterChanged(),l.onButtonClicked()}t.preventDefault();break;case n.Key.Escape:l.onButtonClicked(),t.preventDefault()}}),l}return v(e,t),Object.defineProperty(e.prototype,"filter",{get:function(){return this._filter},enumerable:!0,configurable:!0}),e.prototype.updateEditor=function(){this._edtVal&&this._edtVal.updateEditor(),this._edtCnd&&this._edtCnd.updateEditor()},e.prototype.updateFilter=function(){switch(this._getFilterType()){case f.Value:this._edtVal.updateFilter(),this.filter.conditionFilter.clear();break;case f.Condition:this._edtCnd.updateFilter(),this.filter.valueFilter.clear()}},e.prototype.onFilterChanged=function(t){this.filterChanged.raise(this,t)},e.prototype.onButtonClicked=function(t){this.buttonClicked.raise(this,t)},e.prototype._handleResize=function(){this.isTouching||this._wasTouching||this.onButtonClicked()},e.prototype._showFilter=function(t){switch(this._wasTouching=this.isTouching,t==f.Value&&null==this._edtVal&&(this._edtVal=new a(this._divEdtVal,this.filter.valueFilter)),t==f.Condition&&null==this._edtCnd&&(this._edtCnd=new c(this._divEdtCnd,this.filter.conditionFilter)),0!=(t&this.filter.filterType)&&(t==f.Value?(this._divEdtVal.style.display="",this._divEdtCnd.style.display="none",this._enableLink(this._aVal,!1),this._enableLink(this._aCnd,!0),this._edtVal.focus()):(this._divEdtVal.style.display="none",this._divEdtCnd.style.display="",this._enableLink(this._aVal,!0),this._enableLink(this._aCnd,!1),this._edtCnd.focus())),this.filter.filterType){case f.None:case f.Condition:case f.Value:this._divType.style.display="none";break;default:this._divType.style.display=""}},e.prototype._enableLink=function(t,e){t.style.textDecoration=e?"":"none",t.style.fontWeight=e?"":"bold",n.setAttribute(t,"href",e?"":null)},e.prototype._getFilterType=function(){return"none"!=this._divEdtVal.style.display?f.Value:f.Condition},e.prototype._btnClicked=function(t){if(t.preventDefault(),t.stopPropagation(),!n.hasClass(t.target,"wj-state-disabled"))if(t.target!=this._aVal)if(t.target!=this._aCnd){if(t.target==this._btnAsc||t.target==this._btnDsc){var e=this.filter.column,i=e.sortMemberPath?e.sortMemberPath:e.binding,r=e.grid.collectionView,l=new n.SortDescription(i,t.target==this._btnAsc);r.sortDescriptions.deferUpdate(function(){r.sortDescriptions.clear(),r.sortDescriptions.push(l)})}t.target==this._btnApply?(this.updateFilter(),this.onFilterChanged()):t.target==this._btnClear?this.filter.isActive&&(this.filter.clear(),this.onFilterChanged()):this.updateEditor(),this.onButtonClicked()}else this._showFilter(f.Condition);else this._showFilter(f.Value)},e.controlTemplate='<div><div wj-part="div-sort"><a wj-part="btn-asc" href="" style="min-width:95px" draggable="false"></a>&nbsp;&nbsp;&nbsp;<a wj-part="btn-dsc" href="" style="min-width:95px" draggable="false"></a></div><div style="text-align:right;margin:10px 0px;font-size:80%"><div wj-part="div-type"><a wj-part="a-cnd" href="" draggable="false"></a>&nbsp;|&nbsp;<a wj-part="a-val" href="" draggable="false"></a></div></div><div wj-part="div-edt-val"></div><div wj-part="div-edt-cnd"></div><div style="text-align:right;margin-top:10px"><a wj-part="btn-apply" href="" draggable="false"></a>&nbsp;&nbsp;<a wj-part="btn-cancel" href="" draggable="false"></a>&nbsp;&nbsp;<a wj-part="btn-clear" href="" draggable="false"></a></div>',e}(n.Control),t("ColumnFilterEditor",h),function(t){t[t.None=0]="None",t[t.Condition=1]="Condition",t[t.Value=2]="Value",t[t.Both=3]="Both"}(f||(f={})),t("FilterType",f),_=function(){function t(t,e){this._showIcons=!0,this._showSort=!0,this._defFilterType=f.Both,this.filterApplied=new n.Event,this.filterChanging=new n.Event,this.filterChanged=new n.Event;var l="Missing dependency: FlexGridFilter requires ";n.assert(null!=i,l+"wijmo.grid."),n.assert(null!=r,l+"wijmo.input."),this._filters=[],this._g=n.asType(t,i.FlexGrid,!1),this._g.formatItem.addHandler(this._formatItem.bind(this)),this._g.itemsSourceChanged.addHandler(this.clear.bind(this));var o=this._g.hostElement;t.addEventListener(o,"mousedown",this._mousedown.bind(this),!0),t.addEventListener(o,"click",this._click.bind(this),!0),t.addEventListener(o,"keydown",this._keydown.bind(this),!0),this._g.invalidate(),e&&n.copy(this,e)}return Object.defineProperty(t.prototype,"grid",{get:function(){return this._g},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"filterColumns",{get:function(){return this._filterColumns},set:function(t){this._filterColumns=n.asArray(t),this.clear()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showFilterIcons",{get:function(){return this._showIcons},set:function(t){t!=this.showFilterIcons&&(this._showIcons=n.asBoolean(t),this._g&&this._g.invalidate())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showSortButtons",{get:function(){return this._showSort},set:function(t){this._showSort=n.asBoolean(t)},enumerable:!0,configurable:!0}),t.prototype.getColumnFilter=function(t,e){void 0===e&&(e=!0),t=this._asColumn(t);for(var i=0;i<this._filters.length;i++)if(this._filters[i].column==t)return this._filters[i];if(e&&t.binding){var n=new p(this,t);return this._filters.push(n),n}return null},Object.defineProperty(t.prototype,"defaultFilterType",{get:function(){return this._defFilterType},set:function(t){t!=this.defaultFilterType&&(this._defFilterType=n.asEnum(t,f,!1),this._g.invalidate(),this.clear())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"filterDefinition",{get:function(){for(var t={defaultFilterType:this.defaultFilterType,filters:[]},e=0;e<this._filters.length;e++){var i=this._filters[e];if(i&&i.column&&i.column.binding)if(i.conditionFilter.isActive){var n=i.conditionFilter;t.filters.push({binding:i.column.binding,type:"condition",condition1:{operator:n.condition1.operator,value:n.condition1.value},and:n.and,condition2:{operator:n.condition2.operator,value:n.condition2.value}})}else if(i.valueFilter.isActive){var r=i.valueFilter;t.filters.push({binding:i.column.binding,type:"value",filterText:r.filterText,showValues:r.showValues})}}return JSON.stringify(t)},set:function(t){if(t=n.asString(t),this.clear(),t){var e=JSON.parse(t);this.defaultFilterType=e.defaultFilterType;for(var i=0;i<e.filters.length;i++){var r=e.filters[i],l=this._g.getColumn(r.binding),o=this.getColumnFilter(l,!0);if(o)switch(r.type){case"condition":var a=o.conditionFilter;a.condition1.value=l.dataType==n.DataType.Date?n.changeType(r.condition1.value,l.dataType,null):r.condition1.value,a.condition1.operator=r.condition1.operator,a.and=r.and,a.condition2.value=l.dataType==n.DataType.Date?n.changeType(r.condition2.value,l.dataType,null):r.condition2.value,a.condition2.operator=r.condition2.operator;break;case"value":var s=o.valueFilter;s.filterText=r.filterText,s.showValues=r.showValues}}}this.apply()},enumerable:!0,configurable:!0}),t.prototype.editColumnFilter=function(t,e){var r=this;this.closeEditor(),t=this._asColumn(t);var l=new i.CellRangeEventArgs(this._g.cells,new i.CellRange(-1,t.index));if(this.onFilterChanging(l)){l.cancel=!0;var o=document.createElement("div"),a=this.getColumnFilter(t),s=new h(o,a,this.showSortButtons);n.addClass(o,"wj-dropdown-panel"),this._g.rightToLeft&&(o.dir="rtl"),s.filterChanged.addHandler(function(){l.cancel=!1,setTimeout(function(){l.cancel||r.apply()})}),s.buttonClicked.addHandler(function(){r.closeEditor(),r._g.focus(),r.onFilterChanged(l)}),s.lostFocus.addHandler(function(){setTimeout(function(){var t=n.Control.getControl(r._divEdt);t&&!t.containsFocus()&&r.closeEditor()},10)}),this._g.scrollIntoView(-1,t.index,!0);var c=this._g.columnHeaders,u=e?e.row:c.rows.length-1,d=e?e.col:t.index,p=c.getCellBoundingRect(u,d),f=c.getCellElement(u,d);f?n.showPopup(o,f,!1,!1,!1):n.showPopup(o,p),s.focus(),this._divEdt=o,this._edtCol=t}},t.prototype.closeEditor=function(){if(this._divEdt){var t=n.Control.getControl(this._divEdt);t&&n.hidePopup(t.hostElement,function(){t.dispose()}),this._divEdt=null,this._edtCol=null}},t.prototype.apply=function(){var t=this._g.collectionView;if(t){var e=this._g.editableCollectionView;e&&(e.commitEdit(),e.commitNew()),t.filter?t.refresh():t.filter=this._filter.bind(this)}var i=t?t.updateFilterDefinition:null;n.isFunction(i)&&i.call(t,this),this.onFilterApplied()},t.prototype.clear=function(){this._filters.length&&(this._filters=[],this.apply())},t.prototype.onFilterApplied=function(t){this.filterApplied.raise(this,t)},t.prototype.onFilterChanging=function(t){return this.filterChanging.raise(this,t),!t.cancel},t.prototype.onFilterChanged=function(t){this.filterChanged.raise(this,t)},t.prototype._asColumn=function(t){return n.isString(t)?this._g.getColumn(t):n.isNumber(t)?this._g.columns[t]:n.asType(t,i.Column,!1)},t.prototype._filter=function(t){for(var e=0;e<this._filters.length;e++)if(!this._filters[e].apply(t))return!1;return!0},t.prototype._formatItem=function(e,r){if(r.panel.cellType==i.CellType.ColumnHeader){var l=this._g,o=l.getMergedRange(r.panel,r.row,r.col)||new i.CellRange(r.row,r.col),a=l.columns[o.col],s=l._getBindingColumn(r.panel,r.row,a);if(o.row2==r.panel.rows.length-1||a!=s){var c=this.getColumnFilter(s,this.defaultFilterType!=f.None);if(this._filterColumns&&this._filterColumns.indexOf(s.binding)<0&&(c=null),c&&c.filterType!=f.None){if(this._showIcons){t._filterGlyph||(t._filterGlyph=n.createElement('<div role="button" class="'+t._WJC_FILTER+'"><span class="wj-glyph-filter"></span></div> '));var u=r.cell.querySelector("div")||r.cell;u.querySelector(".wj-glyph-filter")||u.insertBefore(t._filterGlyph.cloneNode(!0),u.firstChild)}n.toggleClass(r.cell,"wj-filter-on",c.isActive),n.toggleClass(r.cell,"wj-filter-off",!c.isActive)}else n.removeClass(r.cell,"wj-filter-on"),n.removeClass(r.cell,"wj-filter-off")}}},t.prototype._mousedown=function(t){this._toggleEditor(t)&&(this._tmd=!0,t.stopPropagation(),t.preventDefault())},t.prototype._click=function(t){(this._tmd||this._toggleEditor(t))&&(t.stopPropagation(),t.preventDefault()),this._tmd=!1},t.prototype._toggleEditor=function(e){var r=this;if(this._tmd=!1,!e.defaultPrevented&&0==e.button)if(n.closestClass(e.target,t._WJC_FILTER)){var l=this._g,o=new i.HitTestInfo(e.target,null);if(o.panel||(o=l.hitTest(e,!0)),o.panel==l.columnHeaders){var a=l.columns[o.col],s=l._getBindingColumn(o.panel,o.row,a);return this._divEdt&&this._edtCol==s?(this.closeEditor(),l.focus()):setTimeout(function(){r.editColumnFilter(s,o)},this._divEdt?100:0),!0}}else this.closeEditor();return!1},t.prototype._keydown=function(t){if(!t.defaultPrevented&&!t.ctrlKey&&t.altKey&&(t.keyCode==n.Key.Down||t.keyCode==n.Key.Up)){var e=this.grid.selection,i=e.col>-1?this.grid.columns[e.col]:null;i&&!i.dataMap&&this.getColumnFilter(i,!0)&&(this.editColumnFilter(i),t.preventDefault(),t.stopPropagation())}},t._WJC_FILTER="wj-elem-filter",t}(),t("FlexGridFilter",_)}}});