all files / grid/renderer/ filter-menu-renderer.js

94.62% Statements 211/223
88.08% Branches 133/151
95.65% Functions 22/23
94.62% Lines 211/223
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378   59× 59× 59× 59×     59× 59× 59× 59× 59× 59× 59× 59×       57× 57× 57× 56×     141× 141×   140× 140× 55× 55× 55×   54× 54×         54×         52× 52×     139×   56×       56× 56× 56× 56× 56× 56× 56×     54×   56×                                                   56× 56× 56× 56×   56× 56×     56× 52×       56× 56× 56×   54×   56× 56×   56× 10× 10×   46× 27× 27×     57× 57× 56×   57×     55×   57× 57×   10×   57× 57× 57×             56×           57× 47×   57×       57× 57× 57× 57× 56×     56× 56× 56× 56×   56×   57× 57× 57× 57× 57× 11× 11× 11× 11×   11× 11× 11×   11×   11× 11×         11× 11×   11×       46×                 42×             47× 47× 47× 47× 47× 11× 11×     47×           43×     18× 18× 18× 18× 18×                             15×           14×     18× 18×           68×                                    
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "@syncfusion/ej2-popups", "./filter-menu-operator", "./string-filter-ui", "./number-filter-ui", "./boolean-filter-ui", "./date-filter-ui", "../base/util", "../base/constant", "../common/checkbox-filter-base"], function (require, exports, ej2_base_1, ej2_base_2, ej2_popups_1, filter_menu_operator_1, string_filter_ui_1, number_filter_ui_1, boolean_filter_ui_1, date_filter_ui_1, util_1, events, checkbox_filter_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var FilterMenuRenderer = (function () {
        function FilterMenuRenderer(parent, filterSettings, serviceLocator, customFltrOperators, fltrObj) {
            this.isDialogOpen = false;
            this.maxHeight = '350px';
            this.isMenuCheck = false;
            this.colTypes = {
                'string': string_filter_ui_1.StringFilterUI, 'number': number_filter_ui_1.NumberFilterUI, 'date': date_filter_ui_1.DateFilterUI, 'dateonly': date_filter_ui_1.DateFilterUI, 'boolean': boolean_filter_ui_1.BooleanFilterUI, 'datetime': date_filter_ui_1.DateFilterUI
            };
            this.parent = parent;
            this.filterSettings = filterSettings;
            this.serviceLocator = serviceLocator;
            this.customFilterOperators = customFltrOperators;
            this.filterObj = fltrObj;
            this.flMuiObj = new filter_menu_operator_1.FlMenuOptrUI(this.parent, this.customFilterOperators, this.serviceLocator);
            this.l10n = this.serviceLocator.getService('localization');
            this.menuFilterBase = new checkbox_filter_base_1.CheckBoxFilterBase(parent);
        }
        FilterMenuRenderer.prototype.clearCustomFilter = function (col) {
            this.clearBtnClick(col);
        };
        FilterMenuRenderer.prototype.applyCustomFilter = function (args) {
            this.filterBtnClick(args.col);
        };
        FilterMenuRenderer.prototype.openDialog = function (args) {
            this.options = args;
            this.col = this.parent.getColumnByField(args.field);
            if (ej2_base_1.isNullOrUndefined(this.col.filter) || (ej2_base_1.isNullOrUndefined(this.col.filter.type) || this.col.filter.type === 'Menu')) {
                this.renderDlgContent(args.target, this.col);
            }
        };
        FilterMenuRenderer.prototype.closeDialog = function (target) {
            var _this = this;
            if (!this.dlgObj) {
                return;
            }
            var elem = document.getElementById(this.dlgObj.element.id);
            if (this.dlgObj && !this.dlgObj.isDestroyed && elem) {
                var argument = { cancel: false, column: this.col, target: target, element: elem };
                this.parent.notify(events.filterMenuClose, argument);
                if (argument.cancel) {
                    return;
                }
                this.isDialogOpen = false;
                Iif (this.isMenuCheck) {
                    this.menuFilterBase.unWireEvents();
                    this.parent.off(events.cBoxFltrComplete, this.actionComplete);
                    this.isMenuCheck = false;
                }
                if ((this.parent.isReact || this.parent.isVue) && this.col.filterTemplate && this.col.filterTemplate instanceof Function) {
                    this.parent.clearTemplate(['filterTemplate'], undefined, function () {
                        _this.dlgObj.destroy();
                    });
                }
                else {
                    this.dlgObj.destroy();
                    ej2_base_1.remove(elem);
                }
            }
            this.parent.notify(events.filterDialogClose, {});
        };
        FilterMenuRenderer.prototype.renderDlgContent = function (target, column) {
            var args = {
                requestType: events.filterBeforeOpen,
                columnName: column.field, columnType: column.type
            };
            var filterModel = 'filterModel';
            args["" + filterModel] = this;
            this.parent.trigger(events.actionBegin, args);
            var mainDiv = this.parent.createElement('div', { className: 'e-flmenu-maindiv', id: column.uid + '-flmenu' });
            this.dlgDiv = this.parent.createElement('div', { className: 'e-flmenu', id: column.uid + '-flmdlg' });
            this.dlgDiv.setAttribute('aria-label', this.l10n.getConstant('FilterMenuDialogARIA'));
            if (this.parent.enableAdaptiveUI) {
                var responsiveCnt = document.querySelector('.e-resfilter > .e-dlg-content > .e-mainfilterdiv');
                responsiveCnt.appendChild(this.dlgDiv);
            }
            else {
                this.parent.element.appendChild(this.dlgDiv);
            }
            this.dlgObj = new ej2_popups_1.Dialog({
                showCloseIcon: false,
                closeOnEscape: false,
                locale: this.parent.locale,
                visible: false,
                enableRtl: this.parent.enableRtl,
                created: this.dialogCreated.bind(this, target, column),
                position: this.parent.element.classList.contains('e-device') ? { X: 'center', Y: 'center' } : { X: '', Y: '' },
                target: this.parent.element.classList.contains('e-device') ? document.body : this.parent.element,
                buttons: [{
                        click: this.filterBtnClick.bind(this, column),
                        buttonModel: {
                            content: this.l10n.getConstant('FilterButton'), isPrimary: true,
                            cssClass: this.parent.cssClass ? 'e-flmenu-okbtn' + ' ' + this.parent.cssClass : 'e-flmenu-okbtn'
                        }
                    },
                    {
                        click: this.clearBtnClick.bind(this, column),
                        buttonModel: { content: this.l10n.getConstant('ClearButton'),
                            cssClass: this.parent.cssClass ? 'e-flmenu-cancelbtn' + ' ' + this.parent.cssClass : 'e-flmenu-cancelbtn' }
                    }],
                content: mainDiv,
                width: (!ej2_base_1.isNullOrUndefined(util_1.parentsUntil(target, 'e-bigger'))) || this.parent.element.classList.contains('e-device') ? 260 : 250,
                animationSettings: { effect: 'None' },
                cssClass: this.parent.cssClass ? 'e-filter-popup' + ' ' + this.parent.cssClass : 'e-filter-popup'
            });
            var isStringTemplate = 'isStringTemplate';
            this.dlgObj["" + isStringTemplate] = true;
            this.renderResponsiveDialog();
            this.dlgObj.appendTo(this.dlgDiv);
        };
        FilterMenuRenderer.prototype.renderResponsiveDialog = function () {
            var gObj = this.parent;
            if (gObj.enableAdaptiveUI) {
                this.dlgObj.position = { X: '', Y: '' };
                this.dlgObj.target = document.querySelector('.e-resfilter > .e-dlg-content > .e-mainfilterdiv');
                this.dlgObj.width = '100%';
                this.dlgObj.isModal = false;
                this.dlgObj.buttons = [{}];
            }
        };
        FilterMenuRenderer.prototype.dialogCreated = function (target, column) {
            if (!ej2_base_2.Browser.isDevice && target) {
                util_1.getFilterMenuPostion(target, this.dlgObj);
            }
            else {
                this.dlgObj.position = { X: 'center', Y: 'center' };
            }
            this.currentDialogCreatedColumn = column;
            this.renderFilterUI(target, column);
            if (!(column.isForeignColumn() && !(!ej2_base_1.isNullOrUndefined(column.filter) && !ej2_base_1.isNullOrUndefined(column.filter.ui)
                && !ej2_base_1.isNullOrUndefined(column.filter.ui.create)))) {
                this.afterRenderFilterUI();
            }
            var isReactCompiler = this.parent.isReact && typeof (column.filterTemplate) !== 'string';
            var isReactChild = this.parent.parentDetails && this.parent.parentDetails.parentInstObj &&
                this.parent.parentDetails.parentInstObj.isReact;
            if (!ej2_base_1.isNullOrUndefined(column.filterTemplate) && !(isReactCompiler || isReactChild)) {
                this.dlgDiv.querySelector('.e-flmenu-valuediv').firstElementChild.focus();
                this.dlgDiv.querySelector('.e-flmenu-valuediv').firstElementChild.classList.add('e-input-focus');
            }
            else if (!ej2_base_1.isNullOrUndefined(this.dlgDiv.querySelector('.e-flmenu-input'))) {
                this.dlgDiv.querySelector('.e-flmenu-input').focus();
                this.dlgDiv.querySelector('.e-flmenu-input').parentElement.classList.add('e-input-focus');
            }
        };
        FilterMenuRenderer.prototype.afterRenderFilterUI = function () {
            var column = this.currentDialogCreatedColumn;
            if (column.showColumnMenu) {
                this.parent.notify(events.filterDialogCreated, {});
            }
            if (this.parent.enableAdaptiveUI) {
                this.dlgObj.element.style.left = '0px';
                this.dlgObj.element.style.maxHeight = 'none';
            }
            else {
                this.dlgObj.element.style.maxHeight = this.maxHeight;
            }
            this.dlgObj.show();
            if (this.parent.getContent().firstElementChild.offsetHeight < this.dlgObj.element.offsetHeight &&
                !util_1.parentsUntil(this.parent.element, 'e-gantt-dialog')) {
                util_1.resetDialogAppend(this.parent, this.dlgObj);
            }
            var optrInput = this.dlgObj.element.querySelector('.e-flm_optrdiv').querySelector('input');
            var valInput = this.dlgObj.element.querySelector('.e-flmenu-valuediv').querySelector('input');
            if (optrInput.value === 'Empty' || optrInput.value === 'Not Empty' ||
                optrInput.value === 'Null' || optrInput.value === 'Not Null') {
                Eif (!ej2_base_1.isNullOrUndefined(valInput['ej2_instances'])) {
                    valInput['ej2_instances'][0]['enabled'] = false;
                }
                else {
                    valInput.setAttribute('disabled', 'true');
                }
            }
            else if (!ej2_base_1.isNullOrUndefined(valInput && valInput.getAttribute('disabled'))) {
                Iif (!ej2_base_1.isNullOrUndefined(valInput['ej2_instances'])) {
                    valInput['ej2_instances'][0]['enabled'] = true;
                }
                else {
                    valInput.removeAttribute('disabled');
                }
            }
            if (!column.filterTemplate) {
                this.writeMethod(column, this.dlgObj.element.querySelector('#' + column.uid + '-flmenu'));
            }
            var args = {
                requestType: events.filterAfterOpen,
                columnName: column.field, columnType: column.type
            };
            var filterModel = 'filterModel';
            args["" + filterModel] = this;
            this.isDialogOpen = true;
            if (!this.isMenuCheck) {
                this.parent.trigger(events.actionComplete, args);
            }
        };
        FilterMenuRenderer.prototype.renderFilterUI = function (target, col) {
            var dlgConetntEle = this.dlgObj.element.querySelector('.e-flmenu-maindiv');
            this.parent.log('column_type_missing', { column: col });
            this.renderOperatorUI(dlgConetntEle, target, col);
            this.renderFlValueUI(dlgConetntEle, target, col);
        };
        FilterMenuRenderer.prototype.renderOperatorUI = function (dlgConetntEle, target, column) {
            this.flMuiObj.renderOperatorUI(dlgConetntEle, target, column, this.dlgObj, this.filterObj.menuOperator);
        };
        FilterMenuRenderer.prototype.renderFlValueUI = function (dlgConetntEle, target, column) {
            var valueDiv = this.parent.createElement('div', { className: 'e-flmenu-valuediv' });
            var fObj = this.filterObj;
            dlgConetntEle.appendChild(valueDiv);
            var instanceofFilterUI = new this.colTypes[column.type](this.parent, this.serviceLocator, this.parent.filterSettings);
            if (column.filterTemplate) {
                var fltrData = {};
                var valueInString = 'value';
                fltrData[column.field] = fltrData["" + valueInString] = fObj.values[column.field];
                if (column.foreignKeyValue) {
                    fltrData[column.foreignKeyValue] = fObj.values[column.field];
                    fltrData[column.field] = undefined;
                }
                var col = 'column';
                fltrData["" + col] = column;
                var isReactCompiler = this.parent.isReact && typeof (column.filterTemplate) !== 'string' &&
                    !(column.filterTemplate.prototype && column.filterTemplate.prototype.CSPTemplate);
                var isReactChild = this.parent.parentDetails && this.parent.parentDetails.parentInstObj &&
                    this.parent.parentDetails.parentInstObj.isReact;
                var tempID = this.parent.element.id + column.uid + 'filterTemplate';
                Iif (isReactCompiler || isReactChild) {
                    column.getFilterTemplate()(fltrData, this.parent, 'filterTemplate', tempID, null, null, valueDiv);
                    this.parent.renderTemplates();
                }
                else {
                    var compElement = column.getFilterTemplate()(fltrData, this.parent, 'filterTemplate', tempID, null, null, null, this.parent.root);
                    util_1.appendChildren(valueDiv, compElement);
                }
                if (this.isMenuCheck) {
                    this.menuFilterBase.cBox = this.dlgObj.element.querySelector('.e-checkboxlist.e-fields');
                    this.menuFilterBase.wireEvents();
                    this.parent.on(events.cBoxFltrComplete, this.actionComplete, this);
                    this.menuFilterBase.getAllData();
                }
            }
            else {
                if (!ej2_base_1.isNullOrUndefined(column.filter) && !ej2_base_1.isNullOrUndefined(column.filter.ui)
                    && !ej2_base_1.isNullOrUndefined(column.filter.ui.create)) {
                    var temp = column.filter.ui.create;
                    Iif (typeof temp === 'string') {
                        temp = ej2_base_1.getValue(temp, window);
                    }
                    temp({
                        column: column, target: valueDiv,
                        getOptrInstance: this.flMuiObj, dialogObj: this.dlgObj
                    });
                }
                else {
                    instanceofFilterUI.create({
                        column: column, target: valueDiv,
                        getOptrInstance: this.flMuiObj, localizeText: this.l10n, dialogObj: this.dlgObj
                    });
                }
            }
        };
        FilterMenuRenderer.prototype.writeMethod = function (col, dlgContentEle) {
            var flValue;
            var target = dlgContentEle.querySelector('.e-flmenu-valinput');
            var instanceofFilterUI = new this.colTypes[col.type](this.parent, this.serviceLocator, this.parent.filterSettings);
            var columns = this.filterSettings.columns;
            for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
                var column = columns_1[_i];
                if (col.uid === column.uid) {
                    flValue = column.value;
                }
            }
            if (!ej2_base_1.isNullOrUndefined(col.filter) && !ej2_base_1.isNullOrUndefined(col.filter.ui)
                && !ej2_base_1.isNullOrUndefined(col.filter.ui.write)) {
                var temp = col.filter.ui.write;
                Iif (typeof temp === 'string') {
                    temp = ej2_base_1.getValue(temp, window);
                }
                temp({ column: col, target: target, parent: this.parent, filteredValue: flValue });
            }
            else {
                instanceofFilterUI.write({ column: col, target: target, parent: this.parent, filteredValue: flValue });
            }
        };
        FilterMenuRenderer.prototype.filterBtnClick = function (col) {
            var flValue;
            var targ = this.dlgObj.element.querySelector('.e-flmenu-valuediv input');
            var flOptrValue = this.flMuiObj.getFlOperator();
            var instanceofFilterUI = new this.colTypes[col.type](this.parent, this.serviceLocator, this.parent.filterSettings);
            if (col.filterTemplate) {
                var element = this.dlgDiv.querySelector('.e-flmenu-valuediv');
                var fltrValue = void 0;
                if (element.children[0].value) {
                    fltrValue = element.children[0].value;
                }
                else {
                    Iif (!ej2_base_1.isNullOrUndefined(element.children[0].ej2_instances)) {
                        fltrValue = (this.parent.isAngular ? element.children[0] :
                            element.querySelector('input')).ej2_instances[0].value;
                    }
                    else {
                        var eControl = element.querySelector('.e-control');
                        if (!ej2_base_1.isNullOrUndefined(eControl)) {
                            fltrValue = col.type === 'boolean' ? eControl.checked :
                                !ej2_base_1.isNullOrUndefined(eControl.ej2_instances) ?
                                    eControl.ej2_instances[0].value :
                                    eControl.value;
                        }
                    }
                }
                this.filterObj.filterByColumn(col.field, flOptrValue, fltrValue);
            }
            else {
                if (!ej2_base_1.isNullOrUndefined(col.filter) &&
                    !ej2_base_1.isNullOrUndefined(col.filter.ui) && !ej2_base_1.isNullOrUndefined(col.filter.ui.read)) {
                    var temp = col.filter.ui.read;
                    Iif (typeof temp === 'string') {
                        temp = ej2_base_1.getValue(temp, window);
                    }
                    flValue = temp({ element: targ, column: col, operator: flOptrValue, fltrObj: this.filterObj });
                }
                else {
                    instanceofFilterUI.read(targ, col, flOptrValue, this.filterObj);
                }
            }
            this.closeDialog();
            if (this.parent.showColumnMenu) {
                this.parent.notify(events.afterFilterColumnMenuClose, {});
            }
        };
        FilterMenuRenderer.prototype.closeResponsiveDialog = function () {
            this.closeDialog();
        };
        FilterMenuRenderer.prototype.clearBtnClick = function (column) {
            this.filterObj.removeFilteredColsByField(column.field);
            this.closeDialog();
            if (this.parent.showColumnMenu) {
                this.parent.notify(events.afterFilterColumnMenuClose, {});
            }
        };
        FilterMenuRenderer.prototype.destroy = function () {
            this.closeDialog();
        };
        FilterMenuRenderer.prototype.getFilterUIInfo = function () {
            return { field: this.col.field, operator: this.flMuiObj.getFlOperator() };
        };
        FilterMenuRenderer.prototype.renderCheckBoxMenu = function () {
            this.isMenuCheck = true;
            this.menuFilterBase.updateModel(this.options);
            this.menuFilterBase.getAndSetChkElem(this.options);
            this.dlgObj.buttons = [{
                    click: this.menuFilterBase.btnClick.bind(this.menuFilterBase),
                    buttonModel: {
                        content: this.menuFilterBase.getLocalizedLabel('FilterButton'),
                        cssClass: 'e-primary', isPrimary: true
                    }
                },
                {
                    click: this.menuFilterBase.btnClick.bind(this.menuFilterBase),
                    buttonModel: { cssClass: 'e-flat', content: this.menuFilterBase.getLocalizedLabel('ClearButton') }
                }];
            this.menuFilterBase.dialogObj = this.dlgObj;
            this.menuFilterBase.dlg = this.dlgObj.element;
            this.menuFilterBase.dlg.classList.add('e-menucheckbox');
            this.menuFilterBase.dlg.classList.remove('e-checkboxfilter');
            this.maxHeight = '800px';
            return this.menuFilterBase.sBox.innerHTML;
        };
        FilterMenuRenderer.prototype.actionComplete = function (args) {
            Eif (this.isMenuCheck) {
                this.parent.trigger(events.actionComplete, args);
            }
        };
        return FilterMenuRenderer;
    }());
    exports.FilterMenuRenderer = FilterMenuRenderer;
});