GPQAPP

Форк
0
/
dataTables.searchBuilder.js 
3797 строк · 169.6 Кб
1
/*! SearchBuilder 1.3.1
2
 * ©SpryMedia Ltd - datatables.net/license/mit
3
 */
4
(function () {
5
    'use strict';
6

7
    var $$2;
8
    var dataTable$2;
9
    // eslint-disable-next-line no-extra-parens
10
    var moment = window.moment;
11
    // eslint-disable-next-line no-extra-parens
12
    var luxon = window.luxon;
13
    /**
14
     * Sets the value of jQuery for use in the file
15
     *
16
     * @param jq the instance of jQuery to be set
17
     */
18
    function setJQuery$2(jq) {
19
        $$2 = jq;
20
        dataTable$2 = jq.fn.dataTable;
21
    }
22
    /**
23
     * The Criteria class is used within SearchBuilder to represent a search criteria
24
     */
25
    var Criteria = /** @class */ (function () {
26
        function Criteria(table, opts, topGroup, index, depth) {
27
            var _this = this;
28
            if (index === void 0) { index = 0; }
29
            if (depth === void 0) { depth = 1; }
30
            // Check that the required version of DataTables is included
31
            if (!dataTable$2 || !dataTable$2.versionCheck || !dataTable$2.versionCheck('1.10.0')) {
32
                throw new Error('SearchPane requires DataTables 1.10 or newer');
33
            }
34
            this.classes = $$2.extend(true, {}, Criteria.classes);
35
            // Get options from user and any extra conditions/column types defined by plug-ins
36
            this.c = $$2.extend(true, {}, Criteria.defaults, $$2.fn.dataTable.ext.searchBuilder, opts);
37
            var i18n = this.c.i18n;
38
            this.s = {
39
                condition: undefined,
40
                conditions: {},
41
                data: undefined,
42
                dataIdx: -1,
43
                dataPoints: [],
44
                dateFormat: false,
45
                depth: depth,
46
                dt: table,
47
                filled: false,
48
                index: index,
49
                origData: undefined,
50
                topGroup: topGroup,
51
                type: '',
52
                value: []
53
            };
54
            this.dom = {
55
                buttons: $$2('<div/>')
56
                    .addClass(this.classes.buttonContainer),
57
                condition: $$2('<select disabled/>')
58
                    .addClass(this.classes.condition)
59
                    .addClass(this.classes.dropDown)
60
                    .addClass(this.classes.italic)
61
                    .attr('autocomplete', 'hacking'),
62
                conditionTitle: $$2('<option value="" disabled selected hidden/>')
63
                    .html(this.s.dt.i18n('searchBuilder.condition', i18n.condition)),
64
                container: $$2('<div/>')
65
                    .addClass(this.classes.container),
66
                data: $$2('<select/>')
67
                    .addClass(this.classes.data)
68
                    .addClass(this.classes.dropDown)
69
                    .addClass(this.classes.italic),
70
                dataTitle: $$2('<option value="" disabled selected hidden/>')
71
                    .html(this.s.dt.i18n('searchBuilder.data', i18n.data)),
72
                defaultValue: $$2('<select disabled/>')
73
                    .addClass(this.classes.value)
74
                    .addClass(this.classes.dropDown)
75
                    .addClass(this.classes.select)
76
                    .addClass(this.classes.italic),
77
                "delete": $$2('<button/>')
78
                    .html(this.s.dt.i18n('searchBuilder.delete', i18n["delete"]))
79
                    .addClass(this.classes["delete"])
80
                    .addClass(this.classes.button)
81
                    .attr('title', this.s.dt.i18n('searchBuilder.deleteTitle', i18n.deleteTitle))
82
                    .attr('type', 'button'),
83
                // eslint-disable-next-line no-useless-escape
84
                left: $$2('<button/>')
85
                    .html(this.s.dt.i18n('searchBuilder.left', i18n.left))
86
                    .addClass(this.classes.left)
87
                    .addClass(this.classes.button)
88
                    .attr('title', this.s.dt.i18n('searchBuilder.leftTitle', i18n.leftTitle))
89
                    .attr('type', 'button'),
90
                // eslint-disable-next-line no-useless-escape
91
                right: $$2('<button/>')
92
                    .html(this.s.dt.i18n('searchBuilder.right', i18n.right))
93
                    .addClass(this.classes.right)
94
                    .addClass(this.classes.button)
95
                    .attr('title', this.s.dt.i18n('searchBuilder.rightTitle', i18n.rightTitle))
96
                    .attr('type', 'button'),
97
                value: [
98
                    $$2('<select disabled/>')
99
                        .addClass(this.classes.value)
100
                        .addClass(this.classes.dropDown)
101
                        .addClass(this.classes.italic)
102
                        .addClass(this.classes.select)
103
                ],
104
                valueTitle: $$2('<option value="--valueTitle--" disabled selected hidden/>')
105
                    .html(this.s.dt.i18n('searchBuilder.value', i18n.value))
106
            };
107
            // If the greyscale option is selected then add the class to add the grey colour to SearchBuilder
108
            if (this.c.greyscale) {
109
                this.dom.data.addClass(this.classes.greyscale);
110
                this.dom.condition.addClass(this.classes.greyscale);
111
                this.dom.defaultValue.addClass(this.classes.greyscale);
112
                for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
113
                    var val = _a[_i];
114
                    val.addClass(this.classes.greyscale);
115
                }
116
            }
117
            // For responsive design, adjust the criterias properties on the following events
118
            this.s.dt.on('draw.dtsb', function () {
119
                _this._adjustCriteria();
120
            });
121
            this.s.dt.on('buttons-action.dtsb', function () {
122
                _this._adjustCriteria();
123
            });
124
            $$2(window).on('resize.dtsb', dataTable$2.util.throttle(function () {
125
                _this._adjustCriteria();
126
            }));
127
            this._buildCriteria();
128
            return this;
129
        }
130
        /**
131
         * Escape html characters within a string
132
         *
133
         * @param txt the string to be escaped
134
         * @returns the escaped string
135
         */
136
        Criteria._escapeHTML = function (txt) {
137
            return txt
138
                .toString()
139
                .replace(/&amp;/g, '&')
140
                .replace(/&lt;/g, '<')
141
                .replace(/&gt;/g, '>')
142
                .replace(/&quot;/g, '"');
143
        };
144
        /**
145
         * Adds the left button to the criteria
146
         */
147
        Criteria.prototype.updateArrows = function (hasSiblings, redraw) {
148
            if (hasSiblings === void 0) { hasSiblings = false; }
149
            if (redraw === void 0) { redraw = true; }
150
            // Empty the container and append all of the elements in the correct order
151
            this.dom.container.children().detach();
152
            this.dom.container
153
                .append(this.dom.data)
154
                .append(this.dom.condition)
155
                .append(this.dom.value[0]);
156
            this.setListeners();
157
            // Trigger the inserted events for the value elements as they are inserted
158
            if (this.dom.value[0] !== undefined) {
159
                this.dom.value[0].trigger('dtsb-inserted');
160
            }
161
            for (var i = 1; i < this.dom.value.length; i++) {
162
                this.dom.container.append(this.dom.value[i]);
163
                this.dom.value[i].trigger('dtsb-inserted');
164
            }
165
            // If this is a top level criteria then don't let it move left
166
            if (this.s.depth > 1) {
167
                this.dom.buttons.append(this.dom.left);
168
            }
169
            // If the depthLimit of the query has been hit then don't add the right button
170
            if ((this.c.depthLimit === false || this.s.depth < this.c.depthLimit) && hasSiblings) {
171
                this.dom.buttons.append(this.dom.right);
172
            }
173
            else {
174
                this.dom.right.remove();
175
            }
176
            this.dom.buttons.append(this.dom["delete"]);
177
            this.dom.container.append(this.dom.buttons);
178
            if (redraw) {
179
                // A different combination of arrows and selectors may lead to a need for responsive to be triggered
180
                this._adjustCriteria();
181
            }
182
        };
183
        /**
184
         * Destroys the criteria, removing listeners and container from the dom
185
         */
186
        Criteria.prototype.destroy = function () {
187
            // Turn off listeners
188
            this.dom.data.off('.dtsb');
189
            this.dom.condition.off('.dtsb');
190
            this.dom["delete"].off('.dtsb');
191
            for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
192
                var val = _a[_i];
193
                val.off('.dtsb');
194
            }
195
            // Remove container from the dom
196
            this.dom.container.remove();
197
        };
198
        /**
199
         * Passes in the data for the row and compares it against this single criteria
200
         *
201
         * @param rowData The data for the row to be compared
202
         * @returns boolean Whether the criteria has passed
203
         */
204
        Criteria.prototype.search = function (rowData, rowIdx) {
205
            var condition = this.s.conditions[this.s.condition];
206
            if (this.s.condition !== undefined && condition !== undefined) {
207
                var filter = rowData[this.s.dataIdx];
208
                // This check is in place for if a custom decimal character is in place
209
                if (this.s.type.includes('num') &&
210
                    (this.s.dt.settings()[0].oLanguage.sDecimal !== '' ||
211
                        this.s.dt.settings()[0].oLanguage.sThousands !== '')) {
212
                    var splitRD = [rowData[this.s.dataIdx]];
213
                    if (this.s.dt.settings()[0].oLanguage.sDecimal !== '') {
214
                        splitRD = rowData[this.s.dataIdx].split(this.s.dt.settings()[0].oLanguage.sDecimal);
215
                    }
216
                    if (this.s.dt.settings()[0].oLanguage.sThousands !== '') {
217
                        for (var i = 0; i < splitRD.length; i++) {
218
                            splitRD[i] = splitRD[i].replace(this.s.dt.settings()[0].oLanguage.sThousands, ',');
219
                        }
220
                    }
221
                    filter = splitRD.join('.');
222
                }
223
                // If orthogonal data is in place we need to get it's values for searching
224
                if (this.c.orthogonal.search !== 'filter') {
225
                    var settings = this.s.dt.settings()[0];
226
                    filter = settings.oApi._fnGetCellData(settings, rowIdx, this.s.dataIdx, typeof this.c.orthogonal === 'string' ?
227
                        this.c.orthogonal :
228
                        this.c.orthogonal.search);
229
                }
230
                if (this.s.type === 'array') {
231
                    // Make sure we are working with an array
232
                    if (!Array.isArray(filter)) {
233
                        filter = [filter];
234
                    }
235
                    filter.sort();
236
                    for (var _i = 0, filter_1 = filter; _i < filter_1.length; _i++) {
237
                        var filt = filter_1[_i];
238
                        if (filt && typeof filt === 'string') {
239
                            filt = filt.replace(/[\r\n\u2028]/g, ' ');
240
                        }
241
                    }
242
                }
243
                else if (filter !== null && typeof filter === 'string') {
244
                    filter = filter.replace(/[\r\n\u2028]/g, ' ');
245
                }
246
                if (this.s.type.includes('html') && typeof filter === 'string') {
247
                    filter = filter.replace(/(<([^>]+)>)/ig, '');
248
                }
249
                // Not ideal, but jqueries .val() returns an empty string even
250
                // when the value set is null, so we shall assume the two are equal
251
                if (filter === null) {
252
                    filter = '';
253
                }
254
                return condition.search(filter, this.s.value, this);
255
            }
256
        };
257
        /**
258
         * Gets the details required to rebuild the criteria
259
         */
260
        Criteria.prototype.getDetails = function (deFormatDates) {
261
            if (deFormatDates === void 0) { deFormatDates = false; }
262
            // This check is in place for if a custom decimal character is in place
263
            if (this.s.type !== null &&
264
                this.s.type.includes('num') &&
265
                (this.s.dt.settings()[0].oLanguage.sDecimal !== '' || this.s.dt.settings()[0].oLanguage.sThousands !== '')) {
266
                for (var i = 0; i < this.s.value.length; i++) {
267
                    var splitRD = [this.s.value[i].toString()];
268
                    if (this.s.dt.settings()[0].oLanguage.sDecimal !== '') {
269
                        splitRD = this.s.value[i].split(this.s.dt.settings()[0].oLanguage.sDecimal);
270
                    }
271
                    if (this.s.dt.settings()[0].oLanguage.sThousands !== '') {
272
                        for (var j = 0; j < splitRD.length; j++) {
273
                            splitRD[j] = splitRD[j].replace(this.s.dt.settings()[0].oLanguage.sThousands, ',');
274
                        }
275
                    }
276
                    this.s.value[i] = splitRD.join('.');
277
                }
278
            }
279
            else if (this.s.type !== null && deFormatDates) {
280
                if (this.s.type.includes('date') ||
281
                    this.s.type.includes('time')) {
282
                    for (var i = 0; i < this.s.value.length; i++) {
283
                        if (this.s.value[i].match(/^\d{4}-([0]\d|1[0-2])-([0-2]\d|3[01])$/g) === null) {
284
                            this.s.value[i] = '';
285
                        }
286
                    }
287
                }
288
                else if (this.s.type.includes('moment')) {
289
                    for (var i = 0; i < this.s.value.length; i++) {
290
                        this.s.value[i] = moment(this.s.value[i], this.s.dateFormat).toISOString();
291
                    }
292
                }
293
                else if (this.s.type.includes('luxon')) {
294
                    for (var i = 0; i < this.s.value.length; i++) {
295
                        this.s.value[i] = luxon.DateTime.fromFormat(this.s.value[i], this.s.dateFormat).toISO();
296
                    }
297
                }
298
            }
299
            if (this.s.type.includes('num') && this.s.dt.page.info().serverSide) {
300
                for (var i = 0; i < this.s.value.length; i++) {
301
                    this.s.value[i] = this.s.value[i].replace(/[^0-9.]/g, '');
302
                }
303
            }
304
            return {
305
                condition: this.s.condition,
306
                data: this.s.data,
307
                origData: this.s.origData,
308
                type: this.s.type,
309
                value: this.s.value.map(function (a) { return a.toString(); })
310
            };
311
        };
312
        /**
313
         * Getter for the node for the container of the criteria
314
         *
315
         * @returns JQuery<HTMLElement> the node for the container
316
         */
317
        Criteria.prototype.getNode = function () {
318
            return this.dom.container;
319
        };
320
        /**
321
         * Populates the criteria data, condition and value(s) as far as has been selected
322
         */
323
        Criteria.prototype.populate = function () {
324
            this._populateData();
325
            // If the column index has been found attempt to select a condition
326
            if (this.s.dataIdx !== -1) {
327
                this._populateCondition();
328
                // If the condittion has been found attempt to select the values
329
                if (this.s.condition !== undefined) {
330
                    this._populateValue();
331
                }
332
            }
333
        };
334
        /**
335
         * Rebuilds the criteria based upon the details passed in
336
         *
337
         * @param loadedCriteria the details required to rebuild the criteria
338
         */
339
        Criteria.prototype.rebuild = function (loadedCriteria) {
340
            // Check to see if the previously selected data exists, if so select it
341
            var foundData = false;
342
            var dataIdx;
343
            this._populateData();
344
            // If a data selection has previously been made attempt to find and select it
345
            if (loadedCriteria.data !== undefined) {
346
                var italic_1 = this.classes.italic;
347
                var data_1 = this.dom.data;
348
                this.dom.data.children('option').each(function () {
349
                    if (!foundData &&
350
                        ($$2(this).text() === loadedCriteria.data ||
351
                            loadedCriteria.origData && $$2(this).prop('origData') === loadedCriteria.origData)) {
352
                        $$2(this).prop('selected', true);
353
                        data_1.removeClass(italic_1);
354
                        foundData = true;
355
                        dataIdx = $$2(this).val();
356
                    }
357
                    else {
358
                        $$2(this).removeProp('selected');
359
                    }
360
                });
361
            }
362
            // If the data has been found and selected then the condition can be populated and searched
363
            if (foundData) {
364
                this.s.data = loadedCriteria.data;
365
                this.s.origData = loadedCriteria.origData;
366
                this.s.dataIdx = dataIdx;
367
                this.c.orthogonal = this._getOptions().orthogonal;
368
                this.dom.dataTitle.remove();
369
                this._populateCondition();
370
                this.dom.conditionTitle.remove();
371
                var condition = void 0;
372
                // Check to see if the previously selected condition exists, if so select it
373
                var options = this.dom.condition.children('option');
374
                // eslint-disable-next-line @typescript-eslint/prefer-for-of
375
                for (var i = 0; i < options.length; i++) {
376
                    var option = $$2(options[i]);
377
                    if (loadedCriteria.condition !== undefined &&
378
                        option.val() === loadedCriteria.condition &&
379
                        typeof loadedCriteria.condition === 'string') {
380
                        option.prop('selected', true);
381
                        condition = option.val();
382
                    }
383
                    else {
384
                        option.removeProp('selected');
385
                    }
386
                }
387
                this.s.condition = condition;
388
                // If the condition has been found and selected then the value can be populated and searched
389
                if (this.s.condition !== undefined) {
390
                    this.dom.conditionTitle.removeProp('selected');
391
                    this.dom.conditionTitle.remove();
392
                    this.dom.condition.removeClass(this.classes.italic);
393
                    // eslint-disable-next-line @typescript-eslint/prefer-for-of
394
                    for (var i = 0; i < options.length; i++) {
395
                        var option = $$2(options[i]);
396
                        if (option.val() !== this.s.condition) {
397
                            option.removeProp('selected');
398
                        }
399
                    }
400
                    this._populateValue(loadedCriteria);
401
                }
402
                else {
403
                    this.dom.conditionTitle.prependTo(this.dom.condition).prop('selected', true);
404
                }
405
            }
406
        };
407
        /**
408
         * Sets the listeners for the criteria
409
         */
410
        Criteria.prototype.setListeners = function () {
411
            var _this = this;
412
            this.dom.data
413
                .unbind('change')
414
                .on('change.dtsb', function () {
415
                _this.dom.dataTitle.removeProp('selected');
416
                // Need to go over every option to identify the correct selection
417
                var options = _this.dom.data.children('option.' + _this.classes.option);
418
                // eslint-disable-next-line @typescript-eslint/prefer-for-of
419
                for (var i = 0; i < options.length; i++) {
420
                    var option = $$2(options[i]);
421
                    if (option.val() === _this.dom.data.val()) {
422
                        _this.dom.data.removeClass(_this.classes.italic);
423
                        option.prop('selected', true);
424
                        _this.s.dataIdx = +option.val();
425
                        _this.s.data = option.text();
426
                        _this.s.origData = option.prop('origData');
427
                        _this.c.orthogonal = _this._getOptions().orthogonal;
428
                        // When the data is changed, the values in condition and
429
                        // value may also change so need to renew them
430
                        _this._clearCondition();
431
                        _this._clearValue();
432
                        _this._populateCondition();
433
                        // If this criteria was previously active in the search then
434
                        // remove it from the search and trigger a new search
435
                        if (_this.s.filled) {
436
                            _this.s.filled = false;
437
                            _this.s.dt.draw();
438
                            _this.setListeners();
439
                        }
440
                        _this.s.dt.state.save();
441
                    }
442
                    else {
443
                        option.removeProp('selected');
444
                    }
445
                }
446
            });
447
            this.dom.condition
448
                .unbind('change')
449
                .on('change.dtsb', function () {
450
                _this.dom.conditionTitle.removeProp('selected');
451
                // Need to go over every option to identify the correct selection
452
                var options = _this.dom.condition.children('option.' + _this.classes.option);
453
                // eslint-disable-next-line @typescript-eslint/prefer-for-of
454
                for (var i = 0; i < options.length; i++) {
455
                    var option = $$2(options[i]);
456
                    if (option.val() === _this.dom.condition.val()) {
457
                        _this.dom.condition.removeClass(_this.classes.italic);
458
                        option.prop('selected', true);
459
                        var condDisp = option.val();
460
                        // Find the condition that has been selected and store it internally
461
                        for (var _i = 0, _a = Object.keys(_this.s.conditions); _i < _a.length; _i++) {
462
                            var cond = _a[_i];
463
                            if (cond === condDisp) {
464
                                _this.s.condition = condDisp;
465
                                break;
466
                            }
467
                        }
468
                        // When the condition is changed, the value selector may switch between
469
                        // a select element and an input element
470
                        _this._clearValue();
471
                        _this._populateValue();
472
                        for (var _b = 0, _c = _this.dom.value; _b < _c.length; _b++) {
473
                            var val = _c[_b];
474
                            // If this criteria was previously active in the search then remove
475
                            // it from the search and trigger a new search
476
                            if (_this.s.filled && val !== undefined && _this.dom.container.has(val[0]).length !== 0) {
477
                                _this.s.filled = false;
478
                                _this.s.dt.draw();
479
                                _this.setListeners();
480
                            }
481
                        }
482
                        if (_this.dom.value.length === 0 ||
483
                            _this.dom.value.length === 1 && _this.dom.value[0] === undefined) {
484
                            _this.s.dt.draw();
485
                        }
486
                    }
487
                    else {
488
                        option.removeProp('selected');
489
                    }
490
                }
491
            });
492
        };
493
        /**
494
         * Adjusts the criteria to make SearchBuilder responsive
495
         */
496
        Criteria.prototype._adjustCriteria = function () {
497
            // If this criteria is not present then don't bother adjusting it
498
            if ($$2(document).has(this.dom.container).length === 0) {
499
                return;
500
            }
501
            var valRight;
502
            var valWidth;
503
            var outmostval = this.dom.value[this.dom.value.length - 1];
504
            // Calculate the width and right value of the outmost value element
505
            if (outmostval !== undefined && this.dom.container.has(outmostval[0]).length !== 0) {
506
                valWidth = outmostval.outerWidth(true);
507
                valRight = outmostval.offset().left + valWidth;
508
            }
509
            else {
510
                return;
511
            }
512
            var leftOffset = this.dom.left.offset();
513
            var rightOffset = this.dom.right.offset();
514
            var clearOffset = this.dom["delete"].offset();
515
            var hasLeft = this.dom.container.has(this.dom.left[0]).length !== 0;
516
            var hasRight = this.dom.container.has(this.dom.right[0]).length !== 0;
517
            var buttonsLeft = hasLeft ?
518
                leftOffset.left :
519
                hasRight ?
520
                    rightOffset.left :
521
                    clearOffset.left;
522
            // Perform the responsive calculations and redraw where necessary
523
            if ((buttonsLeft - valRight < 15 ||
524
                hasLeft && leftOffset.top !== clearOffset.top ||
525
                hasRight && rightOffset.top !== clearOffset.top) &&
526
                !this.dom.container.parent().hasClass(this.classes.vertical)) {
527
                this.dom.container.parent().addClass(this.classes.vertical);
528
                this.s.topGroup.trigger('dtsb-redrawContents');
529
            }
530
            else if (buttonsLeft -
531
                (this.dom.data.offset().left +
532
                    this.dom.data.outerWidth(true) +
533
                    this.dom.condition.outerWidth(true) +
534
                    valWidth) > 15
535
                && this.dom.container.parent().hasClass(this.classes.vertical)) {
536
                this.dom.container.parent().removeClass(this.classes.vertical);
537
                this.s.topGroup.trigger('dtsb-redrawContents');
538
            }
539
        };
540
        /**
541
         * Builds the elements of the dom together
542
         */
543
        Criteria.prototype._buildCriteria = function () {
544
            // Append Titles for select elements
545
            this.dom.data.append(this.dom.dataTitle);
546
            this.dom.condition.append(this.dom.conditionTitle);
547
            // Add elements to container
548
            this.dom.container
549
                .append(this.dom.data)
550
                .append(this.dom.condition);
551
            for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
552
                var val = _a[_i];
553
                val.append(this.dom.valueTitle);
554
                this.dom.container.append(val);
555
            }
556
            // Add buttons to container
557
            this.dom.container
558
                .append(this.dom["delete"])
559
                .append(this.dom.right);
560
            this.setListeners();
561
        };
562
        /**
563
         * Clears the condition select element
564
         */
565
        Criteria.prototype._clearCondition = function () {
566
            this.dom.condition.empty();
567
            this.dom.conditionTitle.prop('selected', true).attr('disabled', 'true');
568
            this.dom.condition.prepend(this.dom.conditionTitle).prop('selectedIndex', 0);
569
            this.s.conditions = {};
570
            this.s.condition = undefined;
571
        };
572
        /**
573
         * Clears the value elements
574
         */
575
        Criteria.prototype._clearValue = function () {
576
            if (this.s.condition !== undefined) {
577
                if (this.dom.value.length > 0 && this.dom.value[0] !== undefined) {
578
                    var _loop_1 = function (val) {
579
                        if (val !== undefined) {
580
                            // Timeout is annoying but because of IOS
581
                            setTimeout(function () {
582
                                val.remove();
583
                            }, 50);
584
                        }
585
                    };
586
                    // Remove all of the value elements
587
                    for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
588
                        var val = _a[_i];
589
                        _loop_1(val);
590
                    }
591
                }
592
                // Call the init function to get the value elements for this condition
593
                this.dom.value = [].concat(this.s.conditions[this.s.condition].init(this, Criteria.updateListener));
594
                if (this.dom.value.length > 0 && this.dom.value[0] !== undefined) {
595
                    this.dom.value[0].insertAfter(this.dom.condition).trigger('dtsb-inserted');
596
                    // Insert all of the value elements
597
                    for (var i = 1; i < this.dom.value.length; i++) {
598
                        this.dom.value[i].insertAfter(this.dom.value[i - 1]).trigger('dtsb-inserted');
599
                    }
600
                }
601
            }
602
            else {
603
                var _loop_2 = function (val) {
604
                    if (val !== undefined) {
605
                        // Timeout is annoying but because of IOS
606
                        setTimeout(function () {
607
                            val.remove();
608
                        }, 50);
609
                    }
610
                };
611
                // Remove all of the value elements
612
                for (var _b = 0, _c = this.dom.value; _b < _c.length; _b++) {
613
                    var val = _c[_b];
614
                    _loop_2(val);
615
                }
616
                // Append the default valueTitle to the default select element
617
                this.dom.valueTitle
618
                    .prop('selected', true);
619
                this.dom.defaultValue
620
                    .append(this.dom.valueTitle)
621
                    .insertAfter(this.dom.condition);
622
            }
623
            this.s.value = [];
624
            this.dom.value = [
625
                $$2('<select disabled/>')
626
                    .addClass(this.classes.value)
627
                    .addClass(this.classes.dropDown)
628
                    .addClass(this.classes.italic)
629
                    .addClass(this.classes.select)
630
                    .append(this.dom.valueTitle.clone())
631
            ];
632
        };
