all files / grid/actions/ search.js

93.75% Statements 45/48
75% Branches 12/16
100% Functions 11/11
93.75% Lines 45/48
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   335× 335×   19× 19× 19×   17× 15× 15×       335×     335× 335× 335× 335× 335×   271×     271× 271× 271× 271×   271×   490× 475×   15× 15×                   13×       11514×   8456×        
define(["require", "exports", "@syncfusion/ej2-base", "../base/constant", "../base/util"], function (require, exports, ej2_base_1, events, util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Search = (function () {
        function Search(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        Search.prototype.search = function (searchString) {
            var gObj = this.parent;
            searchString = ej2_base_1.isNullOrUndefined(searchString) ? '' : searchString;
            if (util_1.isActionPrevent(gObj)) {
                gObj.notify(events.preventBatch, { instance: this, handler: this.search, arg1: searchString });
                return;
            }
            if (searchString !== gObj.searchSettings.key) {
                gObj.searchSettings.key = searchString.toString();
                gObj.dataBind();
            }
            else if (this.refreshSearch) {
                gObj.refresh();
            }
        };
        Search.prototype.addEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.inBoundModelChanged, this.onPropertyChanged, this);
            this.parent.on(events.searchComplete, this.onSearchComplete, this);
            this.parent.on(events.destroy, this.destroy, this);
            this.actionCompleteFunc = this.onActionComplete.bind(this);
            this.parent.addEventListener(events.actionComplete, this.actionCompleteFunc);
        };
        Search.prototype.removeEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.inBoundModelChanged, this.onPropertyChanged);
            this.parent.off(events.searchComplete, this.onSearchComplete);
            this.parent.off(events.destroy, this.destroy);
            this.parent.removeEventListener(events.actionComplete, this.actionCompleteFunc);
        };
        Search.prototype.destroy = function () {
            this.removeEventListener();
        };
        Search.prototype.onPropertyChanged = function (e) {
            if (e.module !== this.getModuleName()) {
                return;
            }
            Eif (!ej2_base_1.isNullOrUndefined(e.properties.key)) {
                this.parent.notify(events.modelChanged, {
                    requestType: 'searching', type: events.actionBegin, searchString: this.parent.searchSettings.key
                });
            }
            else {
                this.parent.notify(events.modelChanged, {
                    requestType: 'searching', type: events.actionBegin
                });
            }
        };
        Search.prototype.onSearchComplete = function (e) {
            this.parent.trigger(events.actionComplete, ej2_base_1.extend(e, {
                searchString: this.parent.searchSettings.key, requestType: 'searching', type: events.actionComplete
            }));
        };
        Search.prototype.onActionComplete = function (e) {
            this.refreshSearch = e.requestType !== 'searching';
        };
        Search.prototype.getModuleName = function () {
            return 'search';
        };
        return Search;
    }());
    exports.Search = Search;
});