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;
});
|