633
        /**
634
         * Gets the options for the column
635
         *
636
         * @returns {object} The options for the column
637
         */
638
        Criteria.prototype._getOptions = function () {
639
            var table = this.s.dt;
640
            return $$2.extend(true, {}, Criteria.defaults, table.settings()[0].aoColumns[this.s.dataIdx].searchBuilder);
641
        };
642
        /**
643
         * Populates the condition dropdown
644
         */
645
        Criteria.prototype._populateCondition = function () {
646
            var conditionOpts = [];
647
            var conditionsLength = Object.keys(this.s.conditions).length;
648
            // If there are no conditions stored then we need to get them from the appropriate type
649
            if (conditionsLength === 0) {
650
                var column = +this.dom.data.children('option:selected').val();
651
                this.s.type = this.s.dt.columns().type().toArray()[column];
652
                var colInits = this.s.dt.settings()[0].aoColumns;
653
                if (colInits !== undefined) {
654
                    var colInit = colInits[column];
655
                    if (colInit.searchBuilderType !== undefined && colInit.searchBuilderType !== null) {
656
                        this.s.type = colInit.searchBuilderType;
657
                    }
658
                    else if (this.s.type === undefined || this.s.type === null) {
659
                        this.s.type = colInit.sType;
660
                    }
661
                }
662
                // If the column type is still unknown, call a draw to try reading it again
663
                if (this.s.type === null || this.s.type === undefined) {
664
                    $$2.fn.dataTable.ext.oApi._fnColumnTypes(this.s.dt.settings()[0]);
665
                    this.s.type = this.s.dt.columns().type().toArray()[column];
666
                }
667
                // Enable the condition element
668
                this.dom.condition
669
                    .removeAttr('disabled')
670
                    .empty()
671
                    .append(this.dom.conditionTitle)
672
                    .addClass(this.classes.italic);
673
                this.dom.conditionTitle
674
                    .prop('selected', true);
675
                var decimal = this.s.dt.settings()[0].oLanguage.sDecimal;
676
                // This check is in place for if a custom decimal character is in place
677
                if (decimal !== '' && this.s.type.indexOf(decimal) === this.s.type.length - decimal.length) {
678
                    if (this.s.type.includes('num-fmt')) {
679
                        this.s.type = this.s.type.replace(decimal, '');
680
                    }
681
                    else if (this.s.type.includes('num')) {
682
                        this.s.type = this.s.type.replace(decimal, '');
683
                    }
684
                }
685
                // Select which conditions are going to be used based on the column type
686
                var conditionObj = this.c.conditions[this.s.type] !== undefined ?
687
                    this.c.conditions[this.s.type] :
688
                    this.s.type.includes('moment') ?
689
                        this.c.conditions.moment :
690
                        this.s.type.includes('luxon') ?
691
                            this.c.conditions.luxon :
692
                            this.c.conditions.string;
693
                // If it is a moment format then extract the date format
694
                if (this.s.type.includes('moment')) {
695
                    this.s.dateFormat = this.s.type.replace(/moment-/g, '');
696
                }
697
                else if (this.s.type.includes('luxon')) {
698
                    this.s.dateFormat = this.s.type.replace(/luxon-/g, '');
699
                }
700
                // Add all of the conditions to the select element
701
                for (var _i = 0, _a = Object.keys(conditionObj); _i < _a.length; _i++) {
702
                    var condition = _a[_i];
703
                    if (conditionObj[condition] !== null) {
704
                        // Serverside processing does not supply the options for the select elements
705
                        // Instead input elements need to be used for these instead
706
                        if (this.s.dt.page.info().serverSide && conditionObj[condition].init === Criteria.initSelect) {
707
                            conditionObj[condition].init = Criteria.initInput;
708
                            conditionObj[condition].inputValue = Criteria.inputValueInput;
709
                            conditionObj[condition].isInputValid = Criteria.isInputValidInput;
710
                        }
711
                        this.s.conditions[condition] = conditionObj[condition];
712
                        var condName = conditionObj[condition].conditionName;
713
                        if (typeof condName === 'function') {
714
                            condName = condName(this.s.dt, this.c.i18n);
715
                        }
716
                        conditionOpts.push($$2('<option>', {
717
                            text: condName,
718
                            value: condition
719
                        })
720
                            .addClass(this.classes.option)
721
                            .addClass(this.classes.notItalic));
722
                    }
723
                }
724
            }
725
            // Otherwise we can just load them in
726
            else if (conditionsLength > 0) {
727
                this.dom.condition.empty().removeAttr('disabled').addClass(this.classes.italic);
728
                for (var _b = 0, _c = Object.keys(this.s.conditions); _b < _c.length; _b++) {
729
                    var condition = _c[_b];
730
                    var condName = this.s.conditions[condition].conditionName;
731
                    if (typeof condName === 'function') {
732
                        condName = condName(this.s.dt, this.c.i18n);
733
                    }
734
                    var newOpt = $$2('<option>', {
735
                        text: condName,
736
                        value: condition
737
                    })
738
                        .addClass(this.classes.option)
739
                        .addClass(this.classes.notItalic);
740
                    if (this.s.condition !== undefined && this.s.condition === condName) {
741
                        newOpt.prop('selected', true);
742
                        this.dom.condition.removeClass(this.classes.italic);
743
                    }
744
                    conditionOpts.push(newOpt);
745
                }
746
            }
747
            else {
748
                this.dom.condition
749
                    .attr('disabled', 'true')
750
                    .addClass(this.classes.italic);
751
                return;
752
            }
753
            for (var _d = 0, conditionOpts_1 = conditionOpts; _d < conditionOpts_1.length; _d++) {
754
                var opt = conditionOpts_1[_d];
755
                this.dom.condition.append(opt);
756
            }
757
            this.dom.condition.prop('selectedIndex', 0);
758
        };
759
        /**
760
         * Populates the data select element
761
         */
762
        Criteria.prototype._populateData = function () {
763
            var _this = this;
764
            this.dom.data.empty().append(this.dom.dataTitle);
765
            // If there are no datas stored then we need to get them from the table
766
            if (this.s.dataPoints.length === 0) {
767
                this.s.dt.columns().every(function (index) {
768
                    // Need to check that the column can be filtered on before adding it
769
                    if (_this.c.columns === true ||
770
                        _this.s.dt.columns(_this.c.columns).indexes().toArray().includes(index)) {
771
                        var found = false;
772
                        for (var _i = 0, _a = _this.s.dataPoints; _i < _a.length; _i++) {
773
                            var val = _a[_i];
774
                            if (val.index === index) {
775
                                found = true;
776
                                break;
777
                            }
778
                        }
779
                        if (!found) {
780
                            var col = _this.s.dt.settings()[0].aoColumns[index];
781
                            var opt = {
782
                                index: index,
783
                                origData: col.data,
784
                                text: (col.searchBuilderTitle === undefined ?
785
                                    col.sTitle :
786
                                    col.searchBuilderTitle).replace(/(<([^>]+)>)/ig, '')
787
                            };
788
                            _this.s.dataPoints.push(opt);
789
                            _this.dom.data.append($$2('<option>', {
790
                                text: opt.text,
791
                                value: opt.index
792
                            })
793
                                .addClass(_this.classes.option)
794
                                .addClass(_this.classes.notItalic)
795
                                .prop('origData', col.data)
796
                                .prop('selected', _this.s.dataIdx === opt.index ? true : false));
797
                            if (_this.s.dataIdx === opt.index) {
798
                                _this.dom.dataTitle.removeProp('selected');
799
                            }
800
                        }
801
                    }
802
                });
803
            }
804
            // Otherwise we can just load them in
805
            else {
806
                var _loop_3 = function (data) {
807
                    this_1.s.dt.columns().every(function (index) {
808
                        var col = _this.s.dt.settings()[0].aoColumns[index];
809
                        if ((col.searchBuilderTitle === undefined ?
810
                            col.sTitle :
811
                            col.searchBuilderTitle).replace(/(<([^>]+)>)/ig, '') === data.text) {
812
                            data.index = index;
813
                            data.origData = col.data;
814
                        }
815
                    });
816
                    var newOpt = $$2('<option>', {
817
                        text: data.text.replace(/(<([^>]+)>)/ig, ''),
818
                        value: data.index
819
                    })
820
                        .addClass(this_1.classes.option)
821
                        .addClass(this_1.classes.notItalic)
822
                        .prop('origData', data.origData);
823
                    if (this_1.s.data === data.text) {
824
                        this_1.s.dataIdx = data.index;
825
                        this_1.dom.dataTitle.removeProp('selected');
826
                        newOpt.prop('selected', true);
827
                        this_1.dom.data.removeClass(this_1.classes.italic);
828
                    }
829
                    this_1.dom.data.append(newOpt);
830
                };
831
                var this_1 = this;
832
                for (var _i = 0, _a = this.s.dataPoints; _i < _a.length; _i++) {
833
                    var data = _a[_i];
834
                    _loop_3(data);
835
                }
836
            }
837
        };
838
        /**
839
         * Populates the Value select element
840
         *
841
         * @param loadedCriteria optional, used to reload criteria from predefined filters
842
         */
843
        Criteria.prototype._populateValue = function (loadedCriteria) {
844
            var _this = this;
845
            var prevFilled = this.s.filled;
846
            this.s.filled = false;
847
            // Remove any previous value elements
848
            // Timeout is annoying but because of IOS
849
            setTimeout(function () {
850
                _this.dom.defaultValue.remove();
851
            }, 50);
852
            var _loop_4 = function (val) {
853
                // Timeout is annoying but because of IOS
854
                setTimeout(function () {
855
                    if (val !== undefined) {
856
                        val.remove();
857
                    }
858
                }, 50);
859
            };
860
            for (var _i = 0, _a = this.dom.value; _i < _a.length; _i++) {
861
                var val = _a[_i];
862
                _loop_4(val);
863
            }
864
            var children = this.dom.container.children();
865
            if (children.length > 3) {
866
                for (var i = 2; i < children.length - 1; i++) {
867
                    $$2(children[i]).remove();
868
                }
869
            }
870
            // Find the column with the title matching the data for the criteria and take note of the index
871
            if (loadedCriteria !== undefined) {
872
                this.s.dt.columns().every(function (index) {
873
                    if (_this.s.dt.settings()[0].aoColumns[index].sTitle === loadedCriteria.data) {
874
                        _this.s.dataIdx = index;
875
                    }
876
                });
877
            }
878
            // Initialise the value elements based on the condition
879
            this.dom.value = [].concat(this.s.conditions[this.s.condition].init(this, Criteria.updateListener, loadedCriteria !== undefined ? loadedCriteria.value : undefined));
880
            if (loadedCriteria !== undefined && loadedCriteria.value !== undefined) {
881
                this.s.value = loadedCriteria.value;
882
            }
883
            // Insert value elements and trigger the inserted event
884
            if (this.dom.value[0] !== undefined) {
885
                this.dom.value[0]
886
                    .insertAfter(this.dom.condition)
887
                    .trigger('dtsb-inserted');
888
            }
889
            for (var i = 1; i < this.dom.value.length; i++) {
890
                this.dom.value[i]
891
                    .insertAfter(this.dom.value[i - 1])
892
                    .trigger('dtsb-inserted');
893
            }
894
            // Check if the criteria can be used in a search
895
            this.s.filled = this.s.conditions[this.s.condition].isInputValid(this.dom.value, this);
896
            this.setListeners();
897
            // If it can and this is different to before then trigger a draw
898
            if (prevFilled !== this.s.filled) {
899
                // If using SSP we want to restrict the amount of server calls that take place
900
                //  and this will already have taken place
901
                if (!this.s.dt.page.info().serverSide) {
902
                    this.s.dt.draw();
903
                }
904
                this.setListeners();
905
            }
906
        };
907
        /**
908
         * Provides throttling capabilities to SearchBuilder without having to use dt's _fnThrottle function
909
         * This is because that function is not quite suitable for our needs as it runs initially rather than waiting
910
         *
911
         * @param args arguments supplied to the throttle function
912
         * @returns Function that is to be run that implements the throttling
913
         */
914
        Criteria.prototype._throttle = function (fn, frequency) {
915
            if (frequency === void 0) { frequency = 200; }
916
            var last = null;
917
            var timer = null;
918
            var that = this;
919
            if (frequency === null) {
920
                frequency = 200;
921
            }
922
            return function () {
923
                var args = [];
924
                for (var _i = 0; _i < arguments.length; _i++) {
925
                    args[_i] = arguments[_i];
926
                }
927
                var now = +new Date();
928
                if (last !== null && now < last + frequency) {
929
                    clearTimeout(timer);
930
                }
931
                else {
932
                    last = now;
933
                }
934
                timer = setTimeout(function () {
935
                    last = null;
936
                    fn.apply(that, args);
937
                }, frequency);
938
            };
939
        };
940
        Criteria.version = '1.1.0';
941
        Criteria.classes = {
942
            button: 'dtsb-button',
943
            buttonContainer: 'dtsb-buttonContainer',
944
            condition: 'dtsb-condition',
945
            container: 'dtsb-criteria',
946
            data: 'dtsb-data',
947
            "delete": 'dtsb-delete',
948
            dropDown: 'dtsb-dropDown',
949
            greyscale: 'dtsb-greyscale',
950
            input: 'dtsb-input',
951
            italic: 'dtsb-italic',
952
            joiner: 'dtsp-joiner',
953
            left: 'dtsb-left',
954
            notItalic: 'dtsb-notItalic',
955
            option: 'dtsb-option',
956
            right: 'dtsb-right',
957
            select: 'dtsb-select',
958
            value: 'dtsb-value',
959
            vertical: 'dtsb-vertical'
960
        };
