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 | 1×
1×
1×
1×
1195×
1195×
1195×
1×
26×
26×
77×
77×
15×
62×
3×
3×
11×
1×
42×
42×
42×
2×
2×
40×
35×
35×
11×
9×
2×
24×
35×
5×
3×
2×
1×
1195×
1195×
1195×
1195×
1195×
1195×
1195×
1×
1126×
1126×
1126×
1126×
1126×
1126×
1×
1126×
1×
1341×
1304×
37×
35×
2×
1×
31×
1×
1104×
1104×
1×
11×
1×
1×
21910×
1×
1×
| 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.headerFocus = false;
this.parent = parent;
this.addEventListener();
}
Search.prototype.hasNonNumericCharacters = function (searchString) {
var decimalFound = false;
for (var _i = 0, searchString_1 = searchString; _i < searchString_1.length; _i++) {
var char = searchString_1[_i];
if ((char < '0' || char > '9') && char !== '.') {
return true;
}
if (char === '.') {
Iif (decimalFound) {
return true;
}
decimalFound = true;
}
}
return false;
};
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) {
this.headerFocus = false;
if (searchString !== '' && !this.hasNonNumericCharacters(searchString)) {
if (searchString === '.' || (searchString.indexOf('.') === -1)) {
gObj.searchSettings.key = searchString.toString();
}
else {
gObj.searchSettings.key = parseFloat(searchString).toString();
}
}
else {
gObj.searchSettings.key = searchString.toString();
}
gObj.dataBind();
}
else if (this.refreshSearch) {
gObj.refresh();
}
else {
this.headerFocus = false;
}
};
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);
this.parent.on(events.cancelBegin, this.cancelBeginEvent, this);
};
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);
this.parent.off(events.cancelBegin, this.cancelBeginEvent);
};
Search.prototype.destroy = function () {
this.removeEventListener();
};
Search.prototype.onPropertyChanged = function (e) {
if (e.module !== this.getModuleName()) {
return;
}
if (!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) {
Iif (this.refreshSearch && e.requestType === 'refresh' && this.headerFocus) {
this.headerFocus = false;
this.parent.focusModule.focus();
ej2_base_1.addClass([this.parent.focusModule.currentInfo.element], ['e-focused']);
}
this.refreshSearch = e.requestType !== 'searching';
};
Search.prototype.cancelBeginEvent = function (e) {
if (e.requestType === 'searching') {
this.parent.setProperties({ searchSettings: { key: '' } }, true);
}
};
Search.prototype.getModuleName = function () {
return 'search';
};
return Search;
}());
exports.Search = Search;
});
|