all files / grid/renderer/ string-filter-ui.js

95.79% Statements 91/95
86.54% Branches 45/52
89.47% Functions 17/19
95.79% Lines 91/95
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147   75× 75× 75× 75× 74× 74×     23× 23× 23× 23×   23× 23×   21×   23× 23× 23×   18× 16×               23× 23× 23×                                   23× 23× 23× 23× 23× 23× 23×       23× 23× 23×     25×                   23× 24×     23× 20× 400×         51× 28×   23× 23× 23× 23× 23× 23×        
define(["require", "exports", "@syncfusion/ej2-dropdowns", "@syncfusion/ej2-data", "@syncfusion/ej2-base", "../base/util", "../base/constant", "../base/string-literals", "../common/checkbox-filter-base"], function (require, exports, ej2_dropdowns_1, ej2_data_1, ej2_base_1, util_1, events, literals, checkbox_filter_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var StringFilterUI = (function () {
        function StringFilterUI(parent, serviceLocator, filterSettings) {
            this.parent = parent;
            this.serLocator = serviceLocator;
            this.filterSettings = filterSettings;
            if (this.parent) {
                this.parent.on(events.filterMenuClose, this.destroy, this);
                this.parent.on(events.destroy, this.destroy, this);
            }
        }
        StringFilterUI.prototype.create = function (args) {
            this.instance = this.parent.createElement('input', { className: 'e-flmenu-input', id: 'strui-' + args.column.uid });
            args.target.appendChild(this.instance);
            this.dialogObj = args.dialogObj;
            this.processDataOperation(args);
        };
        StringFilterUI.prototype.processDataOperation = function (args) {
            var _this = this;
            if (args.column.isForeignColumn()) {
                this.parent.getDataModule().dataManager.executeQuery(this.parent.getDataModule().generateQuery(true))
                    .then(function (result) { _this.getAutoCompleteOptions(args, result); });
                return;
            }
            this.getAutoCompleteOptions(args);
        };
        StringFilterUI.prototype.getAutoCompleteOptions = function (args, result) {
            var isForeignColumn = args.column.isForeignColumn();
            var foreignColumnQuery;
            if (isForeignColumn) {
                var filteredData = checkbox_filter_base_1.CheckBoxFilterBase.getDistinct(result.result, args.column.field)
                    .records || [];
                var filterQuery = void 0;
                for (var i = 0; i < filteredData.length; i++) {
                    if (filterQuery) {
                        filterQuery = filterQuery.or(args.column.field, 'contains', filteredData[parseInt(i.toString(), 10)][args.column.field], this.parent
                            .filterSettings.enableCaseSensitivity, this.parent.filterSettings.ignoreAccent);
                    }
                    else {
                        filterQuery = new ej2_data_1.Predicate(args.column.field, 'contains', filteredData[parseInt(i.toString(), 10)][args.column.field], this.parent
                            .filterSettings.enableCaseSensitivity, this.parent.filterSettings.ignoreAccent);
                    }
                }
                foreignColumnQuery = new ej2_data_1.Query().where(filterQuery);
                foreignColumnQuery.params = this.parent.query.params;
            }
            var dataSource = isForeignColumn ? args.column.dataSource : this.parent.dataSource;
            var fields = { value: isForeignColumn ? args.column.foreignKeyValue : args.column.field };
            var autoComplete = new ej2_dropdowns_1.AutoComplete(ej2_base_1.extend({
                dataSource: dataSource instanceof ej2_data_1.DataManager ? dataSource : new ej2_data_1.DataManager(dataSource),
                fields: fields,
                locale: this.parent.locale,
                enableRtl: this.parent.enableRtl,
                query: isForeignColumn ? foreignColumnQuery : this.parent.getDataModule().generateQuery(true, true),
                sortOrder: 'Ascending',
                cssClass: this.parent.cssClass ? 'e-popup-flmenu' + ' ' + this.parent.cssClass : 'e-popup-flmenu',
                autofill: true,
                placeholder: args.localizeText.getConstant('EnterValue'),
                actionBegin: function () {
                    Eif (this.query.queries.length && this.query.queries[0].fn === 'onWhere' && this.query.queries[0].e
                        && this.query.queries[0].e.predicates) {
                        for (var i = 0; i < this.query.queries[0].e.predicates.length; i++) {
                            Eif (this.properties.fields.value === this.query.queries[0].e.predicates["" + i].field) {
                                this.query.queries[0].e.predicates.splice(i, 1);
                                i = i - 1;
                            }
                        }
                        Eif (!this.query.queries[0].e.predicates.length) {
                            this.query.queries.splice(0, 1);
                        }
                    }
                }
            }, args.column.filter.params));
            this.acFocus = this.focus(autoComplete, args);
            this.acComplete = this.actionComplete(autoComplete);
            this.acOpen = this.openPopup.bind(this);
            autoComplete.addEventListener(literals.focus, this.acFocus);
            autoComplete.addEventListener(literals['open'], this.acOpen);
            autoComplete.addEventListener(events.actionComplete, this.acComplete);
            if (dataSource && 'result' in dataSource) {
                var query = this.parent.getQuery ? this.parent.getQuery().clone() : new ej2_data_1.Query();
                var defObj = util_1.eventPromise({ requestType: 'stringfilterrequest' }, query);
                this.parent.trigger(events.dataStateChange, defObj.state);
                var def = defObj.deffered;
                def.promise.then(function (e) {
                    autoComplete.dataSource = new ej2_data_1.DataManager(e);
                });
            }
            this.actObj = autoComplete;
            this.actObj.appendTo(this.instance);
            if (isForeignColumn) {
                this.parent.filterModule.filterModule.afterRenderFilterUI();
            }
        };
        StringFilterUI.prototype.write = function (args) {
            if (args.filteredValue !== '' && !ej2_base_1.isNullOrUndefined(args.filteredValue)) {
                var struiObj = document.querySelector('#strui-' + args.column.uid).ej2_instances[0];
                struiObj.value = args.filteredValue;
            }
        };
        StringFilterUI.prototype.read = function (element, column, filterOptr, filterObj) {
            var actuiObj = document.querySelector('#strui-' + column.uid).ej2_instances[0];
            Iif (ej2_base_1.Browser.isDevice) {
                actuiObj.hidePopup();
                actuiObj.focusOut();
            }
            var filterValue = actuiObj.value;
            if (ej2_base_1.isNullOrUndefined(filterValue) || filterValue === '') {
                filterValue = null;
            }
            filterObj.filterByColumn(column.field, filterOptr, filterValue, 'and', this.parent.filterSettings.enableCaseSensitivity);
        };
        StringFilterUI.prototype.openPopup = function (args) {
            util_1.getZIndexCalcualtion(args, this.dialogObj);
        };
        StringFilterUI.prototype.focus = function (actObj, args) {
            return function () {
                actObj.filterType = args.getOptrInstance.getFlOperator();
            };
        };
        StringFilterUI.prototype.actionComplete = function (actObj) {
            return function (e) {
                e.result = e.result.filter(function (obj, index, arr) {
                    return arr.map(function (mapObj) {
                        return (ej2_base_1.getValue(actObj.fields.value, mapObj));
                    }).indexOf(ej2_base_1.getValue((actObj.fields.value), obj)) === index;
                });
            };
        };
        StringFilterUI.prototype.destroy = function () {
            if (!this.actObj || this.actObj.isDestroyed) {
                return;
            }
            this.actObj.removeEventListener(literals.focus, this.acFocus);
            this.actObj.removeEventListener(literals['open'], this.acOpen);
            this.actObj.removeEventListener(events.actionComplete, this.acComplete);
            this.actObj.destroy();
            this.parent.off(events.filterMenuClose, this.destroy);
            this.parent.off(events.destroy, this.destroy);
        };
        return StringFilterUI;
    }());
    exports.StringFilterUI = StringFilterUI;
});