961
        /**
962
         * Default initialisation function for select conditions
963
         */
964
        Criteria.initSelect = function (that, fn, preDefined, array) {
965
            if (preDefined === void 0) { preDefined = null; }
966
            if (array === void 0) { array = false; }
967
            var column = that.dom.data.children('option:selected').val();
968
            var indexArray = that.s.dt.rows().indexes().toArray();
969
            var settings = that.s.dt.settings()[0];
970
            that.dom.valueTitle.prop('selected', true);
971
            // Declare select element to be used with all of the default classes and listeners.
972
            var el = $$2('<select/>')
973
                .addClass(Criteria.classes.value)
974
                .addClass(Criteria.classes.dropDown)
975
                .addClass(Criteria.classes.italic)
976
                .addClass(Criteria.classes.select)
977
                .append(that.dom.valueTitle)
978
                .on('change.dtsb', function () {
979
                $$2(this).removeClass(Criteria.classes.italic);
980
                fn(that, this);
981
            });
982
            if (that.c.greyscale) {
983
                el.addClass(Criteria.classes.greyscale);
984
            }
985
            var added = [];
986
            var options = [];
987
            // Add all of the options from the table to the select element.
988
            // Only add one option for each possible value
989
            for (var _i = 0, indexArray_1 = indexArray; _i < indexArray_1.length; _i++) {
990
                var index = indexArray_1[_i];
991
                var filter = settings.oApi._fnGetCellData(settings, index, column, typeof that.c.orthogonal === 'string' ?
992
                    that.c.orthogonal :
993
                    that.c.orthogonal.search);
994
                var value = {
995
                    filter: typeof filter === 'string' ?
996
                        filter.replace(/[\r\n\u2028]/g, ' ') : // Need to replace certain characters to match search values
997
                        filter,
998
                    index: index,
999
                    text: settings.oApi._fnGetCellData(settings, index, column, typeof that.c.orthogonal === 'string' ?
1000
                        that.c.orthogonal :
1001
                        that.c.orthogonal.display)
1002
                };
1003
                // If we are dealing with an array type, either make sure we are working with arrays, or sort them
1004
                if (that.s.type === 'array') {
1005
                    value.filter = !Array.isArray(value.filter) ? [value.filter] : value.filter;
1006
                    value.text = !Array.isArray(value.text) ? [value.text] : value.text;
1007
                }
1008
                // Function to add an option to the select element
1009
                var addOption = function (filt, text) {
1010
                    if (that.s.type.includes('html') && filt !== null && typeof filt === 'string') {
1011
                        filt.replace(/(<([^>]+)>)/ig, '');
1012
                    }
1013
                    // Add text and value, stripping out any html if that is the column type
1014
                    var opt = $$2('<option>', {
1015
                        type: Array.isArray(filt) ? 'Array' : 'String',
1016
                        value: filt
1017
                    })
1018
                        .data('sbv', filt)
1019
                        .addClass(that.classes.option)
1020
                        .addClass(that.classes.notItalic)
1021
                        // Have to add the text this way so that special html characters are not escaped - &amp; etc.
1022
                        .html(typeof text === 'string' ?
1023
                        text.replace(/(<([^>]+)>)/ig, '') :
1024
                        text);
1025
                    var val = opt.val();
1026
                    // Check that this value has not already been added
1027
                    if (added.indexOf(val) === -1) {
1028
                        added.push(val);
1029
                        options.push(opt);
1030
                        if (preDefined !== null && Array.isArray(preDefined[0])) {
1031
                            preDefined[0] = preDefined[0].sort().join(',');
1032
                        }
1033
                        // If this value was previously selected as indicated by preDefined, then select it again
1034
                        if (preDefined !== null && opt.val() === preDefined[0]) {
1035
                            opt.prop('selected', true);
1036
                            el.removeClass(Criteria.classes.italic);
1037
                            that.dom.valueTitle.removeProp('selected');
1038
                        }
1039
                    }
1040
                };
1041
                // If this is to add the individual values within the array we need to loop over the array
1042
                if (array) {
1043
                    for (var i = 0; i < value.filter.length; i++) {
1044
                        addOption(value.filter[i], value.text[i]);
1045
                    }
1046
                }
1047
                // Otherwise the value that is in the cell is to be added
1048
                else {
1049
                    addOption(value.filter, Array.isArray(value.text) ? value.text.join(', ') : value.text);
1050
                }
1051
            }
1052
            options.sort(function (a, b) {
1053
                if (that.s.type === 'array' ||
1054
                    that.s.type === 'string' ||
1055
                    that.s.type === 'html') {
1056
                    if (a.val() < b.val()) {
1057
                        return -1;
1058
                    }
1059
                    else if (a.val() > b.val()) {
1060
                        return 1;
1061
                    }
1062
                    else {
1063
                        return 0;
1064
                    }
1065
                }
1066
                else if (that.s.type === 'num' ||
1067
                    that.s.type === 'html-num') {
1068
                    if (+a.val().replace(/(<([^>]+)>)/ig, '') < +b.val().replace(/(<([^>]+)>)/ig, '')) {
1069
                        return -1;
1070
                    }
1071
                    else if (+a.val().replace(/(<([^>]+)>)/ig, '') > +b.val().replace(/(<([^>]+)>)/ig, '')) {
1072
                        return 1;
1073
                    }
1074
                    else {
1075
                        return 0;
1076
                    }
1077
                }
1078
                else if (that.s.type === 'num-fmt' || that.s.type === 'html-num-fmt') {
1079
                    if (+a.val().replace(/[^0-9.]/g, '') < +b.val().replace(/[^0-9.]/g, '')) {
1080
                        return -1;
1081
                    }
1082
                    else if (+a.val().replace(/[^0-9.]/g, '') > +b.val().replace(/[^0-9.]/g, '')) {
1083
                        return 1;
1084
                    }
1085
                    else {
1086
                        return 0;
1087
                    }
1088
                }
1089
            });
1090
            for (var _a = 0, options_1 = options; _a < options_1.length; _a++) {
1091
                var opt = options_1[_a];
1092
                el.append(opt);
1093
            }
1094
            return el;
1095
        };
1096
        /**
1097
         * Default initialisation function for select array conditions
1098
         *
1099
         * This exists because there needs to be different select functionality for contains/without and equals/not
1100
         */
1101
        Criteria.initSelectArray = function (that, fn, preDefined) {
1102
            if (preDefined === void 0) { preDefined = null; }
1103
            return Criteria.initSelect(that, fn, preDefined, true);
1104
        };
1105
        /**
1106
         * Default initialisation function for input conditions
1107
         */
1108
        Criteria.initInput = function (that, fn, preDefined) {
1109
            if (preDefined === void 0) { preDefined = null; }
1110
            // Declare the input element
1111
            var searchDelay = that.s.dt.settings()[0].searchDelay;
1112
            var el = $$2('<input/>')
1113
                .addClass(Criteria.classes.value)
1114
                .addClass(Criteria.classes.input)
1115
                .on('input.dtsb keypress.dtsb', that._throttle(function (e) {
1116
                var code = e.keyCode || e.which;
1117
                if (!that.c.enterSearch &&
1118
                    !(that.s.dt.settings()[0].oInit.search !== undefined &&
1119
                        that.s.dt.settings()[0].oInit.search["return"]) ||
1120
                    code === 13) {
1121
                    return fn(that, this);
1122
                }
1123
            }, searchDelay === null ? 100 : searchDelay));
1124
            if (that.c.greyscale) {
1125
                el.addClass(Criteria.classes.greyscale);
1126
            }
1127
            // If there is a preDefined value then add it
1128
            if (preDefined !== null) {
1129
                el.val(preDefined[0]);
1130
            }
1131
            // This is add responsive functionality to the logic button without redrawing everything else
1132
            that.s.dt.one('draw.dtsb', function () {
1133
                that.s.topGroup.trigger('dtsb-redrawLogic');
1134
            });
1135
            return el;
1136
        };
1137
        /**
1138
         * Default initialisation function for conditions requiring 2 inputs
1139
         */
1140
        Criteria.init2Input = function (that, fn, preDefined) {
1141
            if (preDefined === void 0) { preDefined = null; }
1142
            // Declare all of the necessary jQuery elements
1143
            var searchDelay = that.s.dt.settings()[0].searchDelay;
1144
            var els = [
1145
                $$2('<input/>')
1146
                    .addClass(Criteria.classes.value)
1147
                    .addClass(Criteria.classes.input)
1148
                    .on('input.dtsb keypress.dtsb', that._throttle(function (e) {
1149
                    var code = e.keyCode || e.which;
1150
                    if (!that.c.enterSearch &&
1151
                        !(that.s.dt.settings()[0].oInit.search !== undefined &&
1152
                            that.s.dt.settings()[0].oInit.search["return"]) ||
1153
                        code === 13) {
1154
                        return fn(that, this);
1155
                    }
1156
                }, searchDelay === null ? 100 : searchDelay)),
1157
                $$2('<span>')
1158
                    .addClass(that.classes.joiner)
1159
                    .html(that.s.dt.i18n('searchBuilder.valueJoiner', that.c.i18n.valueJoiner)),
1160
                $$2('<input/>')
1161
                    .addClass(Criteria.classes.value)
1162
                    .addClass(Criteria.classes.input)
1163
                    .on('input.dtsb keypress.dtsb', that._throttle(function (e) {
1164
                    var code = e.keyCode || e.which;
1165
                    if (!that.c.enterSearch &&
1166
                        !(that.s.dt.settings()[0].oInit.search !== undefined &&
1167
                            that.s.dt.settings()[0].oInit.search["return"]) ||
1168
                        code === 13) {
1169
                        return fn(that, this);
1170
                    }
1171
                }, searchDelay === null ? 100 : searchDelay))
1172
            ];
1173
            if (that.c.greyscale) {
1174
                els[0].addClass(Criteria.classes.greyscale);
1175
                els[2].addClass(Criteria.classes.greyscale);
1176
            }
1177
            // If there is a preDefined value then add it
1178
            if (preDefined !== null) {
1179
                els[0].val(preDefined[0]);
1180
                els[2].val(preDefined[1]);
1181
            }
1182
            // This is add responsive functionality to the logic button without redrawing everything else
1183
            that.s.dt.one('draw.dtsb', function () {
1184
                that.s.topGroup.trigger('dtsb-redrawLogic');
1185
            });
1186
            return els;
1187
        };
1188
        /**
1189
         * Default initialisation function for date conditions
1190
         */
1191
        Criteria.initDate = function (that, fn, preDefined) {
1192
            if (preDefined === void 0) { preDefined = null; }
1193
            var searchDelay = that.s.dt.settings()[0].searchDelay;
1194
            // Declare date element using DataTables dateTime plugin
1195
            var el = $$2('<input/>')
1196
                .addClass(Criteria.classes.value)
1197
                .addClass(Criteria.classes.input)
1198
                .dtDateTime({
1199
                attachTo: 'input',
1200
                format: that.s.dateFormat ? that.s.dateFormat : undefined
1201
            })
1202
                .on('change.dtsb', that._throttle(function () {
1203
                return fn(that, this);
1204
            }, searchDelay === null ? 100 : searchDelay))
1205
                .on('input.dtsb keypress.dtsb', that.c.enterSearch ||
1206
                that.s.dt.settings()[0].oInit.search !== undefined &&
1207
                    that.s.dt.settings()[0].oInit.search["return"] ?
1208
                function (e) {
1209
                    that._throttle(function () {
1210
                        var code = e.keyCode || e.which;
1211
                        if (code === 13) {
1212
                            return fn(that, this);
1213
                        }
1214
                    }, searchDelay === null ? 100 : searchDelay);
1215
                } :
1216
                that._throttle(function () {
1217
                    return fn(that, this);
1218
                }, searchDelay === null ? 100 : searchDelay));
1219
            if (that.c.greyscale) {
1220
                el.addClass(Criteria.classes.greyscale);
1221
            }
1222
            // If there is a preDefined value then add it
1223
            if (preDefined !== null) {
1224
                el.val(preDefined[0]);
1225
            }
1226
            // This is add responsive functionality to the logic button without redrawing everything else
1227
            that.s.dt.one('draw.dtsb', function () {
1228
                that.s.topGroup.trigger('dtsb-redrawLogic');
1229
            });
1230
            return el;
1231
        };
1232
        Criteria.initNoValue = function (that) {
1233
            // This is add responsive functionality to the logic button without redrawing everything else
1234
            that.s.dt.one('draw.dtsb', function () {
1235
                that.s.topGroup.trigger('dtsb-redrawLogic');
1236
            });
1237
        };
1238
        Criteria.init2Date = function (that, fn, preDefined) {
1239
            var _this = this;
1240
            if (preDefined === void 0) { preDefined = null; }
1241
            var searchDelay = that.s.dt.settings()[0].searchDelay;
1242
            // Declare all of the date elements that are required using DataTables dateTime plugin
1243
            var els = [
1244
                $$2('<input/>')
1245
                    .addClass(Criteria.classes.value)
1246
                    .addClass(Criteria.classes.input)
1247
                    .dtDateTime({
1248
                    attachTo: 'input',
1249
                    format: that.s.dateFormat ? that.s.dateFormat : undefined
1250
                })
1251
                    .on('change.dtsb', searchDelay !== null ?
1252
                    that.s.dt.settings()[0].oApi._fnThrottle(function () {
1253
                        return fn(that, this);
1254
                    }, searchDelay) :
1255
                    function () {
1256
                        fn(that, _this);
1257
                    })
1258
                    .on('input.dtsb keypress.dtsb', !that.c.enterSearch &&
1259
                    !(that.s.dt.settings()[0].oInit.search !== undefined &&
1260
                        that.s.dt.settings()[0].oInit.search["return"]) &&
1261
                    searchDelay !== null ?
1262
                    that.s.dt.settings()[0].oApi._fnThrottle(function () {
1263
                        return fn(that, this);
1264
                    }, searchDelay) :
1265
                    that.c.enterSearch ||
1266
                        that.s.dt.settings()[0].oInit.search !== undefined &&
1267
                            that.s.dt.settings()[0].oInit.search["return"] ?
1268
                        function (e) {
1269
                            var code = e.keyCode || e.which;
1270
                            if (code === 13) {
1271
                                fn(that, _this);
1272
                            }
1273
                        } :
1274
                        function () {
1275
                            fn(that, _this);
1276
                        }),
1277
                $$2('<span>')
1278
                    .addClass(that.classes.joiner)
1279
                    .html(that.s.dt.i18n('searchBuilder.valueJoiner', that.c.i18n.valueJoiner)),
1280
                $$2('<input/>')
1281
                    .addClass(Criteria.classes.value)
1282
                    .addClass(Criteria.classes.input)
1283
                    .dtDateTime({
1284
                    attachTo: 'input',
1285
                    format: that.s.dateFormat ? that.s.dateFormat : undefined
1286
                })
1287
                    .on('change.dtsb', searchDelay !== null ?
1288
                    that.s.dt.settings()[0].oApi._fnThrottle(function () {
1289
                        return fn(that, this);
1290
                    }, searchDelay) :
1291
                    function () {
1292
                        fn(that, _this);
1293
                    })
1294
                    .on('input.dtsb keypress.dtsb', !that.c.enterSearch &&
1295
                    !(that.s.dt.settings()[0].oInit.search !== undefined &&
1296
                        that.s.dt.settings()[0].oInit.search["return"]) &&
1297
                    searchDelay !== null ?
1298
                    that.s.dt.settings()[0].oApi._fnThrottle(function () {
1299
                        return fn(that, this);
1300
                    }, searchDelay) :
1301
                    that.c.enterSearch ||
1302
                        that.s.dt.settings()[0].oInit.search !== undefined &&
1303
                            that.s.dt.settings()[0].oInit.search["return"] ?
1304
                        function (e) {
1305
                            var code = e.keyCode || e.which;
1306
                            if (code === 13) {
1307
                                fn(that, _this);
1308
                            }
1309
                        } :
1310
                        function () {
1311
                            fn(that, _this);
1312
                        })
1313
            ];
1314
            if (that.c.greyscale) {
1315
                els[0].addClass(Criteria.classes.greyscale);
1316
                els[2].addClass(Criteria.classes.greyscale);
1317
            }
1318
            // If there are and preDefined values then add them
1319
            if (preDefined !== null && preDefined.length > 0) {
1320
                els[0].val(preDefined[0]);
1321
                els[2].val(preDefined[1]);
1322
            }
1323
            // This is add responsive functionality to the logic button without redrawing everything else
1324
            that.s.dt.one('draw.dtsb', function () {
1325
                that.s.topGroup.trigger('dtsb-redrawLogic');
1326
            });
1327
            return els;
1328
        };
1329
        /**
1330
         * Default function for select elements to validate condition
1331
         */
1332
        Criteria.isInputValidSelect = function (el) {
1333
            var allFilled = true;
1334
            // Check each element to make sure that the selections are valid
1335
            for (var _i = 0, el_1 = el; _i < el_1.length; _i++) {
1336
                var element = el_1[_i];
1337
                if (element.children('option:selected').length ===
1338
                    element.children('option').length -
1339
                        element.children('option.' + Criteria.classes.notItalic).length &&
1340
                    element.children('option:selected').length === 1 &&
1341
                    element.children('option:selected')[0] === element.children('option')[0]) {
1342
                    allFilled = false;
1343
                }
1344
            }
1345
            return allFilled;
1346
        };
1347
        /**
1348
         * Default function for input and date elements to validate condition
1349
         */
1350
        Criteria.isInputValidInput = function (el) {
1351
            var allFilled = true;
1352
            // Check each element to make sure that the inputs are valid
1353
            for (var _i = 0, el_2 = el; _i < el_2.length; _i++) {
1354
                var element = el_2[_i];
1355
                if (element.is('input') && element.val().length === 0) {
1356
                    allFilled = false;
1357
                }
1358
            }
1359
            return allFilled;
1360
        };
1361
        /**
1362
         * Default function for getting select conditions
1363
         */
1364
        Criteria.inputValueSelect = function (el) {
1365
            var values = [];
1366
            // Go through the select elements and push each selected option to the return array
1367
            for (var _i = 0, el_3 = el; _i < el_3.length; _i++) {
1368
                var element = el_3[_i];
1369
                if (element.is('select')) {
1370
                    values.push(Criteria._escapeHTML(element.children('option:selected').data('sbv')));
1371
                }
1372
            }
1373
            return values;
1374
        };
1375
        /**
1376
         * Default function for getting input conditions
1377
         */
1378
        Criteria.inputValueInput = function (el) {
1379
            var values = [];
1380
            // Go through the input elements and push each value to the return array
1381
            for (var _i = 0, el_4 = el; _i < el_4.length; _i++) {
1382
                var element = el_4[_i];
1383
                if (element.is('input')) {
1384
                    values.push(Criteria._escapeHTML(element.val()));
1385
                }
1386
            }
1387
            return values;
1388
        };
1389
        /**
1390
         * Function that is run on each element as a call back when a search should be triggered
1391
         */
