| 22717 | */ |
| 22718 | var SearchBuilder = /** @class */ (function () { |
| 22719 | function SearchBuilder(builderSettings, opts) { |
| 22720 | var _this = this |
| 22721 | // Check that the required version of DataTables is included |
| 22722 | if (!dataTable$1 || !dataTable$1.versionCheck || !dataTable$1.versionCheck("2")) { |
| 22723 | throw new Error("SearchBuilder requires DataTables 2 or newer") |
| 22724 | } |
| 22725 | var table = new dataTable$1.Api(builderSettings) |
| 22726 | this.classes = $$1.extend(true, {}, SearchBuilder.classes) |
| 22727 | // Get options from user |
| 22728 | this.c = $$1.extend(true, {}, SearchBuilder.defaults, opts) |
| 22729 | this.dom = { |
| 22730 | clearAll: $$1('<button type="button">' + table.i18n("searchBuilder.clearAll", this.c.i18n.clearAll) + "</button>") |
| 22731 | .addClass(this.classes.clearAll) |
| 22732 | .addClass(this.classes.button) |
| 22733 | .attr("type", "button"), |
| 22734 | container: $$1("<div/>").addClass(this.classes.container), |
| 22735 | title: $$1("<div/>").addClass(this.classes.title), |
| 22736 | titleRow: $$1("<div/>").addClass(this.classes.titleRow), |
| 22737 | topGroup: undefined |
| 22738 | } |
| 22739 | this.s = { |
| 22740 | dt: table, |
| 22741 | opts: opts, |
| 22742 | search: undefined, |
| 22743 | serverData: undefined, |
| 22744 | topGroup: undefined |
| 22745 | } |
| 22746 | // If searchbuilder is already defined for this table then return |
| 22747 | if (table.settings()[0]._searchBuilder !== undefined) { |
| 22748 | return |
| 22749 | } |
| 22750 | table.settings()[0]._searchBuilder = this |
| 22751 | // If using SSP we want to include the previous state in the very first server call |
| 22752 | if (this.s.dt.page.info().serverSide) { |
| 22753 | this.s.dt.on("preXhr.dtsb", function (e, settings, data) { |
| 22754 | var loadedState = _this.s.dt.state.loaded() |
| 22755 | if (loadedState && loadedState.searchBuilder) { |
| 22756 | data.searchBuilder = _this._collapseArray(loadedState.searchBuilder) |
| 22757 | } |
| 22758 | }) |
| 22759 | this.s.dt.on("xhr.dtsb", function (e, settings, json) { |
| 22760 | if (json && json.searchBuilder && json.searchBuilder.options) { |
| 22761 | _this.s.serverData = json.searchBuilder.options |
| 22762 | } |
| 22763 | }) |
| 22764 | } |
| 22765 | // Run the remaining setup when the table is initialised |
| 22766 | if (this.s.dt.settings()[0]._bInitComplete) { |
| 22767 | this._setUp() |
| 22768 | } else { |
| 22769 | table.one("init.dt", function () { |
| 22770 | _this._setUp() |
| 22771 | }) |
| 22772 | } |
| 22773 | return this |
| 22774 | } |
| 22775 | /** |
| 22776 | * Gets the details required to rebuild the SearchBuilder as it currently is |