all files / actions/ filter.js

97.49% Statements 233/239
89.38% Branches 143/160
96.88% Functions 31/32
97.49% Lines 233/239
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   419× 419× 419× 419× 419× 419×   27959×   419× 419× 3457× 3457×       1397×       16×   419× 419× 419× 419×     1397× 1397× 1397× 1396×   1397× 1000× 1000×     1396× 1396× 1396×   979×   417×   13×   404× 404×   1396×       419×   979× 979× 979×   979× 979×                 979×   13× 13× 13×                 13×   404× 404× 404× 404× 404×                             404×         46× 46× 46×               30× 22×         30× 22× 20×       22× 22× 22× 22× 22× 22× 22×       17×         13×   12× 12×                                                 22× 22× 22×   22× 22×             16× 16× 14×         22× 20×   22×     419× 407×   12× 12× 12× 12×   419× 419×        
define(["require", "exports", "@syncfusion/ej2-treegrid", "@syncfusion/ej2-grids", "@syncfusion/ej2-grids", "@syncfusion/ej2-base", "@syncfusion/ej2-inputs", "@syncfusion/ej2-calendars"], function (require, exports, ej2_treegrid_1, ej2_grids_1, ej2_grids_2, ej2_base_1, ej2_inputs_1, ej2_calendars_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Filter = (function () {
        function Filter(gantt) {
            this.parent = gantt;
            ej2_treegrid_1.TreeGrid.Inject(ej2_treegrid_1.Filter);
            this.parent.treeGrid.allowFiltering = this.parent.allowFiltering;
            this.updateCustomFilters();
            this.parent.treeGrid.filterSettings = ej2_grids_2.getActualProperties(this.parent.filterSettings);
            this.addEventListener();
        }
        Filter.prototype.getModuleName = function () {
            return 'filter';
        };
        Filter.prototype.updateCustomFilters = function () {
            var settings = this.parent.taskFields;
            for (var i = 0; i < this.parent.ganttColumns.length; i++) {
                var column = this.parent.ganttColumns[i];
                if (((column.editType === 'datepickeredit' || column.editType === 'datetimepickeredit') &&
                    (column.field === settings.startDate || column.field === settings.endDate
                        || column.field === settings.baselineStartDate || column.field === settings.baselineEndDate)) ||
                    (column.field === settings.duration && column.editType === 'stringedit')) {
                    this.initiateFiltering(this.parent.ganttColumns[i]);
                }
            }
        };
        Filter.prototype.updateModel = function () {
            this.parent.filterSettings = this.parent.treeGrid.filterSettings;
        };
        Filter.prototype.addEventListener = function () {
            this.parent.on('updateModel', this.updateModel, this);
            this.parent.on('actionBegin', this.actionBegin, this);
            this.parent.on('actionComplete', this.actionComplete, this);
            this.parent.on('columnMenuOpen', this.columnMenuOpen, this);
        };
        Filter.prototype.wireEvents = function (a) {
            ej2_base_1.EventHandler.add(document.getElementById(a), 'click', this.mouseClickHandler, this);
        };
        Filter.prototype.initiateFiltering = function (column) {
            var treeColumn = this.parent.getColumnByField(column.field, this.parent.treeGridModule.treeGridColumns);
            column.allowFiltering = column.allowFiltering === false ? false : true;
            if (column.allowFiltering && (this.parent.filterSettings.type === 'Menu' || this.parent.filterSettings.type === 'Excel') && !column.filter) {
                column.filter = { ui: this.getCustomFilterUi(column) };
            }
            if (treeColumn) {
                treeColumn.allowFiltering = column.allowFiltering;
                treeColumn.filter = column.allowFiltering ? column.filter : {};
            }
        };
        Filter.prototype.getCustomFilterUi = function (column) {
            var settings = this.parent.taskFields;
            var filterUI = {};
            if (column.editType === 'datepickeredit' && (column.field === settings.startDate || column.field === settings.endDate
                || column.field === settings.baselineStartDate || column.field === settings.baselineEndDate)) {
                filterUI = this.getDatePickerFilter(column.field);
            }
            else if (column.editType === 'datetimepickeredit' && (column.field === settings.startDate || column.field === settings.endDate
                || column.field === settings.baselineStartDate || column.field === settings.baselineEndDate)) {
                filterUI = this.getDateTimePickerFilter();
            }
            else Eif (column.field === settings.duration && column.editType === 'stringedit') {
                filterUI = this.getDurationFilter();
            }
            return filterUI;
        };
        Filter.prototype.mouseClickHandler = function (e) {
            Eif (ej2_base_1.closest(e.target, '.e-excelfilter')) {
                this.parent.treeGrid.grid.notify('click', e);
            }
        };
        Filter.prototype.unWireEvents = function () {
            ej2_base_1.EventHandler.remove(this.parent.element, 'click', this.mouseClickHandler);
        };
        Filter.prototype.getDatePickerFilter = function (columnName) {
            var _this = this;
            var parent = this.parent;
            var timeValue = (columnName === parent.taskFields.startDate) || (columnName === parent.taskFields.baselineStartDate)
                ? parent.defaultStartTime : parent.defaultEndTime;
            var dropDateInstance;
            var filterDateUI = {
                create: function (args) {
                    var format = ej2_grids_2.getCustomDateFormat(args.column.format, args.column.type);
                    var flValInput = ej2_base_1.createElement('input', { className: 'flm-input' });
                    args.target.appendChild(flValInput);
                    dropDateInstance = new ej2_calendars_1.DatePicker({ placeholder: _this.parent.localeObj.getConstant('enterValue'), format: format });
                    dropDateInstance.enableRtl = _this.parent.enableRtl;
                    dropDateInstance.appendTo(flValInput);
                },
                write: function (args) {
                    dropDateInstance.value = args.filteredValue;
                },
                read: function (args) {
                    Eif (dropDateInstance.value) {
                        dropDateInstance.value.setSeconds(timeValue);
                    }
                    args.fltrObj.filterByColumn(args.column.field, args.operator, dropDateInstance.value);
                }
            };
            return filterDateUI;
        };
        Filter.prototype.getDateTimePickerFilter = function () {
            var _this = this;
            var dropInstance;
            var filterDateTimeUI = {
                create: function (args) {
                    var format = ej2_grids_2.getCustomDateFormat(args.column.format, args.column.type);
                    var flValInput = ej2_base_1.createElement('input', { className: 'flm-input' });
                    args.target.appendChild(flValInput);
                    dropInstance = new ej2_calendars_1.DateTimePicker({ placeholder: _this.parent.localeObj.getConstant('enterValue'), format: format });
                    dropInstance.enableRtl = _this.parent.enableRtl;
                    dropInstance.appendTo(flValInput);
                },
                write: function (args) {
                    dropInstance.value = args.filteredValue;
                },
                read: function (args) {
                    args.fltrObj.filterByColumn(args.column.field, args.operator, dropInstance.value);
                }
            };
            return filterDateTimeUI;
        };
        Filter.prototype.getDurationFilter = function () {
            var _this = this;
            var parent = this.parent;
            var textBoxInstance;
            var textValue = '';
            var filterDurationUI = {
                create: function (args) {
                    var flValInput = ej2_base_1.createElement('input', { className: 'e-input' });
                    flValInput.setAttribute('placeholder', _this.parent.localeObj.getConstant('enterValue'));
                    args.target.appendChild(flValInput);
                    textBoxInstance = new ej2_inputs_1.TextBox();
                    textBoxInstance.enableRtl = _this.parent.enableRtl;
                    textBoxInstance.appendTo(flValInput);
                },
                write: function (args) {
                    textBoxInstance.value = args.filteredValue ? textValue : '';
                },
                read: function (args) {
                    var durationObj = _this.parent.dataOperation.getDurationValue(textBoxInstance.value);
                    var intVal = ej2_base_1.getValue('duration', durationObj);
                    var unit = ej2_base_1.getValue('durationUnit', durationObj);
                    if (intVal >= 0) {
                        var dayVal = void 0;
                        if (unit === 'minute') {
                            dayVal = (intVal * 60) / parent.secondsPerDay;
                        }
                        else if (unit === 'hour') {
                            dayVal = (intVal * 60 * 60) / parent.secondsPerDay;
                        }
                        else {
                            dayVal = intVal;
                            unit = 'day';
                        }
                        args.fltrObj.filterByColumn(args.column.field, args.operator, dayVal);
                        textValue = _this.parent.dataOperation.getDurationString(intVal, unit);
                    }
                    else {
                        args.fltrObj.filterByColumn(args.column.field, args.operator, null);
                        textValue = null;
                    }
                }
            };
            return filterDurationUI;
        };
        Filter.prototype.columnMenuOpen = function (args) {
            if (this.filterMenuElement && document.body.contains(this.filterMenuElement)) {
                ej2_base_1.remove(this.filterMenuElement);
            }
            this.filterMenuElement = null;
        };
        Filter.prototype.actionBegin = function (args) {
        };
        Filter.prototype.closeFilterOnContextClick = function (element) {
            var datePickerElement = document.querySelector('body > div.e-datepicker');
            var dateTimePickerElement = document.querySelector('body > div.e-datetimepicker');
            if (this.filterMenuElement && document.body.contains(this.filterMenuElement)) {
                var ganttElement = ej2_base_1.closest(element, '#' + this.parent.element.id)
                    || element.querySelector('#' + this.parent.element.id);
                if ((!(this.filterMenuElement.contains(element)) && !ej2_base_1.isNullOrUndefined(ganttElement)) ||
                    (!(this.filterMenuElement.contains(element)) && (ej2_base_1.isNullOrUndefined(datePickerElement)) &&
                        (ej2_base_1.isNullOrUndefined(dateTimePickerElement)) && ((element.nodeName === 'DIV') || (element.nodeName === 'HTML') ||
                        (element.nodeName === 'SPAN') || (element.nodeName === 'BUTTON'))) && !element.classList.contains('e-dropdownbase')) {
                    ej2_base_1.remove(this.filterMenuElement);
                    this.parent.treeGrid.grid.notify('filter-menu-close', { isOpen: false });
                    this.filterMenuElement = null;
                }
            }
        };
        Filter.prototype.actionComplete = function (args) {
            if (!ej2_base_1.isNullOrUndefined(args['filterModel'])) {
                if (!ej2_base_1.isNullOrUndefined(args['filterModel']['dialogObj'])) {
                    Eif (!ej2_base_1.isNullOrUndefined(args['filterModel']['dialogObj']['element'])) {
                        Eif (this.parent.filterSettings.type === 'Excel') {
                            this.wireEvents(args['filterModel']['dialogObj']['element'].id);
                        }
                    }
                }
            }
            if (args.requestType === ej2_grids_1.filterAfterOpen) {
                if (this.parent.treeGrid.filterSettings.type === 'Menu') {
                    this.filterMenuElement = ej2_base_1.getValue('filterModel.dlgObj.element', args);
                }
                else {
                    this.filterMenuElement = ej2_base_1.getValue('filterModel.dialogObj.element', args);
                }
                this.updateFilterMenuPosition(this.filterMenuElement, args);
                var taskID = this.parent.taskFields.id;
                var predecessor = this.parent.taskFields.dependency;
                var resource = this.parent.taskFields.resourceInfo;
                var filterObj = this.parent.treeGrid.grid.filterModule;
                var filterValues = ej2_base_1.getValue('values', filterObj);
                if ((args.columnName === predecessor && ej2_base_1.isNullOrUndefined(ej2_base_1.getValue(predecessor, filterValues)))
                    || (args.columnName === resource && ej2_base_1.isNullOrUndefined(ej2_base_1.getValue(resource, filterValues)))) {
                    var element = this.filterMenuElement.querySelector('.e-dropdownlist');
                    var instanceObj = void 0;
                    Eif (!ej2_base_1.isNullOrUndefined(element)) {
                        instanceObj = ej2_base_1.getValue('ej2_instances[0]', element);
                        instanceObj.index = 2;
                        instanceObj.dataBind();
                    }
                }
                else if (args.columnName === taskID && ej2_base_1.isNullOrUndefined(ej2_base_1.getValue(taskID, filterValues)) && this.parent.treeGrid.filterSettings.type === 'Menu') {
                    var element = this.filterMenuElement.querySelector('.e-flmenu-input');
                    var instanceObj = ej2_base_1.getValue('ej2_instances[0]', element);
                    Eif (!ej2_base_1.isNullOrUndefined(instanceObj) && ej2_base_1.isNullOrUndefined(this.parent.columnByField[args.columnName].format)) {
                        instanceObj.format = 'n';
                    }
                }
            }
        };
        Filter.prototype.setPosition = function (li, ul) {
            var gridPos = this.parent.element.getBoundingClientRect();
            var gridPosTop = gridPos.top;
            var gridPosLeft = gridPos.left;
            var parentNode;
            var parentNodeTop;
            var parentNodeLeft;
            var paddingTop;
            var paddingLeft;
            var marginTop;
            var isValid = true;
            var marginLeft;
            var isNonBodyTag = false;
            if (!ej2_base_1.isNullOrUndefined(this.parent.element.parentNode) && this.parent.element.parentNode['tagName'] !== 'BODY') {
                isNonBodyTag = true;
                parentNode = this.parent.element.parentNode;
                parentNodeTop = parentNode.getBoundingClientRect().top;
                marginTop = parentNode.style.marginTop;
                while (isValid) {
                    if (Math.abs(gridPosTop) > Math.abs(parentNodeTop)) {
                        paddingTop = gridPosTop - parentNodeTop;
                        break;
                    }
                    Eif (!ej2_base_1.isNullOrUndefined(this.parent.element.parentNode)) {
                        if (parentNode.parentNode instanceof HTMLDocument) {
                            break;
                        }
                        parentNode = parentNode.parentNode;
                        if (parentNode.parentNode && parentNode.parentNode.style) {
                            marginTop = parentNode.parentNode.style.marginTop;
                        }
                    }
                    parentNodeTop = parentNode.getBoundingClientRect().top;
                }
                parentNodeLeft = parentNode.getBoundingClientRect().left;
                marginLeft = parentNode.style.marginLeft;
                while (isValid) {
                    if (Math.abs(gridPosLeft) > Math.abs(parentNodeLeft)) {
                        paddingLeft = gridPosLeft - parentNodeLeft;
                        break;
                    }
                    Eif (!ej2_base_1.isNullOrUndefined(this.parent.element.parentNode)) {
                        Iif (parentNode.parentNode instanceof HTMLDocument) {
                            break;
                        }
                        parentNode = parentNode.parentNode;
                        marginLeft = parentNode.style.marginLeft;
                    }
                    parentNodeLeft = parentNode.getBoundingClientRect().left;
                }
            }
            var liPos = li.getBoundingClientRect();
            var left = liPos.right + window.scrollX;
            var top = isNonBodyTag ? liPos.top - gridPosTop : liPos.top + window.scrollY;
            Iif (gridPos.right < (left + ul.offsetWidth)) {
                if ((liPos.left - ul.offsetWidth) > gridPos.left) {
                    left = (liPos.left - ul.offsetWidth);
                }
                else {
                    left -= (left + ul.offsetWidth) - gridPos.right;
                }
            }
            else {
                if ((!ej2_base_1.isNullOrUndefined(paddingTop) || !ej2_base_1.isNullOrUndefined(paddingLeft)) && isNonBodyTag) {
                    left = Math.abs(liPos.right - gridPos.left);
                    top = Math.abs(liPos.top - gridPos.top);
                }
            }
            if (!ej2_base_1.isNullOrUndefined(paddingTop) && !ej2_base_1.isNullOrUndefined(paddingLeft)) {
                ul.style.top = typeof (parseInt(marginTop, 10)) === 'string' ? (top + paddingTop + parseInt(marginTop, 10)) + 'px' : (top + paddingTop) + 'px';
                ul.style.left = typeof (parseInt(marginLeft, 10)) === 'string' ? (left + paddingLeft + parseInt(marginLeft, 10) + 8) + 'px' : (left + paddingLeft) + 'px';
            }
            else {
                ul.style.top = top + 'px';
                ul.style.left = left + 'px';
            }
        };
        Filter.prototype.updateFilterMenuPosition = function (element, args) {
            ej2_base_1.addClass([element], 'e-gantt');
            Eif (!this.parent.enableAdaptiveUI) {
                document.querySelector('#' + this.parent.controlId).appendChild(element);
            }
            var targetElement;
            if (this.parent.showColumnMenu) {
                targetElement = document.querySelector('#treeGrid' + this.parent.controlId + '_gridcontrol_colmenu_Filter');
                element.style.zIndex = targetElement.parentElement.style.zIndex;
                Eif (this.parent.treeGrid.filterSettings.type === 'Menu') {
                    this.setPosition(targetElement, ej2_base_1.getValue('filterModel.dlgObj.element', args));
                }
                else {
                    this.setPosition(targetElement, ej2_base_1.getValue('filterModel.dialogObj.element', args));
                }
            }
            else {
                targetElement = this.parent.treeGrid.grid.getColumnHeaderByField(args.columnName).querySelector('.e-filtermenudiv');
                if (this.parent.treeGrid.filterSettings.type === 'Menu') {
                    ej2_grids_1.getFilterMenuPostion(targetElement, ej2_base_1.getValue('filterModel.dlgObj', args));
                }
                else {
                    ej2_grids_1.getFilterMenuPostion(targetElement, ej2_base_1.getValue('filterModel.dialogObj', args));
                }
            }
            if (this.parent.treeGrid.filterSettings.type === 'Menu') {
                element.querySelector('.e-valid-input').focus();
            }
            if (this.parent.treeGrid.filterSettings.type === 'Excel') {
                var inputElement = document.querySelector('.e-searchinput');
                inputElement.focus();
            }
        };
        Filter.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off('updateModel', this.updateModel);
            this.parent.off('actionBegin', this.actionBegin);
            this.parent.off('actionComplete', this.actionComplete);
            this.parent.off('columnMenuOpen', this.columnMenuOpen);
        };
        Filter.prototype.destroy = function () {
            this.removeEventListener();
            this.unWireEvents();
        };
        return Filter;
    }());
    exports.Filter = Filter;
});