1392
        Criteria.updateListener = function (that, el) {
1393
            // When the value is changed the criteria is now complete so can be included in searches
1394
            // Get the condition from the map based on the key that has been selected for the condition
1395
            var condition = that.s.conditions[that.s.condition];
1396
            that.s.filled = condition.isInputValid(that.dom.value, that);
1397
            that.s.value = condition.inputValue(that.dom.value, that);
1398
            if (!that.s.filled) {
1399
                that.s.dt.draw();
1400
                return;
1401
            }
1402
            if (!Array.isArray(that.s.value)) {
1403
                that.s.value = [that.s.value];
1404
            }
1405
            for (var i = 0; i < that.s.value.length; i++) {
1406
                // If the value is an array we need to sort it
1407
                if (Array.isArray(that.s.value[i])) {
1408
                    that.s.value[i].sort();
1409
                }
1410
                // Otherwise replace the decimal place character for i18n
1411
                else if (that.s.type.includes('num') &&
1412
                    (that.s.dt.settings()[0].oLanguage.sDecimal !== '' ||
1413
                        that.s.dt.settings()[0].oLanguage.sThousands !== '')) {
1414
                    var splitRD = [that.s.value[i].toString()];
1415
                    if (that.s.dt.settings()[0].oLanguage.sDecimal !== '') {
1416
                        splitRD = that.s.value[i].split(that.s.dt.settings()[0].oLanguage.sDecimal);
1417
                    }
1418
                    if (that.s.dt.settings()[0].oLanguage.sThousands !== '') {
1419
                        for (var j = 0; j < splitRD.length; j++) {
1420
                            splitRD[j] = splitRD[j].replace(that.s.dt.settings()[0].oLanguage.sThousands, ',');
1421
                        }
1422
                    }
1423
                    that.s.value[i] = splitRD.join('.');
1424
                }
1425
            }
1426
            // Take note of the cursor position so that we can refocus there later
1427
            var idx = null;
1428
            var cursorPos = null;
1429
            for (var i = 0; i < that.dom.value.length; i++) {
1430
                if (el === that.dom.value[i][0]) {
1431
                    idx = i;
1432
                    if (el.selectionStart !== undefined) {
1433
                        cursorPos = el.selectionStart;
1434
                    }
1435
                }
1436
            }
1437
            // Trigger a search
1438
            that.s.dt.draw();
1439
            // Refocus the element and set the correct cursor position
1440
            if (idx !== null) {
1441
                that.dom.value[idx].removeClass(that.classes.italic);
1442
                that.dom.value[idx].focus();
1443
                if (cursorPos !== null) {
1444
                    that.dom.value[idx][0].setSelectionRange(cursorPos, cursorPos);
1445
                }
1446
            }
1447
        };
1448
        // The order of the conditions will make eslint sad :(
1449
        // Has to be in this order so that they are displayed correctly in select elements
1450
        // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
1451
        // eslint-disable-next-line @typescript-eslint/member-ordering
1452
        Criteria.dateConditions = {
1453
            '=': {
1454
                conditionName: function (dt, i18n) {
1455
                    return dt.i18n('searchBuilder.conditions.date.equals', i18n.conditions.date.equals);
1456
                },
1457
                init: Criteria.initDate,
1458
                inputValue: Criteria.inputValueInput,
1459
                isInputValid: Criteria.isInputValidInput,
1460
                search: function (value, comparison) {
1461
                    value = value.replace(/(\/|-|,)/g, '-');
1462
                    return value === comparison[0];
1463
                }
1464
            },
1465
            // eslint-disable-next-line sort-keys
1466
            '!=': {
1467
                conditionName: function (dt, i18n) {
1468
                    return dt.i18n('searchBuilder.conditions.date.not', i18n.conditions.date.not);
1469
                },
1470
                init: Criteria.initDate,
1471
                inputValue: Criteria.inputValueInput,
1472
                isInputValid: Criteria.isInputValidInput,
1473
                search: function (value, comparison) {
1474
                    value = value.replace(/(\/|-|,)/g, '-');
1475
                    return value !== comparison[0];
1476
                }
1477
            },
1478
            '<': {
1479
                conditionName: function (dt, i18n) {
1480
                    return dt.i18n('searchBuilder.conditions.date.before', i18n.conditions.date.before);
1481
                },
1482
                init: Criteria.initDate,
1483
                inputValue: Criteria.inputValueInput,
1484
                isInputValid: Criteria.isInputValidInput,
1485
                search: function (value, comparison) {
1486
                    value = value.replace(/(\/|-|,)/g, '-');
1487
                    return value < comparison[0];
1488
                }
1489
            },
1490
            '>': {
1491
                conditionName: function (dt, i18n) {
1492
                    return dt.i18n('searchBuilder.conditions.date.after', i18n.conditions.date.after);
1493
                },
1494
                init: Criteria.initDate,
1495
                inputValue: Criteria.inputValueInput,
1496
                isInputValid: Criteria.isInputValidInput,
1497
                search: function (value, comparison) {
1498
                    value = value.replace(/(\/|-|,)/g, '-');
1499
                    return value > comparison[0];
1500
                }
1501
            },
1502
            'between': {
1503
                conditionName: function (dt, i18n) {
1504
                    return dt.i18n('searchBuilder.conditions.date.between', i18n.conditions.date.between);
1505
                },
1506
                init: Criteria.init2Date,
1507
                inputValue: Criteria.inputValueInput,
1508
                isInputValid: Criteria.isInputValidInput,
1509
                search: function (value, comparison) {
1510
                    value = value.replace(/(\/|-|,)/g, '-');
1511
                    if (comparison[0] < comparison[1]) {
1512
                        return comparison[0] <= value && value <= comparison[1];
1513
                    }
1514
                    else {
1515
                        return comparison[1] <= value && value <= comparison[0];
1516
                    }
1517
                }
1518
            },
1519
            // eslint-disable-next-line sort-keys
1520
            '!between': {
1521
                conditionName: function (dt, i18n) {
1522
                    return dt.i18n('searchBuilder.conditions.date.notBetween', i18n.conditions.date.notBetween);
1523
                },
1524
                init: Criteria.init2Date,
1525
                inputValue: Criteria.inputValueInput,
1526
                isInputValid: Criteria.isInputValidInput,
1527
                search: function (value, comparison) {
1528
                    value = value.replace(/(\/|-|,)/g, '-');
1529
                    if (comparison[0] < comparison[1]) {
1530
                        return !(comparison[0] <= value && value <= comparison[1]);
1531
                    }
1532
                    else {
1533
                        return !(comparison[1] <= value && value <= comparison[0]);
1534
                    }
1535
                }
1536
            },
1537
            'null': {
1538
                conditionName: function (dt, i18n) {
1539
                    return dt.i18n('searchBuilder.conditions.date.empty', i18n.conditions.date.empty);
1540
                },
1541
                init: Criteria.initNoValue,
1542
                inputValue: function () {
1543
                    return;
1544
                },
1545
                isInputValid: function () {
1546
                    return true;
1547
                },
1548
                search: function (value) {
1549
                    return value === null || value === undefined || value.length === 0;
1550
                }
1551
            },
1552
            // eslint-disable-next-line sort-keys
1553
            '!null': {
1554
                conditionName: function (dt, i18n) {
1555
                    return dt.i18n('searchBuilder.conditions.date.notEmpty', i18n.conditions.date.notEmpty);
1556
                },
1557
                init: Criteria.initNoValue,
1558
                inputValue: function () {
1559
                    return;
1560
                },
1561
                isInputValid: function () {
1562
                    return true;
1563
                },
1564
                search: function (value) {
1565
                    return !(value === null || value === undefined || value.length === 0);
1566
                }
1567
            }
1568
        };
1569
        // The order of the conditions will make eslint sad :(
1570
        // Has to be in this order so that they are displayed correctly in select elements
1571
        // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
1572
        // eslint-disable-next-line @typescript-eslint/member-ordering
1573
        Criteria.momentDateConditions = {
1574
            '=': {
1575
                conditionName: function (dt, i18n) {
1576
                    return dt.i18n('searchBuilder.conditions.date.equals', i18n.conditions.date.equals);
1577
                },
1578
                init: Criteria.initDate,
1579
                inputValue: Criteria.inputValueInput,
1580
                isInputValid: Criteria.isInputValidInput,
1581
                search: function (value, comparison, that) {
1582
                    return moment(value, that.s.dateFormat).valueOf() ===
1583
                        moment(comparison[0], that.s.dateFormat).valueOf();
1584
                }
1585
            },
1586
            // eslint-disable-next-line sort-keys
1587
            '!=': {
1588
                conditionName: function (dt, i18n) {
1589
                    return dt.i18n('searchBuilder.conditions.date.not', i18n.conditions.date.not);
1590
                },
1591
                init: Criteria.initDate,
1592
                inputValue: Criteria.inputValueInput,
1593
                isInputValid: Criteria.isInputValidInput,
1594
                search: function (value, comparison, that) {
1595
                    return moment(value, that.s.dateFormat).valueOf() !==
1596
                        moment(comparison[0], that.s.dateFormat).valueOf();
1597
                }
1598
            },
1599
            '<': {
1600
                conditionName: function (dt, i18n) {
1601
                    return dt.i18n('searchBuilder.conditions.date.before', i18n.conditions.date.before);
1602
                },
1603
                init: Criteria.initDate,
1604
                inputValue: Criteria.inputValueInput,
1605
                isInputValid: Criteria.isInputValidInput,
1606
                search: function (value, comparison, that) {
1607
                    return moment(value, that.s.dateFormat).valueOf() < moment(comparison[0], that.s.dateFormat).valueOf();
1608
                }
1609
            },
1610
            '>': {
1611
                conditionName: function (dt, i18n) {
1612
                    return dt.i18n('searchBuilder.conditions.date.after', i18n.conditions.date.after);
1613
                },
1614
                init: Criteria.initDate,
1615
                inputValue: Criteria.inputValueInput,
1616
                isInputValid: Criteria.isInputValidInput,
1617
                search: function (value, comparison, that) {
1618
                    return moment(value, that.s.dateFormat).valueOf() > moment(comparison[0], that.s.dateFormat).valueOf();
1619
                }
1620
            },
1621
            'between': {
1622
                conditionName: function (dt, i18n) {
1623
                    return dt.i18n('searchBuilder.conditions.date.between', i18n.conditions.date.between);
1624
                },
1625
                init: Criteria.init2Date,
1626
                inputValue: Criteria.inputValueInput,
1627
                isInputValid: Criteria.isInputValidInput,
1628
                search: function (value, comparison, that) {
1629
                    var val = moment(value, that.s.dateFormat).valueOf();
1630
                    var comp0 = moment(comparison[0], that.s.dateFormat).valueOf();
1631
                    var comp1 = moment(comparison[1], that.s.dateFormat).valueOf();
1632
                    if (comp0 < comp1) {
1633
                        return comp0 <= val && val <= comp1;
1634
                    }
1635
                    else {
1636
                        return comp1 <= val && val <= comp0;
1637
                    }
1638
                }
1639
            },
1640
            // eslint-disable-next-line sort-keys
1641
            '!between': {
1642
                conditionName: function (dt, i18n) {
1643
                    return dt.i18n('searchBuilder.conditions.date.notBetween', i18n.conditions.date.notBetween);
1644
                },
1645
                init: Criteria.init2Date,
1646
                inputValue: Criteria.inputValueInput,
1647
                isInputValid: Criteria.isInputValidInput,
1648
                search: function (value, comparison, that) {
1649
                    var val = moment(value, that.s.dateFormat).valueOf();
1650
                    var comp0 = moment(comparison[0], that.s.dateFormat).valueOf();
1651
                    var comp1 = moment(comparison[1], that.s.dateFormat).valueOf();
1652
                    if (comp0 < comp1) {
1653
                        return !(+comp0 <= +val && +val <= +comp1);
1654
                    }
1655
                    else {
1656
                        return !(+comp1 <= +val && +val <= +comp0);
1657
                    }
1658
                }
1659
            },
1660
            'null': {
1661
                conditionName: function (dt, i18n) {
1662
                    return dt.i18n('searchBuilder.conditions.date.empty', i18n.conditions.date.empty);
1663
                },
1664
                init: Criteria.initNoValue,
1665
                inputValue: function () {
1666
                    return;
1667
                },
1668
                isInputValid: function () {
1669
                    return true;
1670
                },
1671
                search: function (value) {
1672
                    return value === null || value === undefined || value.length === 0;
1673
                }
1674
            },
1675
            // eslint-disable-next-line sort-keys
1676
            '!null': {
1677
                conditionName: function (dt, i18n) {
1678
                    return dt.i18n('searchBuilder.conditions.date.notEmpty', i18n.conditions.date.notEmpty);
1679
                },
1680
                init: Criteria.initNoValue,
1681
                inputValue: function () {
1682
                    return;
1683
                },
1684
                isInputValid: function () {
1685
                    return true;
1686
                },
1687
                search: function (value) {
1688
                    return !(value === null || value === undefined || value.length === 0);
1689
                }
1690
            }
1691
        };
1692
        // The order of the conditions will make eslint sad :(
1693
        // Has to be in this order so that they are displayed correctly in select elements
1694
        // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
1695
        // eslint-disable-next-line @typescript-eslint/member-ordering
1696
        Criteria.luxonDateConditions = {
1697
            '=': {
1698
                conditionName: function (dt, i18n) {
1699
                    return dt.i18n('searchBuilder.conditions.date.equals', i18n.conditions.date.equals);
1700
                },
1701
                init: Criteria.initDate,
1702
                inputValue: Criteria.inputValueInput,
1703
                isInputValid: Criteria.isInputValidInput,
1704
                search: function (value, comparison, that) {
1705
                    return luxon.DateTime.fromFormat(value, that.s.dateFormat).ts
1706
                        === luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
1707
                }
1708
            },
1709
            // eslint-disable-next-line sort-keys
1710
            '!=': {
1711
                conditionName: function (dt, i18n) {
1712
                    return dt.i18n('searchBuilder.conditions.date.not', i18n.conditions.date.not);
1713
                },
1714
                init: Criteria.initDate,
1715
                inputValue: Criteria.inputValueInput,
1716
                isInputValid: Criteria.isInputValidInput,
1717
                search: function (value, comparison, that) {
1718
                    return luxon.DateTime.fromFormat(value, that.s.dateFormat).ts
1719
                        !== luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
1720
                }
1721
            },
1722
            '<': {
1723
                conditionName: function (dt, i18n) {
1724
                    return dt.i18n('searchBuilder.conditions.date.before', i18n.conditions.date.before);
1725
                },
1726
                init: Criteria.initDate,
1727
                inputValue: Criteria.inputValueInput,
1728
                isInputValid: Criteria.isInputValidInput,
1729
                search: function (value, comparison, that) {
1730
                    return luxon.DateTime.fromFormat(value, that.s.dateFormat).ts
1731
                        < luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
1732
                }
1733
            },
1734
            '>': {
1735
                conditionName: function (dt, i18n) {
1736
                    return dt.i18n('searchBuilder.conditions.date.after', i18n.conditions.date.after);
1737
                },
1738
                init: Criteria.initDate,
1739
                inputValue: Criteria.inputValueInput,
1740
                isInputValid: Criteria.isInputValidInput,
1741
                search: function (value, comparison, that) {
1742
                    return luxon.DateTime.fromFormat(value, that.s.dateFormat).ts
1743
                        > luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
1744
                }
1745
            },
1746
            'between': {
1747
                conditionName: function (dt, i18n) {
1748
                    return dt.i18n('searchBuilder.conditions.date.between', i18n.conditions.date.between);
1749
                },
1750
                init: Criteria.init2Date,
1751
                inputValue: Criteria.inputValueInput,
1752
                isInputValid: Criteria.isInputValidInput,
1753
                search: function (value, comparison, that) {
1754
                    var val = luxon.DateTime.fromFormat(value, that.s.dateFormat).ts;
1755
                    var comp0 = luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
1756
                    var comp1 = luxon.DateTime.fromFormat(comparison[1], that.s.dateFormat).ts;
1757
                    if (comp0 < comp1) {
1758
                        return comp0 <= val && val <= comp1;
1759
                    }
1760
                    else {
1761
                        return comp1 <= val && val <= comp0;
1762
                    }
1763
                }
1764
            },
1765
            // eslint-disable-next-line sort-keys
1766
            '!between': {
1767
                conditionName: function (dt, i18n) {
1768
                    return dt.i18n('searchBuilder.conditions.date.notBetween', i18n.conditions.date.notBetween);
1769
                },
1770
                init: Criteria.init2Date,
1771
                inputValue: Criteria.inputValueInput,
1772
                isInputValid: Criteria.isInputValidInput,
1773
                search: function (value, comparison, that) {
1774
                    var val = luxon.DateTime.fromFormat(value, that.s.dateFormat).ts;
1775
                    var comp0 = luxon.DateTime.fromFormat(comparison[0], that.s.dateFormat).ts;
1776
                    var comp1 = luxon.DateTime.fromFormat(comparison[1], that.s.dateFormat).ts;
1777
                    if (comp0 < comp1) {
1778
                        return !(+comp0 <= +val && +val <= +comp1);
1779
                    }
1780
                    else {
1781
                        return !(+comp1 <= +val && +val <= +comp0);
1782
                    }
1783
                }
1784
            },
1785
            'null': {
1786
                conditionName: function (dt, i18n) {
1787
                    return dt.i18n('searchBuilder.conditions.date.empty', i18n.conditions.date.empty);
1788
                },
1789
                init: Criteria.initNoValue,
1790
                inputValue: function () {
1791
                    return;
1792
                },
1793
                isInputValid: function () {
1794
                    return true;
1795
                },
1796
                search: function (value) {
1797
                    return value === null || value === undefined || value.length === 0;
1798
                }
1799
            },
1800
            // eslint-disable-next-line sort-keys
1801
            '!null': {
1802
                conditionName: function (dt, i18n) {
1803
                    return dt.i18n('searchBuilder.conditions.date.notEmpty', i18n.conditions.date.notEmpty);
1804
                },
1805
                init: Criteria.initNoValue,
1806
                inputValue: function () {
1807
                    return;
1808
                },
1809
                isInputValid: function () {
1810
                    return true;
1811
                },
1812
                search: function (value) {
1813
                    return !(value === null || value === undefined || value.length === 0);
1814
                }
1815
            }
1816
        };
1817
        // The order of the conditions will make eslint sad :(
1818
        // Has to be in this order so that they are displayed correctly in select elements
1819
        // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
1820
        // eslint-disable-next-line @typescript-eslint/member-ordering
