/*
    *
    * Wijmo Library 5.20182.500
    * 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/
    *
    */
import*as wjcGrid from"wijmo/wijmo.grid";import*as wjcCore from"wijmo/wijmo";import*as wjcInput from"wijmo/wijmo.input";import*as wjcSelfRef from"wijmo/wijmo.grid.filter";var wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.grid=window.wijmo.grid||{},window.wijmo.grid.filter=wjcSelf;export class ValueFilter{constructor(t){this._maxValues=250,this._sortValues=!0,this._col=t,this._bnd=t.binding?new wjcCore.Binding(t.binding):null}get showValues(){return this._values}set showValues(t){this._values=t}get filterText(){return this._filterText}set filterText(t){this._filterText=wjcCore.asString(t)}get maxValues(){return this._maxValues}set maxValues(t){this._maxValues=wjcCore.asNumber(t,!1,!0)}get uniqueValues(){return this._uniqueValues}set uniqueValues(t){this._uniqueValues=wjcCore.asArray(t)}get sortValues(){return this._sortValues}set sortValues(t){this._sortValues=wjcCore.asBoolean(t)}get dataMap(){return this._map}set dataMap(t){this._map=wjcCore.asType(t,wjcGrid.DataMap,!0)}get column(){return this._col}get isActive(){return null!=this._values&&Object.keys(this._values).length>0}apply(t){let 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):wjcCore.Globalize.format(t,e.format),void 0!=this._values[t])}clear(){this.showValues=null,this.filterText=null}implementsInterface(t){return"IColumnFilter"==t}_getUniqueValues(t,e){let i=[];if(this.uniqueValues){let t=this.uniqueValues;for(let e=0;e<t.length;e++){let l=t[e];i.push({value:l,text:l.toString()})}return i}let l={},r=t.collectionView,s=r?r.sourceCollection:[];if(e&&r&&r.sourceCollection&&r.filter){let t=this.showValues;this.showValues=null;let e=[];for(let t=0;t<s.length;t++)r.filter(s[t])&&e.push(s[t]);s=e,this.showValues=t}for(let e=0;e<s.length;e++){let r=t._binding.getValue(s[e]),a=this.dataMap?this.dataMap.getDisplayValue(r):t.dataMap?t.dataMap.getDisplayValue(r):wjcCore.Globalize.format(r,t.format);l[a]||(l[a]=!0,i.push({value:r,text:a}))}return i}};export class ValueFilterEditor extends wjcCore.Control{constructor(t,e){super(t),this._filter=wjcCore.asType(e,ValueFilter,!1);let i=this.getTemplate();this.applyTemplate("wj-control",i,{_divFilter:"div-filter",_cbSelectAll:"cb-select-all",_spSelectAll:"sp-select-all",_divValues:"div-values"}),this._cbSelectAll.tabIndex=0;let l=wjcCore.culture.FlexGridFilter;if(wjcCore.setText(this._spSelectAll,l.selectAll),this._view=new wjcCore.CollectionView,e.sortValues){let t=e.column.dataMap||e.dataMap?"text":"value",i=e.column.dataType!=wjcCore.DataType.Boolean;this._view.sortDescriptions.push(new wjcCore.SortDescription(t,i))}this._view.filter=this._filterValues.bind(this),this._view.collectionChanged.addHandler(this._updateSelectAllCheck,this),this._filterText="",this._cmbFilter=new wjcInput.ComboBox(this._divFilter,{placeholder:l.search}),this._lbValues=new wjcInput.ListBox(this._divValues,{displayMemberPath:"text",checkedMemberPath:"show",itemsSource:this._view,itemFormatter:(t,e)=>e||l.null,gotFocus:(t,e)=>{t.selectedIndex<0&&(t.selectedIndex=0)}}),wjcCore.setAriaLabel(this._cmbFilter.inputElement,l.ariaLabels.search),this._cmbFilter.textChanged.addHandler(this._filterTextChanged,this),this._cbSelectAll.addEventListener("click",this._cbSelectAllClicked.bind(this)),this.updateEditor()}get filter(){return this._filter}updateEditor(){let t=this._filter.column,e=this._filter._getUniqueValues(t,!0);this._lbValues.isContentHtml=t.isContentHtml;let i=this._filter.showValues;if(i&&0!=Object.keys(i).length){for(let t in i)for(let i=0;i<e.length;i++)if(e[i].text==t){e[i].show=!0;break}}else for(let t=0;t<e.length;t++)e[t].show=!0;this._view.pageSize=20,this._view.sourceCollection=e,this._view.moveCurrentTo(null),setTimeout(()=>{this._view.pageSize=this._filter.maxValues,this._cmbFilter.text=this._filter.filterText,this._filterText=this._cmbFilter.text.toLowerCase()})}clearEditor(){this._cmbFilter.text="",this._filterText="",this._view.pageSize=0,this._view.refresh();let t=this._view.items;for(let e=0;e<t.length;e++)t[e].show=!1;this._view.pageSize=this._filter.maxValues}updateFilter(){let t=null,e=this._view.items;if(this._filterText||this._cbSelectAll.indeterminate){t={};for(let i=0;i<e.length;i++){let l=e[i];l.show&&(t[l.text]=!0)}}this._filter.showValues=t,this._filter.filterText=""}_filterTextChanged(){this._toText&&clearTimeout(this._toText),this._toText=setTimeout(()=>{let t=this._cmbFilter.text.toLowerCase(),e=t!=this._filterText;this._filterText=t,this._view.refresh(),e&&(this._cbSelectAll.checked=!0,this._cbSelectAllClicked())},300)}_filterValues(t){return!this._filterText||!(!t||!t.text)&&t.text.toLowerCase().indexOf(this._filterText)>-1}_cbSelectAllClicked(){let t=this._cbSelectAll.checked,e=this._view.items;for(let i=0;i<e.length;i++)e[i].show=t;this._view.refresh()}_updateSelectAllCheck(){let t=0,e=this._view.items;for(let 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}};ValueFilterEditor.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"></div></div>';export class ConditionFilter{constructor(t){this._c1=new FilterCondition(this),this._c2=new FilterCondition(this),this._and=!0,this._col=t,this._bnd=t.binding?new wjcCore.Binding(t.binding):null}get condition1(){return this._c1}get condition2(){return this._c2}get and(){return this._and}set and(t){this._and=wjcCore.asBoolean(t),this._bnd=this._col&&this._col.binding?new wjcCore.Binding(this._col.binding):null}get dataMap(){return this._map}set dataMap(t){this._map=wjcCore.asType(t,wjcGrid.DataMap,!0)}get column(){return this._col}get isActive(){return this._c1.isActive||this._c2.isActive}apply(t){let e=this._col,i=this._c1,l=this._c2;if(!this._bnd||!this.isActive)return!0;t=this._bnd.getValue(t),e.dataMap?t=e.dataMap.getDisplayValue(t):wjcCore.isDate(t)?(wjcCore.isString(i.value)||wjcCore.isString(l.value))&&(t=wjcCore.Globalize.format(t,e.format)):wjcCore.isNumber(t)&&(t=wjcCore.Globalize.parseFloat(wjcCore.Globalize.format(t,e.format)));let r=i.apply(t),s=l.apply(t);return i.isActive&&l.isActive?this._and?r&&s:r||s:i.isActive?r:!l.isActive||s}clear(){this._c1.clear(),this._c2.clear(),this.and=!0}implementsInterface(t){return"IColumnFilter"==t}};export class ConditionFilterEditor extends wjcCore.Control{constructor(t,e){super(t),this._filter=wjcCore.asType(e,ConditionFilter,!1);let i=this.getTemplate();this.applyTemplate("wj-control",i,{_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"});let l=wjcCore.culture.FlexGridFilter,r=l.ariaLabels;wjcCore.setAriaLabel(this._btnAnd,r.and),wjcCore.setAriaLabel(this._btnOr,r.or),wjcCore.setText(this._divHdr,l.header),wjcCore.setText(this._spAnd,l.and),wjcCore.setText(this._spOr,l.or),this._cmb1=this._createOperatorCombo(this._divCmb1,r.op1),this._cmb2=this._createOperatorCombo(this._divCmb2,r.op2),this._val1=this._createValueInput(this._divVal1,r.val1),this._val2=this._createValueInput(this._divVal2,r.val2);let s=this.hostElement;this.addEventListener(s,"change",this._btnAndOrChanged.bind(this)),this.addEventListener(s,"keydown",this._keydown.bind(this)),this.updateEditor()}get filter(){return this._filter}updateEditor(){let t=this._filter.condition1,e=this._filter.condition2;this._cmb1.selectedValue=t.operator,this._cmb2.selectedValue=e.operator,this._val1 instanceof wjcInput.ComboBox?(this._val1.text=wjcCore.changeType(t.value,wjcCore.DataType.String,null),this._val2.text=wjcCore.changeType(e.value,wjcCore.DataType.String,null)):(this._val1.value=t.value,this._val2.value=e.value);let i=this._filter.and;this._checkRadio(this._btnAnd,i),this._checkRadio(this._btnOr,!i)}clearEditor(){this._cmb1.selectedValue=this._cmb2.selectedValue=null,this._val1.text=this._val2.text=null,this._checkRadio(this._btnAnd,!0),this._checkRadio(this._btnOr,!1)}updateFilter(){let 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 wjcInput.ComboBox){let l=t.dataType==wjcCore.DataType.Date?wjcCore.DataType.String:t.dataType;e.value=wjcCore.changeType(this._val1.text,l,t.format),i.value=wjcCore.changeType(this._val2.text,l,t.format)}else e.value=this._val1.value,i.value=this._val2.value;this._filter.and=this._btnAnd.checked}_createOperatorCombo(t,e){let i=this._filter.column,l=wjcCore.culture.FlexGridFilter,r=l.stringOperators,s=this._filter.dataMap||i.dataMap,a=wjcCore.DataType;i.dataType==a.Date&&this._hasDatePart(i.format)?r=l.dateOperators:i.dataType!=a.Number||s?i.dataType!=a.Boolean||s||(r=l.booleanOperators):r=l.numberOperators;let n=new wjcInput.ComboBox(t,{itemsSource:r,displayMemberPath:"name",selectedValuePath:"op"});return wjcCore.setAriaLabel(n.inputElement,e),n}_createValueInput(t,e){let i=this._filter.column,l=this._filter.dataMap||i.dataMap,r=null,s=wjcCore.DataType;return i.dataType==s.Date&&this._hasDatePart(i.format)?(r=this._hasTimePart(i.format)?new wjcInput.InputDateTime(t):new wjcInput.InputDate(t)).format=i.format:i.dataType!=s.Number||l?(r=new wjcInput.ComboBox(t),l?(r.itemsSource=l.getDisplayValues(),r.isEditable=!0):i.dataType==s.Boolean&&(r.itemsSource=[!0,!1])):(r=new wjcInput.InputNumber(t)).format=i.format,r.isRequired=!1,wjcCore.setAriaLabel(r.inputElement,e),r}_hasDatePart(t){return!t||(t=wjcCore.culture.Globalize.calendar.patterns[t]||t,/[yMd]+/.test(t))}_hasTimePart(t){return!!t&&(t=wjcCore.culture.Globalize.calendar.patterns[t]||t,/[Hmst]+/.test(t))}_btnAndOrChanged(t){let e=t.target==this._btnAnd,i=t.target==this._btnOr;(e||i)&&(this._checkRadio(this._btnAnd,e),this._checkRadio(this._btnOr,i))}_checkRadio(t,e){t.checked=e,t.setAttribute("aria-checked",e.toString()),t.setAttribute("tabindex",e?"1":"-1")}_keydown(t){let e=t.target==this._btnAnd,i=t.target==this._btnOr;if(e||i)switch(t.keyCode){case wjcCore.Key.Left:case wjcCore.Key.Right:case wjcCore.Key.Up:case wjcCore.Key.Down:let i=e?this._btnOr:this._btnAnd;i.click(),i.focus(),t.preventDefault()}}};ConditionFilterEditor.controlTemplate='<div><div wj-part="div-hdr"></div><div wj-part="div-cmb1"></div><br/><div wj-part="div-val1"></div><br/><div role="radiogroup" style="text-align:center"><label><input wj-part="btn-and" type="radio" role="radio"> <span wj-part="sp-and"></span> </label>&nbsp;&nbsp;&nbsp;<label><input wj-part="btn-or" type="radio" role="radio"> <span wj-part="sp-or"></span> </label></div><div wj-part="div-cmb2"></div><br/><div wj-part="div-val2"></div><br/></div>';export class FilterCondition{constructor(t){this._op=null,this._filter=t}get operator(){return this._op}set operator(t){this._op=wjcCore.asEnum(t,Operator,!0)}get value(){return this._val}set value(t){if(this._val=t,this._strVal=wjcCore.isString(t)?t.toString().toLowerCase():null,this._mapVal=null,this._filter){let e=this._filter.dataMap||this._filter.column.dataMap;e&&(this._mapVal=e.getDisplayValue(t),wjcCore.isString(this._mapVal)&&(this._strVal=this._mapVal=this._mapVal.toLowerCase()))}}get isActive(){switch(this._op){case null:return!1;case Operator.EQ:case Operator.NE:return!0;default:return null!=this._val||null!=this._strVal}}clear(){this.operator=null,this.value=null}apply(t){let e=this._mapVal||this._strVal||this._val;switch(wjcCore.isString(t)&&(t=t.toLowerCase()),wjcCore.isString(e)&&null==t&&(t=""),this._op){case null:return!0;case Operator.EQ:return wjcCore.isDate(t)&&wjcCore.isDate(e)?wjcCore.DateTime.sameDate(t,e):t==e;case Operator.NE:return t!=e;case Operator.GT:return t>e;case Operator.GE:return t>=e;case Operator.LT:return t<e;case Operator.LE:return t<=e;case Operator.BW:return!(!this._strVal||!wjcCore.isString(t))&&0==t.indexOf(this._strVal);case Operator.EW:return!!(this._strVal&&wjcCore.isString(t)&&t.length>=this._strVal.length)&&t.substr(t.length-this._strVal.length)==e;case Operator.CT:return!(!this._strVal||!wjcCore.isString(t))&&t.indexOf(this._strVal)>-1;case Operator.NC:return!(!this._strVal||!wjcCore.isString(t))&&t.indexOf(this._strVal)<0}throw"Unknown operator"}};export var Operator;!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"}(Operator||(Operator={}));export class ColumnFilter{constructor(t,e){this._owner=t,this._col=e,this._valueFilter=new ValueFilter(e),this._conditionFilter=new ConditionFilter(e)}get filterType(){return null!=this._filterType?this._filterType:this._owner.defaultFilterType}set filterType(t){if((t=wjcCore.asEnum(t,FilterType,!0))!=this._filterType){let e=this.isActive;this.clear(),this._filterType=t,e?this._owner.apply():this._col.grid&&this._col.grid.invalidate()}}get dataMap(){return this.conditionFilter.dataMap||this.valueFilter.dataMap}set dataMap(t){this.conditionFilter.dataMap=t,this.valueFilter.dataMap=t}get valueFilter(){return this._valueFilter}get conditionFilter(){return this._conditionFilter}get column(){return this._col}get isActive(){return this._conditionFilter.isActive||this._valueFilter.isActive}apply(t){return this._conditionFilter.apply(t)&&this._valueFilter.apply(t)}clear(){this._valueFilter.clear(),this._conditionFilter.clear()}implementsInterface(t){return"IColumnFilter"==t}};wjcCore._addCultureInfo("FlexGridFilter",{ariaLabels:{edit:"Edit Filter for Column",dialog:"Filter Editor for Column",asc:"Sort Column in Ascending Order",dsc:"Sort Column in Descending Order",search:"Search Item List",op1:"First Condition Operator",val1:"First Condition Value",and:"Require both Conditions",or:"Require either Condition",op2:"Second Condition Operator",val2:"Second Condition Value"},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:Operator.EQ},{name:"Does not equal",op:Operator.NE},{name:"Begins with",op:Operator.BW},{name:"Ends with",op:Operator.EW},{name:"Contains",op:Operator.CT},{name:"Does not contain",op:Operator.NC}],numberOperators:[{name:"(not set)",op:null},{name:"Equals",op:Operator.EQ},{name:"Does not equal",op:Operator.NE},{name:"Is Greater than",op:Operator.GT},{name:"Is Greater than or equal to",op:Operator.GE},{name:"Is Less than",op:Operator.LT},{name:"Is Less than or equal to",op:Operator.LE}],dateOperators:[{name:"(not set)",op:null},{name:"Equals",op:Operator.EQ},{name:"Is Before",op:Operator.LT},{name:"Is After",op:Operator.GT}],booleanOperators:[{name:"(not set)",op:null},{name:"Equals",op:Operator.EQ},{name:"Does not equal",op:Operator.NE}]});export class ColumnFilterEditor extends wjcCore.Control{constructor(t,e,i=!0){super(t,null,!0),this.filterChanged=new wjcCore.Event,this.buttonClicked=new wjcCore.Event,this._filter=wjcCore.asType(e,ColumnFilter);let l=this.getTemplate();this.applyTemplate("wj-control wj-content wj-columnfiltereditor",l,{_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"});let r=wjcCore.culture.FlexGridFilter,s=r.ariaLabels,a=this.hostElement,n=this.filter.column,o=n.grid.collectionView;wjcCore.setAttribute(a,"role","dialog"),wjcCore.setAriaLabel(a,s.dialog+" "+n.header),wjcCore.setAriaLabel(this._btnAsc,s.asc),wjcCore.setAriaLabel(this._btnDsc,s.dsc),wjcCore.setText(this._btnAsc,r.ascending),wjcCore.setText(this._btnDsc,r.descending),wjcCore.setText(this._aVal,r.values),wjcCore.setText(this._aCnd,r.conditions),wjcCore.setText(this._btnApply,r.apply),wjcCore.setText(this._btnCancel,r.cancel),wjcCore.setText(this._btnClear,r.clear);let d=this.filter.conditionFilter.isActive||0==(e.filterType&FilterType.Value)?FilterType.Condition:FilterType.Value;this._showFilter(d),i&&o&&o.canSort||(this._divSort.style.display="none");let c=this._btnClicked.bind(this);this._btnApply.addEventListener("click",c),this._btnCancel.addEventListener("click",c),this._btnClear.addEventListener("click",c),this._btnAsc.addEventListener("click",c),this._btnDsc.addEventListener("click",c),this._aVal.addEventListener("click",c),this._aCnd.addEventListener("click",c),a.addEventListener("keydown",t=>{if(!t.defaultPrevented){let e=t.target.tagName.match(/^(a|button)$/i);switch(t.keyCode){case wjcCore.Key.Space:e&&(this._btnClicked(t),t.preventDefault());break;case wjcCore.Key.Enter:e?this._btnClicked(t):(this.updateFilter(),this.onFilterChanged(),this.onButtonClicked()),t.preventDefault();break;case wjcCore.Key.Escape:this.onButtonClicked(),t.preventDefault();break;case wjcCore.Key.Tab:wjcCore.moveFocus(this.hostElement,t.shiftKey?-1:1),t.preventDefault()}}})}get filter(){return this._filter}updateEditor(){this._edtVal&&this._edtVal.updateEditor(),this._edtCnd&&this._edtCnd.updateEditor()}updateFilter(){switch(this._getFilterType()){case FilterType.Value:this._edtVal.updateFilter(),this.filter.conditionFilter.clear();break;case FilterType.Condition:this._edtCnd.updateFilter(),this.filter.valueFilter.clear()}}onFilterChanged(t){this.filterChanged.raise(this,t)}onButtonClicked(t){this.buttonClicked.raise(this,t)}_handleResize(){this.isTouching||this._wasTouching||this.onButtonClicked()}_showFilter(t){switch(this._wasTouching=this.isTouching,t==FilterType.Value&&null==this._edtVal&&(this._edtVal=new ValueFilterEditor(this._divEdtVal,this.filter.valueFilter)),t==FilterType.Condition&&null==this._edtCnd&&(this._edtCnd=new ConditionFilterEditor(this._divEdtCnd,this.filter.conditionFilter)),0!=(t&this.filter.filterType)&&(t==FilterType.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 FilterType.None:case FilterType.Condition:case FilterType.Value:this._divType.style.display="none";break;default:this._divType.style.display=""}}_enableLink(t,e){wjcCore.toggleClass(t,"wj-state-disabled",!e),wjcCore.setAttribute(t,"href",e?"":null),wjcCore.setAttribute(t,"disabled",e?null:"disabled")}_getFilterType(){let t=FilterType;return"none"!=this._divEdtVal.style.display?t.Value:t.Condition}_btnClicked(t){if(t.preventDefault(),t.stopPropagation(),!wjcCore.hasClass(t.target,"wj-state-disabled")){if(t.target==this._aVal)return this._showFilter(FilterType.Value),void wjcCore.moveFocus(this._edtVal.hostElement,0);if(t.target==this._aCnd)return this._showFilter(FilterType.Condition),void wjcCore.moveFocus(this._edtCnd.hostElement,0);if(t.target==this._btnAsc||t.target==this._btnDsc){let e=this.filter.column,i=e.sortMemberPath?e.sortMemberPath:e.binding,l=e.grid.collectionView,r=new wjcCore.SortDescription(i,t.target==this._btnAsc);l.sortDescriptions.deferUpdate(()=>{l.sortDescriptions.clear(),l.sortDescriptions.push(r)})}t.target==this._btnApply?(this.updateFilter(),this.onFilterChanged()):t.target==this._btnClear?this.filter.isActive&&(this.filter.clear(),this.onFilterChanged()):this.updateEditor(),this.onButtonClicked()}}};ColumnFilterEditor.controlTemplate='<div><div wj-part="div-sort"><button wj-part="btn-asc" class="wj-btn" style="min-width:95px"></button>&nbsp;&nbsp;&nbsp;<button wj-part="btn-dsc" class="wj-btn" style="min-width:95px"></button></div><div wj-part="div-type" class="wj-filtertype"><a wj-part="a-cnd" href="" draggable="false"></a>&nbsp;|&nbsp;<a wj-part="a-val" href="" draggable="false"></a></div><div wj-part="div-edt-val" tabindex="-1"></div><div wj-part="div-edt-cnd" tabindex="-1"></div><div style="text-align:right;margin-top:10px"><button wj-part="btn-apply" class="wj-btn"></button>&nbsp;&nbsp;<button wj-part="btn-cancel" class="wj-btn"></button>&nbsp;&nbsp;<button wj-part="btn-clear" class="wj-btn"></button></div>';export var FilterType;!function(t){t[t.None=0]="None",t[t.Condition=1]="Condition",t[t.Value=2]="Value",t[t.Both=3]="Both"}(FilterType||(FilterType={}));export class FlexGridFilter{constructor(t,e){this._showIcons=!0,this._showSort=!0,this._defFilterType=FilterType.Both,this.filterApplied=new wjcCore.Event,this.filterChanging=new wjcCore.Event,this.filterChanged=new wjcCore.Event;let i="Missing dependency: FlexGridFilter requires ";wjcCore.assert(null!=wjcGrid,i+"wijmo.grid."),wjcCore.assert(null!=wjcInput,i+"wijmo.input."),this._filters=[],this._g=wjcCore.asType(t,wjcGrid.FlexGrid,!1),this._g.formatItem.addHandler(this._formatItem.bind(this)),this._g.itemsSourceChanged.addHandler(this.clear.bind(this));let l=this._g.hostElement;t.addEventListener(l,"mousedown",this._mousedown.bind(this),!0),t.addEventListener(l,"click",this._click.bind(this),!0),t.addEventListener(l,"keydown",this._keydown.bind(this),!0),this._g.invalidate(),e&&wjcCore.copy(this,e)}get grid(){return this._g}get filterColumns(){return this._filterColumns}set filterColumns(t){this._filterColumns=wjcCore.asArray(t),this.clear()}get showFilterIcons(){return this._showIcons}set showFilterIcons(t){t!=this.showFilterIcons&&(this._showIcons=wjcCore.asBoolean(t),this._g&&this._g.invalidate())}get showSortButtons(){return this._showSort}set showSortButtons(t){this._showSort=wjcCore.asBoolean(t)}getColumnFilter(t,e=!0){t=this._asColumn(t);for(let e=0;e<this._filters.length;e++)if(this._filters[e].column==t)return this._filters[e];if(e&&t.binding){let e=new ColumnFilter(this,t);return this._filters.push(e),e}return null}get defaultFilterType(){return this._defFilterType}set defaultFilterType(t){(t=wjcCore.asEnum(t,FilterType,!1))!=this.defaultFilterType&&(this._defFilterType=t,this._g.invalidate(),this.clear())}get filterDefinition(){let t={defaultFilterType:this.defaultFilterType,filters:[]};for(let e=0;e<this._filters.length;e++){let i=this._filters[e];if(i&&i.column&&i.column.binding)if(i.conditionFilter.isActive){let e=i.conditionFilter;t.filters.push({binding:i.column.binding,type:"condition",condition1:{operator:e.condition1.operator,value:e.condition1.value},and:e.and,condition2:{operator:e.condition2.operator,value:e.condition2.value}})}else if(i.valueFilter.isActive){let e=i.valueFilter;t.filters.push({binding:i.column.binding,type:"value",filterText:e.filterText,showValues:e.showValues})}}return JSON.stringify(t)}set filterDefinition(t){if(t=wjcCore.asString(t),this.clear(),t){let e=JSON.parse(t);this.defaultFilterType=e.defaultFilterType;for(let t=0;t<e.filters.length;t++){let i=e.filters[t],l=this._g.getColumn(i.binding),r=this.getColumnFilter(l,!0);if(r)switch(i.type){case"condition":let t=r.conditionFilter;t.condition1.value=l.dataType==wjcCore.DataType.Date?wjcCore.changeType(i.condition1.value,l.dataType,null):i.condition1.value,t.condition1.operator=i.condition1.operator,t.and=i.and,t.condition2.value=l.dataType==wjcCore.DataType.Date?wjcCore.changeType(i.condition2.value,l.dataType,null):i.condition2.value,t.condition2.operator=i.condition2.operator;break;case"value":let e=r.valueFilter;e.filterText=i.filterText,e.showValues=i.showValues}}}this.apply()}get activeEditor(){return wjcCore.Control.getControl(this._divEdt)}editColumnFilter(t,e){this.closeEditor(),t=this._asColumn(t);let i=document.createElement("div"),l=this.getColumnFilter(t),r=new ColumnFilterEditor(i,l,this.showSortButtons);wjcCore.addClass(i,"wj-dropdown-panel"),this._divEdt=i,this._edtCol=t;let s=new wjcGrid.CellRangeEventArgs(this._g.cells,new wjcGrid.CellRange(-1,t.index));if(!this.onFilterChanging(s))return void(this._divEdt=this._edtCol=null);s.cancel=!0,this._g.rightToLeft&&(i.dir="rtl"),r.filterChanged.addHandler(()=>{s.cancel=!1,setTimeout(()=>{s.cancel||this.apply()})}),r.buttonClicked.addHandler(()=>{this.closeEditor(),this._g.focus(),this.onFilterChanged(s)}),r.lostFocus.addHandler(()=>{setTimeout(()=>{let t=wjcCore.Control.getControl(this._divEdt);t&&!t.containsFocus()&&this.closeEditor()},10)});let a=this._g;a._edtHdl._commitRowEdits(),a.scrollIntoView(-1,t.index,!0);let n=this._g.columnHeaders,o=e&&e.panel==n?e.row:n.rows.length-1,d=e?e.col:t.index,c=n.getCellBoundingRect(o,d),h=n.getCellElement(o,d);h?wjcCore.showPopup(i,h,!1,!1,!1):wjcCore.showPopup(i,c),this._setAriaExpanded(h,!0),this._setAriaExpanded(a.cells.getCellElement(-1,d),!0);let u=r.hostElement.querySelectorAll("input");for(let t=0;t<u.length;t++){let e=u[t];if(e.offsetHeight>0&&e.tabIndex>-1&&!e.disabled){e.focus();break}}r.containsFocus()||r.focus()}_setAriaExpanded(t,e){if(t){var i=t.querySelector("."+FlexGridFilter._WJC_FILTER);wjcCore.setAttribute(i,"aria-expanded",e)}}closeEditor(){let t=this._g,e=wjcCore.Control.getControl(this._divEdt),i=this._edtCol;if(e&&wjcCore.hidePopup(e.hostElement,()=>{e.dispose()}),i){let e=t.columnHeaders,l=e.rows.length?e.getCellElement(e.rows.length-1,i.index):null;this._setAriaExpanded(l,!1),l=t.cells.getCellElement(-1,i.index),this._setAriaExpanded(l,!1)}this._divEdt=null,this._edtCol=null}apply(){let t=this._g.collectionView;if(t){let e=this._g.editableCollectionView;e&&(e.commitEdit(),e.commitNew()),t.filter=this._filter.bind(this)}let e=t?t.updateFilterDefinition:null;wjcCore.isFunction(e)&&e.call(t,this),this.onFilterApplied()}clear(){this._filters.length&&(this._filters=[],this.apply())}onFilterApplied(t){this.filterApplied.raise(this,t)}onFilterChanging(t){return this.filterChanging.raise(this,t),!t.cancel}onFilterChanged(t){this.filterChanged.raise(this,t)}_asColumn(t){return wjcCore.isString(t)?this._g.getColumn(t):wjcCore.isNumber(t)?this._g.columns[t]:wjcCore.asType(t,wjcGrid.Column,!1)}_filter(t){for(let e=0;e<this._filters.length;e++)if(!this._filters[e].apply(t))return!1;return!0}_formatItem(t,e){if(e.panel==t.columnHeaders){let t=this._g,i=t.getMergedRange(e.panel,e.row,e.col)||new wjcGrid.CellRange(e.row,e.col),l=t.columns[i.col],r=t._getBindingColumn(e.panel,e.row,l),s=e.cell;if(i.row2==e.panel.rows.length-1||l!=r){let i=this.getColumnFilter(r,this.defaultFilterType!=FilterType.None);this._filterColumns&&this._filterColumns.indexOf(r.binding)<0&&(i=null),i?(wjcCore.toggleClass(s,"wj-filter-on",i.isActive),wjcCore.toggleClass(s,"wj-filter-off",!i.isActive)):(wjcCore.removeClass(s,"wj-filter-on"),wjcCore.removeClass(s,"wj-filter-off")),i&&i.filterType!=FilterType.None&&(this._showIcons&&this._addFilterButton(r,i,s),0==e.row&&(s=t.cells.getCellElement(-1,e.col))&&this._addFilterButton(l,i,s))}}}_addFilterButton(t,e,i){let l=FlexGridFilter._WJC_FILTER,r=wjcCore.createElement('<button class="wj-btn wj-btn-glyph wj-right '+l+'" type="button" tabindex="-1"><span class="wj-glyph-filter"></span></button>');wjcCore.setAriaLabel(r,wjcCore.culture.FlexGridFilter.ariaLabels.edit+" "+t.header),wjcCore.setAttribute(r,"aria-haspopup","dialog"),wjcCore.setAttribute(r,"aria-expanded",!1),wjcCore.setAttribute(r,"aria-describedby",t.describedById),wjcCore.setAttribute(r,"aria-pressed",e.isActive),i.querySelector("."+l)||i.appendChild(r)}_mousedown(t){this._toggleEditor(t)&&(this._tmd=!0,t.stopPropagation(),t.preventDefault())}_click(t){(this._tmd||this._toggleEditor(t))&&(t.stopPropagation(),t.preventDefault()),this._tmd=!1}_toggleEditor(t){if(this._tmd=!1,!t.defaultPrevented&&0==t.button)if(wjcCore.closestClass(t.target,FlexGridFilter._WJC_FILTER)){let e=this._g,i=e.hitTest(t.target);if(i.panel||(i=e.hitTest(t)),i.panel==e.columnHeaders||i.panel==e.cells&&-1==i.row){let t=e.columns[i.col],l=e._getBindingColumn(i.panel,i.row,t);return this._divEdt&&this._edtCol==l?(this.closeEditor(),e.focus()):setTimeout(()=>{this.editColumnFilter(l,i)},this._divEdt?100:0),!0}}else this.closeEditor();return!1}_keydown(t){if(!t.defaultPrevented&&!t.ctrlKey&&t.altKey&&(t.keyCode==wjcCore.Key.Down||t.keyCode==wjcCore.Key.Up)){let 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())}}};FlexGridFilter._WJC_FILTER="wj-elem-filter";