1821
        Criteria.numConditions = {
1822
            '=': {
1823
                conditionName: function (dt, i18n) {
1824
                    return dt.i18n('searchBuilder.conditions.number.equals', i18n.conditions.number.equals);
1825
                },
1826
                init: Criteria.initSelect,
1827
                inputValue: Criteria.inputValueSelect,
1828
                isInputValid: Criteria.isInputValidSelect,
1829
                search: function (value, comparison) {
1830
                    return +value === +comparison[0];
1831
                }
1832
            },
1833
            // eslint-disable-next-line sort-keys
1834
            '!=': {
1835
                conditionName: function (dt, i18n) {
1836
                    return dt.i18n('searchBuilder.conditions.number.not', i18n.conditions.number.not);
1837
                },
1838
                init: Criteria.initSelect,
1839
                inputValue: Criteria.inputValueSelect,
1840
                isInputValid: Criteria.isInputValidSelect,
1841
                search: function (value, comparison) {
1842
                    return +value !== +comparison[0];
1843
                }
1844
            },
1845
            '<': {
1846
                conditionName: function (dt, i18n) {
1847
                    return dt.i18n('searchBuilder.conditions.number.lt', i18n.conditions.number.lt);
1848
                },
1849
                init: Criteria.initInput,
1850
                inputValue: Criteria.inputValueInput,
1851
                isInputValid: Criteria.isInputValidInput,
1852
                search: function (value, comparison) {
1853
                    return +value < +comparison[0];
1854
                }
1855
            },
1856
            '<=': {
1857
                conditionName: function (dt, i18n) {
1858
                    return dt.i18n('searchBuilder.conditions.number.lte', i18n.conditions.number.lte);
1859
                },
1860
                init: Criteria.initInput,
1861
                inputValue: Criteria.inputValueInput,
1862
                isInputValid: Criteria.isInputValidInput,
1863
                search: function (value, comparison) {
1864
                    return +value <= +comparison[0];
1865
                }
1866
            },
1867
            '>=': {
1868
                conditionName: function (dt, i18n) {
1869
                    return dt.i18n('searchBuilder.conditions.number.gte', i18n.conditions.number.gte);
1870
                },
1871
                init: Criteria.initInput,
1872
                inputValue: Criteria.inputValueInput,
1873
                isInputValid: Criteria.isInputValidInput,
1874
                search: function (value, comparison) {
1875
                    return +value >= +comparison[0];
1876
                }
1877
            },
1878
            // eslint-disable-next-line sort-keys
1879
            '>': {
1880
                conditionName: function (dt, i18n) {
1881
                    return dt.i18n('searchBuilder.conditions.number.gt', i18n.conditions.number.gt);
1882
                },
1883
                init: Criteria.initInput,
1884
                inputValue: Criteria.inputValueInput,
1885
                isInputValid: Criteria.isInputValidInput,
1886
                search: function (value, comparison) {
1887
                    return +value > +comparison[0];
1888
                }
1889
            },
1890
            'between': {
1891
                conditionName: function (dt, i18n) {
1892
                    return dt.i18n('searchBuilder.conditions.number.between', i18n.conditions.number.between);
1893
                },
1894
                init: Criteria.init2Input,
1895
                inputValue: Criteria.inputValueInput,
1896
                isInputValid: Criteria.isInputValidInput,
1897
                search: function (value, comparison) {
1898
                    if (+comparison[0] < +comparison[1]) {
1899
                        return +comparison[0] <= +value && +value <= +comparison[1];
1900
                    }
1901
                    else {
1902
                        return +comparison[1] <= +value && +value <= +comparison[0];
1903
                    }
1904
                }
1905
            },
1906
            // eslint-disable-next-line sort-keys
1907
            '!between': {
1908
                conditionName: function (dt, i18n) {
1909
                    return dt.i18n('searchBuilder.conditions.number.notBetween', i18n.conditions.number.notBetween);
1910
                },
1911
                init: Criteria.init2Input,
1912
                inputValue: Criteria.inputValueInput,
1913
                isInputValid: Criteria.isInputValidInput,
1914
                search: function (value, comparison) {
1915
                    if (+comparison[0] < +comparison[1]) {
1916
                        return !(+comparison[0] <= +value && +value <= +comparison[1]);
1917
                    }
1918
                    else {
1919
                        return !(+comparison[1] <= +value && +value <= +comparison[0]);
1920
                    }
1921
                }
1922
            },
1923
            'null': {
1924
                conditionName: function (dt, i18n) {
1925
                    return dt.i18n('searchBuilder.conditions.number.empty', i18n.conditions.number.empty);
1926
                },
1927
                init: Criteria.initNoValue,
1928
                inputValue: function () {
1929
                    return;
1930
                },
1931
                isInputValid: function () {
1932
                    return true;
1933
                },
1934
                search: function (value) {
1935
                    return value === null || value === undefined || value.length === 0;
1936
                }
1937
            },
1938
            // eslint-disable-next-line sort-keys
1939
            '!null': {
1940
                conditionName: function (dt, i18n) {
1941
                    return dt.i18n('searchBuilder.conditions.number.notEmpty', i18n.conditions.number.notEmpty);
1942
                },
1943
                init: Criteria.initNoValue,
1944
                inputValue: function () {
1945
                    return;
1946
                },
1947
                isInputValid: function () {
1948
                    return true;
1949
                },
1950
                search: function (value) {
1951
                    return !(value === null || value === undefined || value.length === 0);
1952
                }
1953
            }
1954
        };
1955
        // The order of the conditions will make eslint sad :(
1956
        // Has to be in this order so that they are displayed correctly in select elements
1957
        // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
1958
        // eslint-disable-next-line @typescript-eslint/member-ordering
1959
        Criteria.numFmtConditions = {
1960
            '=': {
1961
                conditionName: function (dt, i18n) {
1962
                    return dt.i18n('searchBuilder.conditions.number.equals', i18n.conditions.number.equals);
1963
                },
1964
                init: Criteria.initSelect,
1965
                inputValue: Criteria.inputValueSelect,
1966
                isInputValid: Criteria.isInputValidSelect,
1967
                search: function (value, comparison) {
1968
                    var val = value.indexOf('-') === 0 ?
1969
                        '-' + value.replace(/[^0-9.]/g, '') :
1970
                        value.replace(/[^0-9.]/g, '');
1971
                    var comp = comparison[0].indexOf('-') === 0 ?
1972
                        '-' + comparison[0].replace(/[^0-9.]/g, '') :
1973
                        comparison[0].replace(/[^0-9.]/g, '');
1974
                    return +val === +comp;
1975
                }
1976
            },
1977
            // eslint-disable-next-line sort-keys
1978
            '!=': {
1979
                conditionName: function (dt, i18n) {
1980
                    return dt.i18n('searchBuilder.conditions.number.not', i18n.conditions.number.not);
1981
                },
1982
                init: Criteria.initSelect,
1983
                inputValue: Criteria.inputValueSelect,
1984
                isInputValid: Criteria.isInputValidSelect,
1985
                search: function (value, comparison) {
1986
                    var val = value.indexOf('-') === 0 ?
1987
                        '-' + value.replace(/[^0-9.]/g, '') :
1988
                        value.replace(/[^0-9.]/g, '');
1989
                    var comp = comparison[0].indexOf('-') === 0 ?
1990
                        '-' + comparison[0].replace(/[^0-9.]/g, '') :
1991
                        comparison[0].replace(/[^0-9.]/g, '');
1992
                    return +val !== +comp;
1993
                }
1994
            },
1995
            '<': {
1996
                conditionName: function (dt, i18n) {
1997
                    return dt.i18n('searchBuilder.conditions.number.lt', i18n.conditions.number.lt);
1998
                },
1999
                init: Criteria.initInput,
2000
                inputValue: Criteria.inputValueInput,
2001
                isInputValid: Criteria.isInputValidInput,
2002
                search: function (value, comparison) {
2003
                    var val = value.indexOf('-') === 0 ?
2004
                        '-' + value.replace(/[^0-9.]/g, '') :
2005
                        value.replace(/[^0-9.]/g, '');
2006
                    var comp = comparison[0].indexOf('-') === 0 ?
2007
                        '-' + comparison[0].replace(/[^0-9.]/g, '') :
2008
                        comparison[0].replace(/[^0-9.]/g, '');
2009
                    return +val < +comp;
2010
                }
2011
            },
2012
            '<=': {
2013
                conditionName: function (dt, i18n) {
2014
                    return dt.i18n('searchBuilder.conditions.number.lte', i18n.conditions.number.lte);
2015
                },
2016
                init: Criteria.initInput,
2017
                inputValue: Criteria.inputValueInput,
2018
                isInputValid: Criteria.isInputValidInput,
2019
                search: function (value, comparison) {
2020
                    var val = value.indexOf('-') === 0 ?
2021
                        '-' + value.replace(/[^0-9.]/g, '') :
2022
                        value.replace(/[^0-9.]/g, '');
2023
                    var comp = comparison[0].indexOf('-') === 0 ?
2024
                        '-' + comparison[0].replace(/[^0-9.]/g, '') :
2025
                        comparison[0].replace(/[^0-9.]/g, '');
2026
                    return +val <= +comp;
2027
                }
2028
            },
2029
            '>=': {
2030
                conditionName: function (dt, i18n) {
2031
                    return dt.i18n('searchBuilder.conditions.number.gte', i18n.conditions.number.gte);
2032
                },
2033
                init: Criteria.initInput,
2034
                inputValue: Criteria.inputValueInput,
2035
                isInputValid: Criteria.isInputValidInput,
2036
                search: function (value, comparison) {
2037
                    var val = value.indexOf('-') === 0 ?
2038
                        '-' + value.replace(/[^0-9.]/g, '') :
2039
                        value.replace(/[^0-9.]/g, '');
2040
                    var comp = comparison[0].indexOf('-') === 0 ?
2041
                        '-' + comparison[0].replace(/[^0-9.]/g, '') :
2042
                        comparison[0].replace(/[^0-9.]/g, '');
2043
                    return +val >= +comp;
2044
                }
2045
            },
2046
            // eslint-disable-next-line sort-keys
2047
            '>': {
2048
                conditionName: function (dt, i18n) {
2049
                    return dt.i18n('searchBuilder.conditions.number.gt', i18n.conditions.number.gt);
2050
                },
2051
                init: Criteria.initInput,
2052
                inputValue: Criteria.inputValueInput,
2053
                isInputValid: Criteria.isInputValidInput,
2054
                search: function (value, comparison) {
2055
                    var val = value.indexOf('-') === 0 ?
2056
                        '-' + value.replace(/[^0-9.]/g, '') :
2057
                        value.replace(/[^0-9.]/g, '');
2058
                    var comp = comparison[0].indexOf('-') === 0 ?
2059
                        '-' + comparison[0].replace(/[^0-9.]/g, '') :
2060
                        comparison[0].replace(/[^0-9.]/g, '');
2061
                    return +val > +comp;
2062
                }
2063
            },
2064
            'between': {
2065
                conditionName: function (dt, i18n) {
2066
                    return dt.i18n('searchBuilder.conditions.number.between', i18n.conditions.number.between);
2067
                },
2068
                init: Criteria.init2Input,
2069
                inputValue: Criteria.inputValueInput,
2070
                isInputValid: Criteria.isInputValidInput,
2071
                search: function (value, comparison) {
2072
                    var val = value.indexOf('-') === 0 ?
2073
                        '-' + value.replace(/[^0-9.]/g, '') :
2074
                        value.replace(/[^0-9.]/g, '');
2075
                    var comp0 = comparison[0].indexOf('-') === 0 ?
2076
                        '-' + comparison[0].replace(/[^0-9.]/g, '') :
2077
                        comparison[0].replace(/[^0-9.]/g, '');
2078
                    var comp1 = comparison[1].indexOf('-') === 0 ?
2079
                        '-' + comparison[1].replace(/[^0-9.]/g, '') :
2080
                        comparison[1].replace(/[^0-9.]/g, '');
2081
                    if (+comp0 < +comp1) {
2082
                        return +comp0 <= +val && +val <= +comp1;
2083
                    }
2084
                    else {
2085
                        return +comp1 <= +val && +val <= +comp0;
2086
                    }
2087
                }
2088
            },
2089
            // eslint-disable-next-line sort-keys
2090
            '!between': {
2091
                conditionName: function (dt, i18n) {
2092
                    return dt.i18n('searchBuilder.conditions.number.notBetween', i18n.conditions.number.notBetween);
2093
                },
2094
                init: Criteria.init2Input,
2095
                inputValue: Criteria.inputValueInput,
2096
                isInputValid: Criteria.isInputValidInput,
2097
                search: function (value, comparison) {
2098
                    var val = value.indexOf('-') === 0 ?
2099
                        '-' + value.replace(/[^0-9.]/g, '') :
2100
                        value.replace(/[^0-9.]/g, '');
2101
                    var comp0 = comparison[0].indexOf('-') === 0 ?
2102
                        '-' + comparison[0].replace(/[^0-9.]/g, '') :
2103
                        comparison[0].replace(/[^0-9.]/g, '');
2104
                    var comp1 = comparison[1].indexOf('-') === 0 ?
2105
                        '-' + comparison[1].replace(/[^0-9.]/g, '') :
2106
                        comparison[1].replace(/[^0-9.]/g, '');
2107
                    if (+comp0 < +comp1) {
2108
                        return !(+comp0 <= +val && +val <= +comp1);
2109
                    }
2110
                    else {
2111
                        return !(+comp1 <= +val && +val <= +comp0);
2112
                    }
2113
                }
2114
            },
2115
            'null': {
2116
                conditionName: function (dt, i18n) {
2117
                    return dt.i18n('searchBuilder.conditions.number.empty', i18n.conditions.number.empty);
2118
                },
2119
                init: Criteria.initNoValue,
2120
                inputValue: function () {
2121
                    return;
2122
                },
2123
                isInputValid: function () {
2124
                    return true;
2125
                },
2126
                search: function (value) {
2127
                    return value === null || value === undefined || value.length === 0;
2128
                }
2129
            },
2130
            // eslint-disable-next-line sort-keys
2131
            '!null': {
2132
                conditionName: function (dt, i18n) {
2133
                    return dt.i18n('searchBuilder.conditions.number.notEmpty', i18n.conditions.number.notEmpty);
2134
                },
2135
                init: Criteria.initNoValue,
2136
                inputValue: function () {
2137
                    return;
2138
                },
2139
                isInputValid: function () {
2140
                    return true;
2141
                },
2142
                search: function (value) {
2143
                    return !(value === null || value === undefined || value.length === 0);
2144
                }
2145
            }
2146
        };
2147
        // The order of the conditions will make eslint sad :(
2148
        // Has to be in this order so that they are displayed correctly in select elements
2149
        // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
2150
        // eslint-disable-next-line @typescript-eslint/member-ordering
2151
        Criteria.stringConditions = {
2152
            '=': {
2153
                conditionName: function (dt, i18n) {
2154
                    return dt.i18n('searchBuilder.conditions.string.equals', i18n.conditions.string.equals);
2155
                },
2156
                init: Criteria.initSelect,
2157
                inputValue: Criteria.inputValueSelect,
2158
                isInputValid: Criteria.isInputValidSelect,
2159
                search: function (value, comparison) {
2160
                    return value === comparison[0];
2161
                }
2162
            },
2163
            // eslint-disable-next-line sort-keys
2164
            '!=': {
2165
                conditionName: function (dt, i18n) {
2166
                    return dt.i18n('searchBuilder.conditions.string.not', i18n.conditions.string.not);
2167
                },
2168
                init: Criteria.initSelect,
2169
                inputValue: Criteria.inputValueSelect,
2170
                isInputValid: Criteria.isInputValidInput,
2171
                search: function (value, comparison) {
2172
                    return value !== comparison[0];
2173
                }
2174
            },
2175
            'starts': {
2176
                conditionName: function (dt, i18n) {
2177
                    return dt.i18n('searchBuilder.conditions.string.startsWith', i18n.conditions.string.startsWith);
2178
                },
2179
                init: Criteria.initInput,
2180
                inputValue: Criteria.inputValueInput,
2181
                isInputValid: Criteria.isInputValidInput,
2182
                search: function (value, comparison) {
2183
                    return value.toLowerCase().indexOf(comparison[0].toLowerCase()) === 0;
2184
                }
2185
            },
2186
            // eslint-disable-next-line sort-keys
2187
            '!starts': {
2188
                conditionName: function (dt, i18n) {
2189
                    return dt.i18n('searchBuilder.conditions.string.notStartsWith', i18n.conditions.string.notStartsWith);
2190
                },
2191
                init: Criteria.initInput,
2192
                inputValue: Criteria.inputValueInput,
2193
                isInputValid: Criteria.isInputValidInput,
2194
                search: function (value, comparison) {
2195
                    return value.toLowerCase().indexOf(comparison[0].toLowerCase()) !== 0;
2196
                }
2197
            },
2198
            // eslint-disable-next-line sort-keys
2199
            'contains': {
2200
                conditionName: function (dt, i18n) {
2201
                    return dt.i18n('searchBuilder.conditions.string.contains', i18n.conditions.string.contains);
2202
                },
2203
                init: Criteria.initInput,
2204
                inputValue: Criteria.inputValueInput,
2205
                isInputValid: Criteria.isInputValidInput,
2206
                search: function (value, comparison) {
2207
                    return value.toLowerCase().includes(comparison[0].toLowerCase());
2208
                }
2209
            },
2210
            // eslint-disable-next-line sort-keys
2211
            '!contains': {
2212
                conditionName: function (dt, i18n) {
2213
                    return dt.i18n('searchBuilder.conditions.string.notContains', i18n.conditions.string.notContains);
2214
                },
2215
                init: Criteria.initInput,
2216
                inputValue: Criteria.inputValueInput,
2217
                isInputValid: Criteria.isInputValidInput,
2218
                search: function (value, comparison) {
2219
                    return !value.toLowerCase().includes(comparison[0].toLowerCase());
2220
                }
2221
            },
2222
            'ends': {
2223
                conditionName: function (dt, i18n) {
2224
                    return dt.i18n('searchBuilder.conditions.string.endsWith', i18n.conditions.string.endsWith);
2225
                },
2226
                init: Criteria.initInput,
2227
                inputValue: Criteria.inputValueInput,
2228
                isInputValid: Criteria.isInputValidInput,
2229
                search: function (value, comparison) {
2230
                    return value.toLowerCase().endsWith(comparison[0].toLowerCase());
2231
                }
2232
            },
2233
            // eslint-disable-next-line sort-keys
2234
            '!ends': {
2235
                conditionName: function (dt, i18n) {
2236
                    return dt.i18n('searchBuilder.conditions.string.notEndsWith', i18n.conditions.string.notEndsWith);
2237
                },
2238
                init: Criteria.initInput,
2239
                inputValue: Criteria.inputValueInput,
2240
                isInputValid: Criteria.isInputValidInput,
2241
                search: function (value, comparison) {
2242
                    return !value.toLowerCase().endsWith(comparison[0].toLowerCase());
2243
                }
2244
            },
2245
            'null': {
2246
                conditionName: function (dt, i18n) {
2247
                    return dt.i18n('searchBuilder.conditions.string.empty', i18n.conditions.string.empty);
2248
                },
2249
                init: Criteria.initNoValue,
2250
                inputValue: function () {
2251
                    return;
2252
                },
2253
                isInputValid: function () {
2254
                    return true;
2255
                },
2256
                search: function (value) {
2257
                    return value === null || value === undefined || value.length === 0;
2258
                }
2259
            },
2260
            // eslint-disable-next-line sort-keys
2261
            '!null': {
2262
                conditionName: function (dt, i18n) {
2263
                    return dt.i18n('searchBuilder.conditions.string.notEmpty', i18n.conditions.string.notEmpty);
2264
                },
2265
                init: Criteria.initNoValue,
2266
                inputValue: function () {
2267
                    return;
2268
                },
2269
                isInputValid: function () {
2270
                    return true;
2271
                },
2272
                search: function (value) {
2273
                    return !(value === null || value === undefined || value.length === 0);
2274
                }
2275
            }
2276
        };
2277
        // The order of the conditions will make eslint sad :(
2278
        // Also have to disable member ordering for this as the private methods used are not yet declared otherwise
2279
        // eslint-disable-next-line @typescript-eslint/member-ordering
2280
        Criteria.arrayConditions = {
2281
            'contains': {
2282
                conditionName: function (dt, i18n) {
2283
                    return dt.i18n('searchBuilder.conditions.array.contains', i18n.conditions.array.contains);
2284
                },
2285
                init: Criteria.initSelectArray,
2286
                inputValue: Criteria.inputValueSelect,
2287
                isInputValid: Criteria.isInputValidSelect,
2288
                search: function (value, comparison) {
2289
                    return value.includes(comparison[0]);
2290
                }
2291
            },
2292
            'without': {
2293
                conditionName: function (dt, i18n) {
2294
                    return dt.i18n('searchBuilder.conditions.array.without', i18n.conditions.array.without);
2295
                },
2296
                init: Criteria.initSelectArray,
2297
                inputValue: Criteria.inputValueSelect,
2298
                isInputValid: Criteria.isInputValidSelect,
2299
                search: function (value, comparison) {
2300
                    return value.indexOf(comparison[0]) === -1;
2301
                }
2302
            },
2303
            // eslint-disable-next-line sort-keys
2304
            '=': {
2305
                conditionName: function (dt, i18n) {
2306
                    return dt.i18n('searchBuilder.conditions.array.equals', i18n.conditions.array.equals);
2307
                },
2308
                init: Criteria.initSelect,
2309
                inputValue: Criteria.inputValueSelect,
2310
                isInputValid: Criteria.isInputValidSelect,
2311
                search: function (value, comparison) {
2312
                    if (value.length === comparison[0].length) {
2313
                        for (var i = 0; i < value.length; i++) {
2314
                            if (value[i] !== comparison[0][i]) {
2315
                                return false;
2316
                            }
2317
                        }
2318
                        return true;
2319
                    }
2320
                    return false;
2321
                }
2322
            },
2323
            // eslint-disable-next-line sort-keys
2324
            '!=': {
2325
                conditionName: function (dt, i18n) {
2326
                    return dt.i18n('searchBuilder.conditions.array.not', i18n.conditions.array.not);
2327
                },
2328
                init: Criteria.initSelect,
2329
                inputValue: Criteria.inputValueSelect,
2330
                isInputValid: Criteria.isInputValidSelect,
2331
                search: function (value, comparison) {
2332
                    if (value.length === comparison[0].length) {
2333
                        for (var i = 0; i < value.length; i++) {
2334
                            if (value[i] !== comparison[0][i]) {
2335
                                return true;
2336
                            }
2337
                        }
2338
                        return false;
2339
                    }
2340
                    return true;
2341
                }
2342
            },
2343
            'null': {
2344
                conditionName: function (dt, i18n) {
2345
                    return dt.i18n('searchBuilder.conditions.array.empty', i18n.conditions.array.empty);
2346
                },
2347
                init: Criteria.initNoValue,
2348
                inputValue: function () {
2349
                    return;
2350
                },
2351
                isInputValid: function () {
2352
                    return true;
2353
                },
2354
                search: function (value) {
2355
                    return value === null || value === undefined || value.length === 0;
2356
                }
2357
            },
2358
            // eslint-disable-next-line sort-keys
2359
            '!null': {
2360
                conditionName: function (dt, i18n) {
2361
                    return dt.i18n('searchBuilder.conditions.array.notEmpty', i18n.conditions.array.notEmpty);
2362
                },
2363
                init: Criteria.initNoValue,
2364
                inputValue: function () {
2365
                    return;
2366
                },
2367
                isInputValid: function () {
2368
                    return true;
2369
                },
2370
                search: function (value) {
2371
                    return value !== null && value !== undefined && value.length !== 0;
2372
                }
2373
            }
2374
        };
2375
        // eslint will be sad because we have to disable member ordering for this as the
2376
        // private static properties used are not yet declared otherwise
2377
        // eslint-disable-next-line @typescript-eslint/member-ordering
2378
        Criteria.defaults = {
2379
            columns: true,
2380
            conditions: {
2381
                'array': Criteria.arrayConditions,
2382
                'date': Criteria.dateConditions,
2383
                'html': Criteria.stringConditions,
2384
                'html-num': Criteria.numConditions,
2385
                'html-num-fmt': Criteria.numFmtConditions,
2386
                'luxon': Criteria.luxonDateConditions,
2387
                'moment': Criteria.momentDateConditions,
2388
                'num': Criteria.numConditions,
2389
                'num-fmt': Criteria.numFmtConditions,
2390
                'string': Criteria.stringConditions
2391
            },
2392
            depthLimit: false,
2393
            enterSearch: false,
2394
            filterChanged: undefined,
2395
            greyscale: false,
2396
            i18n: {
2397
                add: 'Add Condition',
2398
                button: {
2399
                    0: 'Search Builder',
2400
                    _: 'Search Builder (%d)'
2401
                },
2402
                clearAll: 'Clear All',
2403
                condition: 'Condition',
2404
                data: 'Data',
2405
                "delete": '&times',
2406
                deleteTitle: 'Delete filtering rule',
2407
                left: '<',
2408
                leftTitle: 'Outdent criteria',
2409
                logicAnd: 'And',
2410
                logicOr: 'Or',
2411
                right: '>',
2412
                rightTitle: 'Indent criteria',
2413
                title: {
2414
                    0: 'Custom Search Builder',
2415
                    _: 'Custom Search Builder (%d)'
2416
                },
2417
                value: 'Value',
2418
                valueJoiner: 'and'
2419
            },
2420
            logic: 'AND',
2421
            orthogonal: {
2422
                display: 'display',
2423
                search: 'filter'
2424
            },
2425
            preDefined: false
2426
        };
2427
        return Criteria;
2428
    }());
2429

2430
    var $$1;
2431
    var dataTable$1;
2432
    /**
2433
     * Sets the value of jQuery for use in the file
2434
     *
2435
     * @param jq the instance of jQuery to be set
2436
     */
2437
    function setJQuery$1(jq) {
2438
        $$1 = jq;
2439
        dataTable$1 = jq.fn.dataTable;
2440
    }
2441
    /**
2442
     * The Group class is used within SearchBuilder to represent a group of criteria
2443
     */
2444
    var Group = /** @class */ (function () {
2445
        function Group(table, opts, topGroup, index, isChild, depth) {
2446
            if (index === void 0) { index = 0; }
2447
            if (isChild === void 0) { isChild = false; }
2448
            if (depth === void 0) { depth = 1; }
2449
            // Check that the required version of DataTables is included
2450
            if (!dataTable$1 || !dataTable$1.versionCheck || !dataTable$1.versionCheck('1.10.0')) {
2451
                throw new Error('SearchBuilder requires DataTables 1.10 or newer');
2452
            }
2453
            this.classes = $$1.extend(true, {}, Group.classes);
2454
            // Get options from user
2455
            this.c = $$1.extend(true, {}, Group.defaults, opts);
2456
            this.s = {
2457
                criteria: [],
2458
                depth: depth,
2459
                dt: table,
2460
                index: index,
2461
                isChild: isChild,
2462
                logic: undefined,
2463
                opts: opts,
2464
                preventRedraw: false,
2465
                toDrop: undefined,
2466
                topGroup: topGroup
2467
            };
2468
            this.dom = {
2469
                add: $$1('<button/>')
2470
                    .addClass(this.classes.add)
2471
                    .addClass(this.classes.button)
2472
                    .attr('type', 'button'),
2473
                clear: $$1('<button>&times</button>')
2474
                    .addClass(this.classes.button)
2475
                    .addClass(this.classes.clearGroup)
2476
                    .attr('type', 'button'),
2477
                container: $$1('<div/>')
2478
                    .addClass(this.classes.group),
2479
                logic: $$1('<button><div/></button>')
2480
                    .addClass(this.classes.logic)
2481
                    .addClass(this.classes.button)
2482
                    .attr('type', 'button'),
2483
                logicContainer: $$1('<div/>')
2484
                    .addClass(this.classes.logicContainer)
2485
            };
2486
            // A reference to the top level group is maintained throughout any subgroups and criteria that may be created
2487
            if (this.s.topGroup === undefined) {
2488
                this.s.topGroup = this.dom.container;
2489
            }
2490
            this._setup();
2491
            return this;
2492
        }
2493
        /**
2494
         * Destroys the groups buttons, clears the internal criteria and removes it from the dom
2495
         */
2496
        Group.prototype.destroy = function () {
2497
            // Turn off listeners
2498
            this.dom.add.off('.dtsb');
2499
            this.dom.logic.off('.dtsb');
2500
            // Trigger event for groups at a higher level to pick up on
2501
            this.dom.container
2502
                .trigger('dtsb-destroy')
2503
                .remove();
2504
            this.s.criteria = [];
2505
        };
2506
        /**
2507
         * Gets the details required to rebuild the group
2508
         */
2509
        // Eslint upset at empty object but needs to be done
2510
        // eslint-disable-next-line @typescript-eslint/ban-types
2511
        Group.prototype.getDetails = function (deFormatDates) {
2512
            if (deFormatDates === void 0) { deFormatDates = false; }
2513
            if (this.s.criteria.length === 0) {
2514
                return {};
2515
            }
2516
            var details = {
2517
                criteria: [],
2518
                logic: this.s.logic
2519
            };
2520
            // NOTE here crit could be either a subgroup or a criteria
2521
            for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
2522
                var crit = _a[_i];
2523
                details.criteria.push(crit.criteria.getDetails(deFormatDates));
2524
            }
2525
            return details;
2526
        };
2527
        /**
2528
         * Getter for the node for the container of the group
2529
         *
2530
         * @returns Node for the container of the group
2531
         */
2532
        Group.prototype.getNode = function () {
2533
            return this.dom.container;
2534
        };
2535
        /**
2536
         * Rebuilds the group based upon the details passed in
2537
         *
2538
         * @param loadedDetails the details required to rebuild the group
2539
         */
2540
        Group.prototype.rebuild = function (loadedDetails) {
2541
            // If no criteria are stored then just return
2542
            if (loadedDetails.criteria === undefined ||
2543
                loadedDetails.criteria === null ||
2544
                Array.isArray(loadedDetails.criteria) && loadedDetails.criteria.length === 0) {
2545
                return;
2546
            }
2547
            this.s.logic = loadedDetails.logic;
2548
            this.dom.logic.children().first().html(this.s.logic === 'OR'
2549
                ? this.s.dt.i18n('searchBuilder.logicOr', this.c.i18n.logicOr)
2550
                : this.s.dt.i18n('searchBuilder.logicAnd', this.c.i18n.logicAnd));
2551
            // Add all of the criteria, be it a sub group or a criteria
2552
            if (Array.isArray(loadedDetails.criteria)) {
2553
                for (var _i = 0, _a = loadedDetails.criteria; _i < _a.length; _i++) {
2554
                    var crit = _a[_i];
2555
                    if (crit.logic !== undefined) {
2556
                        this._addPrevGroup(crit);
2557
                    }
2558
                    else if (crit.logic === undefined) {
2559
                        this._addPrevCriteria(crit);
2560
                    }
2561
                }
2562
            }
2563
            // For all of the criteria children, update the arrows incase they require changing and set the listeners
2564
            for (var _b = 0, _c = this.s.criteria; _b < _c.length; _b++) {
2565
                var crit = _c[_b];
2566
                if (crit.criteria instanceof Criteria) {
2567
                    crit.criteria.updateArrows(this.s.criteria.length > 1, false);
2568
                    this._setCriteriaListeners(crit.criteria);
2569
                }
2570
            }
2571
        };
2572
        /**
2573
         * Redraws the Contents of the searchBuilder Groups and Criteria
2574
         */
2575
        Group.prototype.redrawContents = function () {
2576
            if (this.s.preventRedraw) {
2577
                return;
2578
            }
2579
            // Clear the container out and add the basic elements
2580
            this.dom.container.children().detach();
2581
            this.dom.container
2582
                .append(this.dom.logicContainer)
2583
                .append(this.dom.add);
2584
            // Sort the criteria by index so that they appear in the correct order
2585
            this.s.criteria.sort(function (a, b) {
2586
                if (a.criteria.s.index < b.criteria.s.index) {
2587
                    return -1;
2588
                }
2589
                else if (a.criteria.s.index > b.criteria.s.index) {
2590
                    return 1;
2591
                }
2592
                return 0;
2593
            });
2594
            this.setListeners();
2595
            for (var i = 0; i < this.s.criteria.length; i++) {
2596
                var crit = this.s.criteria[i].criteria;
2597
                if (crit instanceof Criteria) {
2598
                    // Reset the index to the new value
2599
                    this.s.criteria[i].index = i;
2600
                    this.s.criteria[i].criteria.s.index = i;
2601
                    // Add to the group
2602
                    this.s.criteria[i].criteria.dom.container.insertBefore(this.dom.add);
2603
                    // Set listeners for various points
2604
                    this._setCriteriaListeners(crit);
2605
                    this.s.criteria[i].criteria.rebuild(this.s.criteria[i].criteria.getDetails());
2606
                }
2607
                else if (crit instanceof Group && crit.s.criteria.length > 0) {
2608
                    // Reset the index to the new value
2609
                    this.s.criteria[i].index = i;
2610
                    this.s.criteria[i].criteria.s.index = i;
2611
                    // Add the sub group to the group
2612
                    this.s.criteria[i].criteria.dom.container.insertBefore(this.dom.add);
2613
                    // Redraw the contents of the group
2614
                    crit.redrawContents();
2615
                    this._setGroupListeners(crit);
2616
                }
2617
                else {
2618
                    // The group is empty so remove it
2619
                    this.s.criteria.splice(i, 1);
2620
                    i--;
2621
                }
2622
            }
2623
            this.setupLogic();
2624
        };
2625
        /**
2626
         * Resizes the logic button only rather than the entire dom.
2627
         */
2628
        Group.prototype.redrawLogic = function () {
2629
            for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
2630
                var crit = _a[_i];
2631
                if (crit instanceof Group) {
2632
                    crit.redrawLogic();
2633
                }
2634
            }
2635
            this.setupLogic();
2636
        };
2637
        /**
2638
         * Search method, checking the row data against the criteria in the group
2639
         *
2640
         * @param rowData The row data to be compared
2641
         * @returns boolean The result of the search
2642
         */
2643
        Group.prototype.search = function (rowData, rowIdx) {
2644
            if (this.s.logic === 'AND') {
2645
                return this._andSearch(rowData, rowIdx);
2646
            }
2647
            else if (this.s.logic === 'OR') {
2648
                return this._orSearch(rowData, rowIdx);
2649
            }
2650
            return true;
2651
        };
2652
        /**
2653
         * Locates the groups logic button to the correct location on the page
2654
         */
2655
        Group.prototype.setupLogic = function () {
2656
            // Remove logic button
2657
            this.dom.logicContainer.remove();
2658
            this.dom.clear.remove();
2659
            // If there are no criteria in the group then keep the logic removed and return
2660
            if (this.s.criteria.length < 1) {
2661
                if (!this.s.isChild) {
2662
                    this.dom.container.trigger('dtsb-destroy');
2663
                    // Set criteria left margin
2664
                    this.dom.container.css('margin-left', 0);
2665
                }
2666
                return;
2667
            }
2668
            // Set width, take 2 for the border
2669
            var height = this.dom.container.height() - 1;
2670
            this.dom.clear.height('0px');
2671
            this.dom.logicContainer.append(this.dom.clear).width(height);
2672
            // Prepend logic button
2673
            this.dom.container.prepend(this.dom.logicContainer);
2674
            this._setLogicListener();
2675
            // Set criteria left margin
2676
            this.dom.container.css('margin-left', this.dom.logicContainer.outerHeight(true));
2677
            var logicOffset = this.dom.logicContainer.offset();
2678
            // Set horizontal alignment
2679
            var currentLeft = logicOffset.left;
2680
            var groupLeft = this.dom.container.offset().left;
2681
            var shuffleLeft = currentLeft - groupLeft;
2682
            var newPos = currentLeft - shuffleLeft - this.dom.logicContainer.outerHeight(true);
2683
            this.dom.logicContainer.offset({ left: newPos });
2684
            // Set vertical alignment
2685
            var firstCrit = this.dom.logicContainer.next();
2686
            var currentTop = logicOffset.top;
2687
            var firstTop = $$1(firstCrit).offset().top;
2688
            var shuffleTop = currentTop - firstTop;
2689
            var newTop = currentTop - shuffleTop;
2690
            this.dom.logicContainer.offset({ top: newTop });
2691
            this.dom.clear.outerHeight(this.dom.logicContainer.height());
2692
            this._setClearListener();
2693
        };
2694
        /**
2695
         * Sets listeners on the groups elements
2696
         */
2697
        Group.prototype.setListeners = function () {
2698
            var _this = this;
2699
            this.dom.add.unbind('click');
2700
            this.dom.add.on('click.dtsb', function () {
2701
                // If this is the parent group then the logic button has not been added yet
2702
                if (!_this.s.isChild) {
2703
                    _this.dom.container.prepend(_this.dom.logicContainer);
2704
                }
2705
                _this.addCriteria();
2706
                _this.dom.container.trigger('dtsb-add');
2707
                _this.s.dt.state.save();
2708
                return false;
2709
            });
2710
            for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
2711
                var crit = _a[_i];
2712
                crit.criteria.setListeners();
2713
            }
2714
            this._setClearListener();
2715
            this._setLogicListener();
2716
        };
2717
        /**
2718
         * Adds a criteria to the group
2719
         *
2720
         * @param crit Instance of Criteria to be added to the group
2721
         */
2722
        Group.prototype.addCriteria = function (crit, redraw) {
2723
            if (crit === void 0) { crit = null; }
2724
            if (redraw === void 0) { redraw = true; }
2725
            var index = crit === null ? this.s.criteria.length : crit.s.index;
2726
            var criteria = new Criteria(this.s.dt, this.s.opts, this.s.topGroup, index, this.s.depth);
2727
            // If a Criteria has been passed in then set the values to continue that
2728
            if (crit !== null) {
2729
                criteria.c = crit.c;
2730
                criteria.s = crit.s;
2731
                criteria.s.depth = this.s.depth;
2732
                criteria.classes = crit.classes;
2733
            }
2734
            criteria.populate();
2735
            var inserted = false;
2736
            for (var i = 0; i < this.s.criteria.length; i++) {
2737
                if (i === 0 && this.s.criteria[i].criteria.s.index > criteria.s.index) {
2738
                    // Add the node for the criteria at the start of the group
2739
                    criteria.getNode().insertBefore(this.s.criteria[i].criteria.dom.container);
2740
                    inserted = true;
2741
                }
2742
                else if (i < this.s.criteria.length - 1 &&
2743
                    this.s.criteria[i].criteria.s.index < criteria.s.index &&
2744
                    this.s.criteria[i + 1].criteria.s.index > criteria.s.index) {
2745
                    // Add the node for the criteria in the correct location
2746
                    criteria.getNode().insertAfter(this.s.criteria[i].criteria.dom.container);
2747
                    inserted = true;
2748
                }
2749
            }
2750
            if (!inserted) {
2751
                criteria.getNode().insertBefore(this.dom.add);
2752
            }
2753
            // Add the details for this criteria to the array
2754
            this.s.criteria.push({
2755
                criteria: criteria,
2756
                index: index
2757
            });
2758
            this.s.criteria = this.s.criteria.sort(function (a, b) { return a.criteria.s.index - b.criteria.s.index; });
2759
            for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
2760
                var opt = _a[_i];
2761
                if (opt.criteria instanceof Criteria) {
2762
                    opt.criteria.updateArrows(this.s.criteria.length > 1, redraw);
2763
                }
2764
            }
2765
            this._setCriteriaListeners(criteria);
2766
            criteria.setListeners();
2767
            this.setupLogic();
2768
        };
2769
        /**
2770
         * Checks the group to see if it has any filled criteria
2771
         */
2772
        Group.prototype.checkFilled = function () {
2773
            for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
2774
                var crit = _a[_i];
2775
                if (crit.criteria instanceof Criteria && crit.criteria.s.filled ||
2776
                    crit.criteria instanceof Group && crit.criteria.checkFilled()) {
2777
                    return true;
2778
                }
2779
            }
2780
            return false;
2781
        };
2782
        /**
2783
         * Gets the count for the number of criteria in this group and any sub groups
2784
         */
2785
        Group.prototype.count = function () {
2786
            var count = 0;
2787
            for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
2788
                var crit = _a[_i];
2789
                if (crit.criteria instanceof Group) {
2790
                    count += crit.criteria.count();
2791
                }
2792
                else {
2793
                    count++;
2794
                }
2795
            }
2796
            return count;
2797
        };
2798
        /**
2799
         * Rebuilds a sub group that previously existed
2800
         *
2801
         * @param loadedGroup The details of a group within this group
2802
         */
2803
        Group.prototype._addPrevGroup = function (loadedGroup) {
2804
            var idx = this.s.criteria.length;
2805
            var group = new Group(this.s.dt, this.c, this.s.topGroup, idx, true, this.s.depth + 1);
2806
            // Add the new group to the criteria array
2807
            this.s.criteria.push({
2808
                criteria: group,
2809
                index: idx,
2810
                logic: group.s.logic
2811
            });
2812
            // Rebuild it with the previous conditions for that group
2813
            group.rebuild(loadedGroup);
2814
            this.s.criteria[idx].criteria = group;
2815
            this.s.topGroup.trigger('dtsb-redrawContents');
2816
            this._setGroupListeners(group);
2817
        };
2818
        /**
2819
         * Rebuilds a criteria of this group that previously existed
2820
         *
2821
         * @param loadedCriteria The details of a criteria within the group
2822
         */
2823
        Group.prototype._addPrevCriteria = function (loadedCriteria) {
2824
            var idx = this.s.criteria.length;
2825
            var criteria = new Criteria(this.s.dt, this.s.opts, this.s.topGroup, idx, this.s.depth);
2826
            criteria.populate();
2827
            // Add the new criteria to the criteria array
2828
            this.s.criteria.push({
2829
                criteria: criteria,
2830
                index: idx
2831
            });
2832
            // Rebuild it with the previous conditions for that criteria
2833
            criteria.rebuild(loadedCriteria);
2834
            this.s.criteria[idx].criteria = criteria;
2835
            this.s.topGroup.trigger('dtsb-redrawContents');
2836
        };
2837
        /**
2838
         * Checks And the criteria using AND logic
2839
         *
2840
         * @param rowData The row data to be checked against the search criteria
2841
         * @returns boolean The result of the AND search
2842
         */
2843
        Group.prototype._andSearch = function (rowData, rowIdx) {
2844
            // If there are no criteria then return true for this group
2845
            if (this.s.criteria.length === 0) {
2846
                return true;
2847
            }
2848
            for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
2849
                var crit = _a[_i];
2850
                // If the criteria is not complete then skip it
2851
                if (crit.criteria instanceof Criteria && !crit.criteria.s.filled) {
2852
                    continue;
2853
                }
2854
                // Otherwise if a single one fails return false
2855
                else if (!crit.criteria.search(rowData, rowIdx)) {
2856
                    return false;
2857
                }
2858
            }
2859
            // If we get to here then everything has passed, so return true for the group
2860
            return true;
2861
        };
2862
        /**
2863
         * Checks And the criteria using OR logic
2864
         *
2865
         * @param rowData The row data to be checked against the search criteria
2866
         * @returns boolean The result of the OR search
2867
         */
2868
        Group.prototype._orSearch = function (rowData, rowIdx) {
2869
            // If there are no criteria in the group then return true
2870
            if (this.s.criteria.length === 0) {
2871
                return true;
2872
            }
2873
            // This will check to make sure that at least one criteria in the group is complete
2874
            var filledfound = false;
2875
            for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
2876
                var crit = _a[_i];
2877
                if (crit.criteria instanceof Criteria && crit.criteria.s.filled) {
2878
                    // A completed criteria has been found so set the flag
2879
                    filledfound = true;
2880
                    // If the search passes then return true
2881
                    if (crit.criteria.search(rowData, rowIdx)) {
2882
                        return true;
2883
                    }
2884
                }
2885
                else if (crit.criteria instanceof Group && crit.criteria.checkFilled()) {
2886
                    filledfound = true;
2887
                    if (crit.criteria.search(rowData, rowIdx)) {
2888
                        return true;
2889
                    }
2890
                }
2891
            }
2892
            // If we get here we need to return the inverse of filledfound,
2893
            //  as if any have been found and we are here then none have passed
2894
            return !filledfound;
2895
        };
2896
        /**
2897
         * Removes a criteria from the group
2898
         *
2899
         * @param criteria The criteria instance to be removed
2900
         */
2901
        Group.prototype._removeCriteria = function (criteria, group) {
2902
            if (group === void 0) { group = false; }
2903
            // If removing a criteria and there is only then then just destroy the group
2904
            if (this.s.criteria.length <= 1 && this.s.isChild) {
2905
                this.destroy();
2906
            }
2907
            else {
2908
                // Otherwise splice the given criteria out and redo the indexes
2909
                var last = void 0;
2910
                for (var i = 0; i < this.s.criteria.length; i++) {
2911
                    if (this.s.criteria[i].index === criteria.s.index &&
2912
                        (!group || this.s.criteria[i].criteria instanceof Group)) {
2913
                        last = i;
2914
                    }
2915
                }
2916
                // We want to remove the last element with the desired index, as its replacement will be inserted before it
2917
                if (last !== undefined) {
2918
                    this.s.criteria.splice(last, 1);
2919
                }
2920
                for (var i = 0; i < this.s.criteria.length; i++) {
2921
                    this.s.criteria[i].index = i;
2922
                    this.s.criteria[i].criteria.s.index = i;
2923
                }
2924
            }
2925
        };
2926
        /**
2927
         * Sets the listeners in group for a criteria
2928
         *
2929
         * @param criteria The criteria for the listeners to be set on
2930
         */
2931
        Group.prototype._setCriteriaListeners = function (criteria) {
2932
            var _this = this;
2933
            criteria.dom["delete"]
2934
                .unbind('click')
2935
                .on('click.dtsb', function () {
2936
                _this._removeCriteria(criteria);
2937
                criteria.dom.container.remove();
2938
                for (var _i = 0, _a = _this.s.criteria; _i < _a.length; _i++) {
2939
                    var crit = _a[_i];
2940
                    if (crit.criteria instanceof Criteria) {
2941
                        crit.criteria.updateArrows(_this.s.criteria.length > 1);
2942
                    }
2943
                }
2944
                criteria.destroy();
2945
                _this.s.dt.draw();
2946
                _this.s.topGroup.trigger('dtsb-redrawContents');
2947
                return false;
2948
            });
2949
            criteria.dom.right
2950
                .unbind('click')
2951
                .on('click.dtsb', function () {
2952
                var idx = criteria.s.index;
2953
                var group = new Group(_this.s.dt, _this.s.opts, _this.s.topGroup, criteria.s.index, true, _this.s.depth + 1);
2954
                // Add the criteria that is to be moved to the new group
2955
                group.addCriteria(criteria);
2956
                // Update the details in the current groups criteria array
2957
                _this.s.criteria[idx].criteria = group;
2958
                _this.s.criteria[idx].logic = 'AND';
2959
                _this.s.topGroup.trigger('dtsb-redrawContents');
2960
                _this._setGroupListeners(group);
2961
                return false;
2962
            });
2963
            criteria.dom.left
2964
                .unbind('click')
2965
                .on('click.dtsb', function () {
2966
                _this.s.toDrop = new Criteria(_this.s.dt, _this.s.opts, _this.s.topGroup, criteria.s.index);
2967
                _this.s.toDrop.s = criteria.s;
2968
                _this.s.toDrop.c = criteria.c;
2969
                _this.s.toDrop.classes = criteria.classes;
2970
                _this.s.toDrop.populate();
2971
                // The dropCriteria event mutates the reference to the index so need to store it
2972
                var index = _this.s.toDrop.s.index;
2973
                _this.dom.container.trigger('dtsb-dropCriteria');
2974
                criteria.s.index = index;
2975
                _this._removeCriteria(criteria);
2976
                // By tracking the top level group we can directly trigger a redraw on it,
2977
                //  bubbling is also possible, but that is slow with deep levelled groups
2978
                _this.s.topGroup.trigger('dtsb-redrawContents');
2979
                _this.s.dt.draw();
2980
                return false;
2981
            });
2982
        };
2983
        /**
2984
         * Set's the listeners for the group clear button
2985
         */
2986
        Group.prototype._setClearListener = function () {
2987
            var _this = this;
2988
            this.dom.clear
2989
                .unbind('click')
2990
                .on('click.dtsb', function () {
2991
                if (!_this.s.isChild) {
2992
                    _this.dom.container.trigger('dtsb-clearContents');
2993
                    return false;
2994
                }
2995
                _this.destroy();
2996
                _this.s.topGroup.trigger('dtsb-redrawContents');
2997
                return false;
2998
            });
2999
        };
3000
        /**
3001
         * Sets listeners for sub groups of this group
3002
         *
3003
         * @param group The sub group that the listeners are to be set on
3004
         */
3005
        Group.prototype._setGroupListeners = function (group) {
3006
            var _this = this;
3007
            // Set listeners for the new group
3008
            group.dom.add
3009
                .unbind('click')
3010
                .on('click.dtsb', function () {
3011
                _this.setupLogic();
3012
                _this.dom.container.trigger('dtsb-add');
3013
                return false;
3014
            });
3015
            group.dom.container
3016
                .unbind('dtsb-add')
3017
                .on('dtsb-add.dtsb', function () {
3018
                _this.setupLogic();
3019
                _this.dom.container.trigger('dtsb-add');
3020
                return false;
3021
            });
3022
            group.dom.container
3023
                .unbind('dtsb-destroy')
3024
                .on('dtsb-destroy.dtsb', function () {
3025
                _this._removeCriteria(group, true);
3026
                group.dom.container.remove();
3027
                _this.setupLogic();
3028
                return false;
3029
            });
3030
            group.dom.container
3031
                .unbind('dtsb-dropCriteria')
3032
                .on('dtsb-dropCriteria.dtsb', function () {
3033
                var toDrop = group.s.toDrop;
3034
                toDrop.s.index = group.s.index;
3035
                toDrop.updateArrows(_this.s.criteria.length > 1, false);
3036
                _this.addCriteria(toDrop, false);
3037
                return false;
3038
            });
3039
            group.setListeners();
3040
        };
3041
        /**
3042
         * Sets up the Group instance, setting listeners and appending elements
3043
         */
3044
        Group.prototype._setup = function () {
3045
            this.setListeners();
3046
            this.dom.add.html(this.s.dt.i18n('searchBuilder.add', this.c.i18n.add));
3047
            this.dom.logic.children().first().html(this.c.logic === 'OR'
3048
                ? this.s.dt.i18n('searchBuilder.logicOr', this.c.i18n.logicOr)
3049
                : this.s.dt.i18n('searchBuilder.logicAnd', this.c.i18n.logicAnd));
3050
            this.s.logic = this.c.logic === 'OR' ? 'OR' : 'AND';
3051
            if (this.c.greyscale) {
3052
                this.dom.logic.addClass(this.classes.greyscale);
3053
            }
3054
            this.dom.logicContainer.append(this.dom.logic).append(this.dom.clear);
3055
            // Only append the logic button immediately if this is a sub group,
3056
            //  otherwise it will be prepended later when adding a criteria
3057
            if (this.s.isChild) {
3058
                this.dom.container.append(this.dom.logicContainer);
3059
            }
3060
            this.dom.container.append(this.dom.add);
3061
        };
3062
        /**
3063
         * Sets the listener for the logic button
3064
         */
3065
        Group.prototype._setLogicListener = function () {
3066
            var _this = this;
3067
            this.dom.logic
3068
                .unbind('click')
3069
                .on('click.dtsb', function () {
3070
                _this._toggleLogic();
3071
                _this.s.dt.draw();
3072
                for (var _i = 0, _a = _this.s.criteria; _i < _a.length; _i++) {
3073
                    var crit = _a[_i];
3074
                    crit.criteria.setListeners();
3075
                }
3076
            });
3077
        };
3078
        /**
3079
         * Toggles the logic for the group
3080
         */
3081
        Group.prototype._toggleLogic = function () {
3082
            if (this.s.logic === 'OR') {
3083
                this.s.logic = 'AND';
3084
                this.dom.logic.children().first().html(this.s.dt.i18n('searchBuilder.logicAnd', this.c.i18n.logicAnd));
3085
            }
3086
            else if (this.s.logic === 'AND') {
3087
                this.s.logic = 'OR';
3088
                this.dom.logic.children().first().html(this.s.dt.i18n('searchBuilder.logicOr', this.c.i18n.logicOr));
3089
            }
3090
        };
3091
        Group.version = '1.1.0';
3092
        Group.classes = {
3093
            add: 'dtsb-add',
3094
            button: 'dtsb-button',
3095
            clearGroup: 'dtsb-clearGroup',
3096
            greyscale: 'dtsb-greyscale',
3097
            group: 'dtsb-group',
3098
            inputButton: 'dtsb-iptbtn',
3099
            logic: 'dtsb-logic',
3100
            logicContainer: 'dtsb-logicContainer'
3101
        };
3102
        Group.defaults = {
3103
            columns: true,
3104
            conditions: {
3105
                'date': Criteria.dateConditions,
3106
                'html': Criteria.stringConditions,
3107
                'html-num': Criteria.numConditions,
3108
                'html-num-fmt': Criteria.numFmtConditions,
3109
                'luxon': Criteria.luxonDateConditions,
3110
                'moment': Criteria.momentDateConditions,
3111
                'num': Criteria.numConditions,
3112
                'num-fmt': Criteria.numFmtConditions,
3113
                'string': Criteria.stringConditions
3114
            },
3115
            depthLimit: false,
3116
            enterSearch: false,
3117
            filterChanged: undefined,
3118
            greyscale: false,
3119
            i18n: {
3120
                add: 'Add Condition',
3121
                button: {
3122
                    0: 'Search Builder',
3123
                    _: 'Search Builder (%d)'
3124
                },
3125
                clearAll: 'Clear All',
3126
                condition: 'Condition',
3127
                data: 'Data',
3128
                "delete": '&times',
3129
                deleteTitle: 'Delete filtering rule',
3130
                left: '<',
3131
                leftTitle: 'Outdent criteria',
3132
                logicAnd: 'And',
3133
                logicOr: 'Or',
3134
                right: '>',
3135
                rightTitle: 'Indent criteria',
3136
                title: {
3137
                    0: 'Custom Search Builder',
3138
                    _: 'Custom Search Builder (%d)'
3139
                },
3140
                value: 'Value',
3141
                valueJoiner: 'and'
3142
            },
3143
            logic: 'AND',
3144
            orthogonal: {
3145
                display: 'display',
3146
                search: 'filter'
3147
            },
3148
            preDefined: false
3149
        };
3150
        return Group;
3151
    }());
3152

3153
    var $;
3154
    var dataTable;
3155
    /**
3156
     * Sets the value of jQuery for use in the file
3157
     *
3158
     * @param jq the instance of jQuery to be set
3159
     */
3160
    function setJQuery(jq) {
3161
        $ = jq;
3162
        dataTable = jq.fn.DataTable;
3163
    }
3164
    /**
3165
     * SearchBuilder class for DataTables.
3166
     * Allows for complex search queries to be constructed and implemented on a DataTable
3167
     */
3168
    var SearchBuilder = /** @class */ (function () {
3169
        function SearchBuilder(builderSettings, opts) {
3170
            var _this = this;
3171
            // Check that the required version of DataTables is included
3172
            if (!dataTable || !dataTable.versionCheck || !dataTable.versionCheck('1.10.0')) {
3173
                throw new Error('SearchBuilder requires DataTables 1.10 or newer');
3174
            }
3175
            var table = new dataTable.Api(builderSettings);
3176
            this.classes = $.extend(true, {}, SearchBuilder.classes);
3177
            // Get options from user
3178
            this.c = $.extend(true, {}, SearchBuilder.defaults, opts);
3179
            this.dom = {
3180
                clearAll: $('<button type="button">' + table.i18n('searchBuilder.clearAll', this.c.i18n.clearAll) + '</button>')
3181
                    .addClass(this.classes.clearAll)
3182
                    .addClass(this.classes.button)
3183
                    .attr('type', 'button'),
3184
                container: $('<div/>')
3185
                    .addClass(this.classes.container),
3186
                title: $('<div/>')
3187
                    .addClass(this.classes.title),
3188
                titleRow: $('<div/>')
3189
                    .addClass(this.classes.titleRow),
3190
                topGroup: undefined
3191
            };
3192
            this.s = {
3193
                dt: table,
3194
                opts: opts,
3195
                search: undefined,
3196
                topGroup: undefined
3197
            };
3198
            // If searchbuilder is already defined for this table then return
3199
            if (table.settings()[0]._searchBuilder !== undefined) {
3200
                return;
3201
            }
3202
            table.settings()[0]._searchBuilder = this;
3203
            // If using SSP we want to include the previous state in the very first server call
3204
            if (this.s.dt.page.info().serverSide) {
3205
                this.s.dt.on('preXhr.dtsb', function (e, settings, data) {
3206
                    var loadedState = _this.s.dt.state.loaded();
3207
                    if (loadedState && loadedState.searchBuilder) {
3208
                        data.searchBuilder = _this._collapseArray(loadedState.searchBuilder);
3209
                    }
3210
                });
3211
            }
3212
            // Run the remaining setup when the table is initialised
3213
            if (this.s.dt.settings()[0]._bInitComplete) {
3214
                this._setUp();
3215
            }
3216
            else {
3217
                table.one('init.dt', function () {
3218
                    _this._setUp();
3219
                });
3220
            }
3221
            return this;
3222
        }
3223
        /**
3224
         * Gets the details required to rebuild the SearchBuilder as it currently is
3225
         */
3226
        // eslint upset at empty object but that is what it is
3227
        // eslint-disable-next-line @typescript-eslint/ban-types
3228
        SearchBuilder.prototype.getDetails = function (deFormatDates) {
3229
            if (deFormatDates === void 0) { deFormatDates = false; }
3230
            return this.s.topGroup.getDetails(deFormatDates);
3231
        };
3232
        /**
3233
         * Getter for the node of the container for the searchBuilder
3234
         *
3235
         * @returns JQuery<HTMLElement> the node of the container
3236
         */
3237
        SearchBuilder.prototype.getNode = function () {
3238
            return this.dom.container;
3239
        };
3240
        /**
3241
         * Rebuilds the SearchBuilder to a state that is provided
3242
         *
3243
         * @param details The details required to perform a rebuild
3244
         */
3245
        SearchBuilder.prototype.rebuild = function (details) {
3246
            this.dom.clearAll.click();
3247
            // If there are no details to rebuild then return
3248
            if (details === undefined || details === null) {
3249
                return this;
3250
            }
3251
            this.s.topGroup.s.preventRedraw = true;
3252
            this.s.topGroup.rebuild(details);
3253
            this.s.topGroup.s.preventRedraw = false;
3254
            this.s.topGroup.redrawContents();
3255
            this.s.dt.draw(false);
3256
            this.s.topGroup.setListeners();
3257
            return this;
3258
        };
3259
        /**
3260
         * Applies the defaults to preDefined criteria
3261
         *
3262
         * @param preDef the array of criteria to be processed.
3263
         */
3264
        SearchBuilder.prototype._applyPreDefDefaults = function (preDef) {
3265
            var _this = this;
3266
            if (preDef.criteria !== undefined && preDef.logic === undefined) {
3267
                preDef.logic = 'AND';
3268
            }
3269
            var _loop_1 = function (crit) {
3270
                // Apply the defaults to any further criteria
3271
                if (crit.criteria !== undefined) {
3272
                    crit = this_1._applyPreDefDefaults(crit);
3273
                }
3274
                else {
3275
                    this_1.s.dt.columns().every(function (index) {
3276
                        if (_this.s.dt.settings()[0].aoColumns[index].sTitle === crit.data) {
3277
                            crit.dataIdx = index;
3278
                        }
3279
                    });
3280
                }
3281
            };
3282
            var this_1 = this;
3283
            for (var _i = 0, _a = preDef.criteria; _i < _a.length; _i++) {
3284
                var crit = _a[_i];
3285
                _loop_1(crit);
3286
            }
3287
            return preDef;
3288
        };
3289
        /**
3290
         * Set's up the SearchBuilder
3291
         */
3292
        SearchBuilder.prototype._setUp = function (loadState) {
3293
            var _this = this;
3294
            if (loadState === void 0) { loadState = true; }
3295
            // Register an Api method for getting the column type
3296
            $.fn.DataTable.Api.registerPlural('columns().type()', 'column().type()', function () {
3297
                return this.iterator('column', function (settings, column) {
3298
                    return settings.aoColumns[column].sType;
3299
                }, 1);
3300
            });
3301
            // Check that DateTime is included, If not need to check if it could be used
3302
            // eslint-disable-next-line no-extra-parens
3303
            if (!dataTable.DateTime) {
3304
                var types = this.s.dt.columns().type().toArray();
3305
                if (types === undefined || types.includes(undefined) || types.includes(null)) {
3306
                    types = [];
3307
                    for (var _i = 0, _a = this.s.dt.settings()[0].aoColumns; _i < _a.length; _i++) {
3308
                        var colInit = _a[_i];
3309
                        types.push(colInit.searchBuilderType !== undefined ? colInit.searchBuilderType : colInit.sType);
3310
                    }
3311
                }
3312
                var columnIdxs = this.s.dt.columns().toArray();
3313
                // If the types are not yet set then draw to see if they can be retrieved then
3314
                if (types === undefined || types.includes(undefined) || types.includes(null)) {
3315
                    $.fn.dataTable.ext.oApi._fnColumnTypes(this.s.dt.settings()[0]);
3316
                    types = this.s.dt.columns().type().toArray();
3317
                }
3318
                for (var i = 0; i < columnIdxs[0].length; i++) {
3319
                    var column = columnIdxs[0][i];
3320
                    var type = types[column];
3321
                    if (
3322
                    // Check if this column can be filtered
3323
                    (this.c.columns === true ||
3324
                        Array.isArray(this.c.columns) &&
3325
                            this.c.columns.includes(i)) &&
3326
                        // Check if the type is one of the restricted types
3327
                        (type.includes('date') ||
3328
                            type.includes('moment') ||
3329
                            type.includes('luxon'))) {
3330
                        alert('SearchBuilder Requires DateTime when used with dates.');
3331
                        throw new Error('SearchBuilder requires DateTime');
3332
                    }
3333
                }
3334
            }
3335
            this.s.topGroup = new Group(this.s.dt, this.c, undefined);
3336
            this._setClearListener();
3337
            this.s.dt.on('stateSaveParams.dtsb', function (e, settings, data) {
3338
                data.searchBuilder = _this.getDetails();
3339
                data.page = _this.s.dt.page();
3340
            });
3341
            this.s.dt.on('stateLoadParams.dtsb', function (e, settings, data) {
3342
                _this.rebuild(data.searchBuilder);
3343
            });
3344
            this._build();
3345
            this.s.dt.on('preXhr.dtsb', function (e, settings, data) {
3346
                if (_this.s.dt.page.info().serverSide) {
3347
                    data.searchBuilder = _this._collapseArray(_this.getDetails(true));
3348
                }
3349
            });
3350
            this.s.dt.on('column-reorder', function () {
3351
                _this.rebuild(_this.getDetails());
3352
            });
3353
            if (loadState) {
3354
                var loadedState = this.s.dt.state.loaded();
3355
                // If the loaded State is not null rebuild based on it for statesave
3356
                if (loadedState !== null && loadedState.searchBuilder !== undefined) {
3357
                    this.s.topGroup.rebuild(loadedState.searchBuilder);
3358
                    this.s.topGroup.dom.container.trigger('dtsb-redrawContents');
3359
                    // If using SSP we want to restrict the amount of server calls that take place
3360
                    //  and this information will already have been processed
3361
                    if (!this.s.dt.page.info().serverSide) {
3362
                        this.s.dt.page(loadedState.page).draw('page');
3363
                    }
3364
                    this.s.topGroup.setListeners();
3365
                }
3366
                // Otherwise load any predefined options
3367
                else if (this.c.preDefined !== false) {
3368
                    this.c.preDefined = this._applyPreDefDefaults(this.c.preDefined);
3369
                    this.rebuild(this.c.preDefined);
3370
                }
3371
            }
3372
            this._setEmptyListener();
3373
            this.s.dt.state.save();
3374
        };
3375
        SearchBuilder.prototype._collapseArray = function (criteria) {
3376
            if (criteria.logic === undefined) {
3377
                if (criteria.value !== undefined) {
3378
                    criteria.value.sort(function (a, b) {
3379
                        if (!isNaN(+a)) {
3380
                            a = +a;
3381
                            b = +b;
3382
                        }
3383
                        if (a < b) {
3384
                            return -1;
3385
                        }
3386
                        else if (b < a) {
3387
                            return 1;
3388
                        }
3389
                        else {
3390
                            return 0;
3391
                        }
3392
                    });
3393
                    criteria.value1 = criteria.value[0];
3394
                    criteria.value2 = criteria.value[1];
3395
                }
3396
            }
3397
            else {
3398
                for (var i = 0; i < criteria.criteria.length; i++) {
3399
                    criteria.criteria[i] = this._collapseArray(criteria.criteria[i]);
3400
                }
3401
            }
3402
            return criteria;
3403
        };
3404
        /**
3405
         * Updates the title of the SearchBuilder
3406
         *
3407
         * @param count the number of filters in the SearchBuilder
3408
         */
3409
        SearchBuilder.prototype._updateTitle = function (count) {
3410
            this.dom.title.html(this.s.dt.i18n('searchBuilder.title', this.c.i18n.title, count));
3411
        };
3412
        /**
3413
         * Builds all of the dom elements together
3414
         */
3415
        SearchBuilder.prototype._build = function () {
3416
            var _this = this;
3417
            // Empty and setup the container
3418
            this.dom.clearAll.remove();
3419
            this.dom.container.empty();
3420
            var count = this.s.topGroup.count();
3421
            this._updateTitle(count);
3422
            this.dom.titleRow.append(this.dom.title);
3423
            this.dom.container.append(this.dom.titleRow);
3424
            this.dom.topGroup = this.s.topGroup.getNode();
3425
            this.dom.container.append(this.dom.topGroup);
3426
            this._setRedrawListener();
3427
            var tableNode = this.s.dt.table(0).node();
3428
            if (!$.fn.dataTable.ext.search.includes(this.s.search)) {
3429
                // Custom search function for SearchBuilder
3430
                this.s.search = function (settings, searchData, dataIndex) {
3431
                    if (settings.nTable !== tableNode) {
3432
                        return true;
3433
                    }
3434
                    return _this.s.topGroup.search(searchData, dataIndex);
3435
                };
3436
                // Add SearchBuilder search function to the dataTables search array
3437
                $.fn.dataTable.ext.search.push(this.s.search);
3438
            }
3439
            this.s.dt.on('destroy.dtsb', function () {
3440
                _this.dom.container.remove();
3441
                _this.dom.clearAll.remove();
3442
                var searchIdx = $.fn.dataTable.ext.search.indexOf(_this.s.search);
3443
                while (searchIdx !== -1) {
3444
                    $.fn.dataTable.ext.search.splice(searchIdx, 1);
3445
                    searchIdx = $.fn.dataTable.ext.search.indexOf(_this.s.search);
3446
                }
3447
                _this.s.dt.off('.dtsb');
3448
                $(_this.s.dt.table().node()).off('.dtsb');
3449
            });
3450
        };
3451
        /**
3452
         * Checks if the clearAll button should be added or not
3453
         */
3454
        SearchBuilder.prototype._checkClear = function () {
3455
            if (this.s.topGroup.s.criteria.length > 0) {
3456
                this.dom.clearAll.insertAfter(this.dom.title);
3457
                this._setClearListener();
3458
            }
3459
            else {
3460
                this.dom.clearAll.remove();
3461
            }
3462
        };
3463
        /**
3464
         * Update the count in the title/button
3465
         *
3466
         * @param count Number of filters applied
3467
         */
3468
        SearchBuilder.prototype._filterChanged = function (count) {
3469
            var fn = this.c.filterChanged;
3470
            if (typeof fn === 'function') {
3471
                fn(count, this.s.dt.i18n('searchBuilder.button', this.c.i18n.button, count));
3472
            }
3473
        };
3474
        /**
3475
         * Set the listener for the clear button
3476
         */
3477
        SearchBuilder.prototype._setClearListener = function () {
3478
            var _this = this;
3479
            this.dom.clearAll.unbind('click');
3480
            this.dom.clearAll.on('click.dtsb', function () {
3481
                _this.s.topGroup = new Group(_this.s.dt, _this.c, undefined);
3482
                _this._build();
3483
                _this.s.dt.draw();
3484
                _this.s.topGroup.setListeners();
3485
                _this.dom.clearAll.remove();
3486
                _this._setEmptyListener();
3487
                _this._filterChanged(0);
3488
                return false;
3489
            });
3490
        };
3491
        /**
3492
         * Set the listener for the Redraw event
3493
         */
3494
        SearchBuilder.prototype._setRedrawListener = function () {
3495
            var _this = this;
3496
            this.s.topGroup.dom.container.unbind('dtsb-redrawContents');
3497
            this.s.topGroup.dom.container.on('dtsb-redrawContents.dtsb', function () {
3498
                _this._checkClear();
3499
                _this.s.topGroup.redrawContents();
3500
                _this.s.topGroup.setupLogic();
3501
                _this._setEmptyListener();
3502
                var count = _this.s.topGroup.count();
3503
                _this._updateTitle(count);
3504
                _this._filterChanged(count);
3505
                // If using SSP we want to restrict the amount of server calls that take place
3506
                //  and this information will already have been processed
3507
                if (!_this.s.dt.page.info().serverSide) {
3508
                    _this.s.dt.draw();
3509
                }
3510
                _this.s.dt.state.save();
3511
            });
3512
            this.s.topGroup.dom.container.unbind('dtsb-redrawLogic');
3513
            this.s.topGroup.dom.container.on('dtsb-redrawLogic.dtsb', function () {
3514
                _this.s.topGroup.redrawLogic();
3515
                var count = _this.s.topGroup.count();
3516
                _this._updateTitle(count);
3517
                _this._filterChanged(count);
3518
            });
3519
            this.s.topGroup.dom.container.unbind('dtsb-add');
3520
            this.s.topGroup.dom.container.on('dtsb-add.dtsb', function () {
3521
                var count = _this.s.topGroup.count();
3522
                _this._updateTitle(count);
3523
                _this._filterChanged(count);
3524
            });
3525
            this.s.dt.on('postEdit.dtsb postCreate.dtsb postRemove.dtsb', function () {
3526
                _this.s.topGroup.redrawContents();
3527
            });
3528
            this.s.topGroup.dom.container.unbind('dtsb-clearContents');
3529
            this.s.topGroup.dom.container.on('dtsb-clearContents.dtsb', function () {
3530
                _this._setUp(false);
3531
                _this._filterChanged(0);
3532
                _this.s.dt.draw();
3533
            });
3534
        };
3535
        /**
3536
         * Sets listeners to check whether clearAll should be added or removed
3537
         */
3538
        SearchBuilder.prototype._setEmptyListener = function () {
3539
            var _this = this;
3540
            this.s.topGroup.dom.add.on('click.dtsb', function () {
3541
                _this._checkClear();
3542
            });
3543
            this.s.topGroup.dom.container.on('dtsb-destroy.dtsb', function () {
3544
                _this.dom.clearAll.remove();
3545
            });
3546
        };
3547
        SearchBuilder.version = '1.3.1';
3548
        SearchBuilder.classes = {
3549
            button: 'dtsb-button',
3550
            clearAll: 'dtsb-clearAll',
3551
            container: 'dtsb-searchBuilder',
3552
            inputButton: 'dtsb-iptbtn',
3553
            title: 'dtsb-title',
3554
            titleRow: 'dtsb-titleRow'
3555
        };
3556
        SearchBuilder.defaults = {
3557
            columns: true,
3558
            conditions: {
3559
                'date': Criteria.dateConditions,
3560
                'html': Criteria.stringConditions,
3561
                'html-num': Criteria.numConditions,
3562
                'html-num-fmt': Criteria.numFmtConditions,
3563
                'luxon': Criteria.luxonDateConditions,
3564
                'moment': Criteria.momentDateConditions,
3565
                'num': Criteria.numConditions,
3566
                'num-fmt': Criteria.numFmtConditions,
3567
                'string': Criteria.stringConditions
3568
            },
3569
            depthLimit: false,
3570
            enterSearch: false,
3571
            filterChanged: undefined,
3572
            greyscale: false,
3573
            i18n: {
3574
                add: 'Add Condition',
3575
                button: {
3576
                    0: 'Search Builder',
3577
                    _: 'Search Builder (%d)'
3578
                },
3579
                clearAll: 'Clear All',
3580
                condition: 'Condition',
3581
                conditions: {
3582
                    array: {
3583
                        contains: 'Contains',
3584
                        empty: 'Empty',
3585
                        equals: 'Equals',
3586
                        not: 'Not',
3587
                        notEmpty: 'Not Empty',
3588
                        without: 'Without'
3589
                    },
3590
                    date: {
3591
                        after: 'After',
3592
                        before: 'Before',
3593
                        between: 'Between',
3594
                        empty: 'Empty',
3595
                        equals: 'Equals',
3596
                        not: 'Not',
3597
                        notBetween: 'Not Between',
3598
                        notEmpty: 'Not Empty'
3599
                    },
3600
                    // eslint-disable-next-line id-blacklist
3601
                    number: {
3602
                        between: 'Between',
3603
                        empty: 'Empty',
3604
                        equals: 'Equals',
3605
                        gt: 'Greater Than',
3606
                        gte: 'Greater Than Equal To',
3607
                        lt: 'Less Than',
3608
                        lte: 'Less Than Equal To',
3609
                        not: 'Not',
3610
                        notBetween: 'Not Between',
3611
                        notEmpty: 'Not Empty'
3612
                    },
3613
                    // eslint-disable-next-line id-blacklist
3614
                    string: {
3615
                        contains: 'Contains',
3616
                        empty: 'Empty',
3617
                        endsWith: 'Ends With',
3618
                        equals: 'Equals',
3619
                        not: 'Not',
3620
                        notContains: 'Does Not Contain',
3621
                        notEmpty: 'Not Empty',
3622
                        notEndsWith: 'Does Not End With',
3623
                        notStartsWith: 'Does Not Start With',
3624
                        startsWith: 'Starts With'
3625
                    }
3626
                },
3627
                data: 'Data',
3628
                "delete": '&times',
3629
                deleteTitle: 'Delete filtering rule',
3630
                left: '<',
3631
                leftTitle: 'Outdent criteria',
3632
                logicAnd: 'And',
3633
                logicOr: 'Or',
3634
                right: '>',
3635
                rightTitle: 'Indent criteria',
3636
                title: {
3637
                    0: 'Custom Search Builder',
3638
                    _: 'Custom Search Builder (%d)'
3639
                },
3640
                value: 'Value',
3641
                valueJoiner: 'and'
3642
            },
3643
            logic: 'AND',
3644
            orthogonal: {
3645
                display: 'display',
3646
                search: 'filter'
3647
            },
3648
            preDefined: false
3649
        };
3650
        return SearchBuilder;
3651
    }());
3652

3653
    /*! SearchBuilder 1.3.1
3654
     * ©SpryMedia Ltd - datatables.net/license/mit
3655
     */
3656
    // DataTables extensions common UMD. Note that this allows for AMD, CommonJS
3657
    // (with window and jQuery being allowed as parameters to the returned
3658
    // function) or just default browser loading.
3659
    (function (factory) {
3660
        if (typeof define === 'function' && define.amd) {
3661
            // AMD
3662
            define(['jquery', 'datatables.net'], function ($) {
3663
                return factory($, window, document);
3664
            });
3665
        }
3666
        else if (typeof exports === 'object') {
3667
            // CommonJS
3668
            module.exports = function (root, $) {
3669
                if (!root) {
3670
                    root = window;
3671
                }
3672
                if (!$ || !$.fn.dataTable) {
3673
                    // eslint-disable-next-line @typescript-eslint/no-var-requires
3674
                    $ = require('datatables.net')(root, $).$;
3675
                }
3676
                return factory($, root, root.document);
3677
            };
3678
        }
3679
        else {
3680
            // Browser - assume jQuery has already been loaded
3681
            // eslint-disable-next-line no-extra-parens
3682
            factory(window.jQuery, window, document);
3683
        }
3684
    }(function ($, window, document) {
3685
        setJQuery($);
3686
        setJQuery$1($);
3687
        setJQuery$2($);
3688
        var dataTable = $.fn.dataTable;
3689
        // eslint-disable-next-line no-extra-parens
3690
        $.fn.dataTable.SearchBuilder = SearchBuilder;
3691
        // eslint-disable-next-line no-extra-parens
3692
        $.fn.DataTable.SearchBuilder = SearchBuilder;
3693
        // eslint-disable-next-line no-extra-parens
3694
        $.fn.dataTable.Group = Group;
3695
        // eslint-disable-next-line no-extra-parens
3696
        $.fn.DataTable.Group = Group;
3697
        // eslint-disable-next-line no-extra-parens
3698
        $.fn.dataTable.Criteria = Criteria;
3699
        // eslint-disable-next-line no-extra-parens
3700
        $.fn.DataTable.Criteria = Criteria;
3701
        // eslint-disable-next-line no-extra-parens
3702
        var apiRegister = $.fn.dataTable.Api.register;
3703
        // Set up object for plugins
3704
        $.fn.dataTable.ext.searchBuilder = {
3705
            conditions: {}
3706
        };
3707
        $.fn.dataTable.ext.buttons.searchBuilder = {
3708
            action: function (e, dt, node, config) {
3709
                this.popover(config._searchBuilder.getNode(), {
3710
                    align: 'container',
3711
                    span: 'container'
3712
                });
3713
                // Need to redraw the contents to calculate the correct positions for the elements
3714
                if (config._searchBuilder.s.topGroup !== undefined) {
3715
                    config._searchBuilder.s.topGroup.dom.container.trigger('dtsb-redrawContents');
3716
                }
3717
                if (config._searchBuilder.s.topGroup.s.criteria.length === 0) {
3718
                    $('.' + $.fn.dataTable.Group.classes.add).click();
3719
                }
3720
            },
3721
            config: {},
3722
            init: function (dt, node, config) {
3723
                var sb = new $.fn.dataTable.SearchBuilder(dt, $.extend({
3724
                    filterChanged: function (count, text) {
3725
                        dt.button(node).text(text);
3726
                    }
3727
                }, config.config));
3728
                dt.button(node).text(config.text || dt.i18n('searchBuilder.button', sb.c.i18n.button, 0));
3729
                config._searchBuilder = sb;
3730
            },
3731
            text: null
3732
        };
3733
        apiRegister('searchBuilder.getDetails()', function (deFormatDates) {
3734
            if (deFormatDates === void 0) { deFormatDates = false; }
3735
            var ctx = this.context[0];
3736
            // If SearchBuilder has not been initialised on this instance then return
3737
            return ctx._searchBuilder ?
3738
                ctx._searchBuilder.getDetails(deFormatDates) :
3739
                null;
3740
        });
3741
        apiRegister('searchBuilder.rebuild()', function (details) {
3742
            var ctx = this.context[0];
3743
            // If SearchBuilder has not been initialised on this instance then return
3744
            if (ctx._searchBuilder === undefined) {
3745
                return null;
3746
            }
3747
            ctx._searchBuilder.rebuild(details);
3748
            return this;
3749
        });
3750
        apiRegister('searchBuilder.container()', function () {
3751
            var ctx = this.context[0];
3752
            // If SearchBuilder has not been initialised on this instance then return
3753
            return ctx._searchBuilder ?
3754
                ctx._searchBuilder.getNode() :
3755
                null;
3756
        });
3757
        /**
3758
         * Init function for SearchBuilder
3759
         *
3760
         * @param settings the settings to be applied
3761
         * @param options the options for SearchBuilder
3762
         * @returns JQUERY<HTMLElement> Returns the node of the SearchBuilder
3763
         */
3764
        function _init(settings, options) {
3765
            var api = new dataTable.Api(settings);
3766
            var opts = options
3767
                ? options
3768
                : api.init().searchBuilder || dataTable.defaults.searchBuilder;
3769
            var searchBuilder = new SearchBuilder(api, opts);
3770
            var node = searchBuilder.getNode();
3771
            return node;
3772
        }
3773
        // Attach a listener to the document which listens for DataTables initialisation
3774
        // events so we can automatically initialise
3775
        $(document).on('preInit.dt.dtsp', function (e, settings) {
3776
            if (e.namespace !== 'dt') {
3777
                return;
3778
            }
3779
            if (settings.oInit.searchBuilder ||
3780
                dataTable.defaults.searchBuilder) {
3781
                if (!settings._searchBuilder) {
3782
                    _init(settings);
3783
                }
3784
            }
3785
        });
3786
        // DataTables `dom` feature option
3787
        dataTable.ext.feature.push({
3788
            cFeature: 'Q',
3789
            fnInit: _init
3790
        });
3791
        // DataTables 2 layout feature
3792
        if (dataTable.ext.features) {
3793
            dataTable.ext.features.register('searchBuilder', _init);
3794
        }
3795
    }));
3796

3797
}());
3798

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.