all files / grid/renderer/ responsive-dialog-renderer.js

95.19% Statements 475/499
85.52% Branches 307/359
100% Functions 43/43
95.19% Lines 475/499
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 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732   41× 41× 41× 41× 41× 41×   41×           41× 41× 41×                                       31× 17×   31× 18×     64× 64× 64× 64× 64× 64×   37× 37× 37× 37× 14×   14×     23× 23×                 15× 15× 15× 15× 15× 15×     15× 73×   10×   63× 63× 63× 63× 63× 63× 63× 34× 34× 34× 34× 34× 34× 34×     34× 34× 34×     34× 34×     63×       23× 23×     34× 34× 10×   34×               15× 13×                 13× 13× 13×                             13×                     37×   15× 15×     22× 22× 22×   22×   22×           22× 22× 22× 22×           22× 22× 12× 12×     15× 15× 15×     15× 15×         15× 15× 15×     15× 15×     15× 15× 15×   37×                                 37× 37× 37× 15× 15× 15×     22× 22×     37×   22× 22×     22× 22× 22×         22× 22× 22×   37×   36×                                                       39× 39× 39×   38×   37× 16×   21×   13×     39×   39× 39×   37× 16×   21×   39×   25× 25×   23×   23×   25×   39× 39× 39× 39× 39× 39× 39× 39× 39× 39× 24×       24× 24× 24×     39× 39× 39× 24× 24× 24×       24× 16× 16×       24× 24× 24×               24×   39× 24×   39×                       22×   21× 21× 21×   21×   18× 18× 14× 14×   18× 18×     24× 11× 11×     24× 24×                               43×                
define(["require", "exports", "@syncfusion/ej2-popups", "@syncfusion/ej2-base", "../base/util", "../base/constant", "@syncfusion/ej2-buttons", "../base/enum"], function (require, exports, ej2_popups_1, ej2_base_1, util_1, events, ej2_buttons_1, enum_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ResponsiveDialogRenderer = (function () {
        function ResponsiveDialogRenderer(parent, serviceLocator) {
            this.sortedCols = [];
            this.sortPredicate = [];
            this.isCustomDialog = false;
            this.parent = parent;
            this.serviceLocator = serviceLocator;
            this.addEventListener();
        }
        ResponsiveDialogRenderer.prototype.addEventListener = function () {
            this.evtHandlers = [{ event: events.filterDialogClose, handler: this.closeCustomDialog },
                { event: events.refreshCustomFilterOkBtn, handler: this.refreshCustomFilterOkBtn },
                { event: events.renderResponsiveCmenu, handler: this.renderResponsiveContextMenu },
                { event: events.filterCmenuSelect, handler: this.renderCustomFilterDiv },
                { event: events.customFilterClose, handler: this.customExFilterClose },
                { event: events.refreshCustomFilterClearBtn, handler: this.refreshCustomFilterClearBtn }];
            util_1.addRemoveEventListener(this.parent, this.evtHandlers, true, this);
            this.onActionCompleteFn = this.editComplate.bind(this);
            this.parent.addEventListener(events.actionComplete, this.onActionCompleteFn);
        };
        ResponsiveDialogRenderer.prototype.customExFilterClose = function () {
            this.isCustomDlgRender = false;
        };
        ResponsiveDialogRenderer.prototype.renderCustomFilterDiv = function () {
            var header = this.customResponsiveDlg.element.querySelector('.e-dlg-header-content');
            var title = header.querySelector('.e-dlg-custom-header');
            var closeBtn = header.querySelector('.e-dlg-closeicon-btn');
            this.isCustomDlgRender = true;
            this.parent.filterModule.filterModule.closeDialog();
            this.saveBtn.element.style.display = '';
            this.refreshCustomFilterOkBtn({ disabled: false });
            this.backBtn.element.style.display = 'none';
            closeBtn.style.display = '';
            title.innerHTML = this.parent.localeObj.getConstant('CustomFilter');
            var content = this.customResponsiveDlg.element.querySelector('.e-dlg-content');
            this.customExcelFilterParent = this.parent.createElement('div', { className: 'e-xl-customfilterdiv e-default-filter' });
            content.appendChild(this.customExcelFilterParent);
        };
        ResponsiveDialogRenderer.prototype.renderResponsiveContextMenu = function (args) {
            if (this.action === enum_1.ResponsiveDialogAction.isFilter) {
                var content = this.customResponsiveDlg.element.querySelector('.e-dlg-content');
                var header = this.customResponsiveDlg.element.querySelector('.e-dlg-header-content');
                var closeBtn = header.querySelector('.e-dlg-closeicon-btn');
                var text = header.querySelector('.e-dlg-custom-header');
                if (args.isOpen) {
                    content.firstChild.style.display = 'none';
                    content.appendChild(args.target);
                    closeBtn.style.display = 'none';
                    this.saveBtn.element.style.display = 'none';
                    this.filterClearBtn.element.style.display = 'none';
                    text.innerHTML = args.header;
                    var backBtn = this.parent.createElement('button');
                    var span = this.parent.createElement('span', { className: 'e-btn-icon e-resfilterback e-icons' });
                    backBtn.appendChild(span);
                    this.backBtn = new ej2_buttons_1.Button({
                        cssClass: this.parent.cssClass ? 'e-res-back-btn' + ' ' + this.parent.cssClass : 'e-res-back-btn'
                    });
                    this.backBtn.appendTo(backBtn);
                    text.parentElement.insertBefore(backBtn, text);
                }
                else Iif (this.backBtn && !this.isCustomDlgRender) {
                    content.firstChild.style.display = '';
                    ej2_base_1.remove(this.backBtn.element);
                    closeBtn.style.display = '';
                    this.saveBtn.element.style.display = '';
                    if (this.isFiltered) {
                        this.filterClearBtn.element.style.display = '';
                    }
                    text.innerHTML = this.getHeaderTitle({ action: enum_1.ResponsiveDialogAction.isFilter }, args.col);
                }
            }
        };
        ResponsiveDialogRenderer.prototype.refreshCustomFilterClearBtn = function (args) {
            if (this.filterClearBtn) {
                this.isFiltered = args.isFiltered;
                this.filterClearBtn.element.style.display = args.isFiltered ? '' : 'none';
            }
        };
        ResponsiveDialogRenderer.prototype.refreshCustomFilterOkBtn = function (args) {
            if (this.saveBtn) {
                this.saveBtn.disabled = args.disabled;
            }
            if (this.parent.columnChooserModule && this.parent.columnChooserModule.responsiveDialogRenderer.saveBtn) {
                this.parent.columnChooserModule.responsiveDialogRenderer.saveBtn.disabled = args.disabled;
            }
        };
        ResponsiveDialogRenderer.prototype.columnMenuResponsiveContent = function (str, locale, disabled) {
            var cDiv = this.parent.createElement('div', { className: 'e-responsivecoldiv e-responsive' + str.toLowerCase() + 'div' + (disabled ? ' e-disabled' : '') });
            var span = this.parent.createElement('span', { className: 'e-icons e-res' + str.toLowerCase() + '-icon e-btn-icon' });
            var icon = this.parent.createElement('span', { innerHTML: locale, className: 'e-rescolumn-menu e-res-header-text' });
            cDiv.appendChild(span);
            cDiv.appendChild(icon);
            this.customColumnDiv.appendChild(cDiv);
        };
        ResponsiveDialogRenderer.prototype.renderResponsiveContent = function (col, column) {
            var _this = this;
            var gObj = this.parent;
            var isColumnChooser = this.action === enum_1.ResponsiveDialogAction.isColumnChooser;
            if (col || isColumnChooser) {
                this.filterParent = this.parent.createElement('div', { className: (isColumnChooser ? 'e-maincolumnchooserdiv ' : '') + 'e-mainfilterdiv e-default-filter',
                    id: (isColumnChooser ? 'columchooser' : col.uid) + '-main-filter' });
                return this.filterParent;
            }
            else {
                this.customColumnDiv = gObj.createElement('div', { className: 'columndiv columnmenudiv', styles: 'width: 100%' });
                if (this.parent.showColumnMenu && this.parent.rowRenderingMode === 'Horizontal' && this.action === enum_1.ResponsiveDialogAction.isColMenu) {
                    this.columnMenuResponsiveContent('AutoFitAll', gObj.localeObj.getConstant('AutoFitAll'));
                    this.columnMenuResponsiveContent('AutoFit', gObj.localeObj.getConstant('AutoFit'));
                    Eif (column.allowGrouping && gObj.allowGrouping) {
                        this.columnMenuResponsiveContent('Group', gObj.localeObj.getConstant('Group'), gObj.groupSettings.columns.indexOf(column.field) >= 0);
                        this.columnMenuResponsiveContent('UnGroup', gObj.localeObj.getConstant('Ungroup'), gObj.groupSettings.columns.indexOf(column.field) < 0);
                    }
                    Eif (column.allowSorting && gObj.allowSorting) {
                        var direction = 'None';
                        var sortColumns = this.parent.sortSettings.columns;
                        for (var i = 0; i < sortColumns.length; i++) {
                            Eif (sortColumns[parseInt(i.toString(), 10)].field === column.field) {
                                direction = sortColumns[parseInt(i.toString(), 10)].direction;
                                break;
                            }
                        }
                        this.columnMenuResponsiveContent('ascending', gObj.localeObj.getConstant('SortAscending'), direction === 'Ascending');
                        this.columnMenuResponsiveContent('descending', gObj.localeObj.getConstant('SortDescending'), direction === 'Descending');
                    }
                    Eif (gObj.showColumnChooser) {
                        this.columnMenuResponsiveContent('Column', gObj.localeObj.getConstant('Columnchooser'));
                    }
                    Eif (column.allowFiltering && gObj.allowFiltering) {
                        this.columnMenuResponsiveContent('Filter', gObj.localeObj.getConstant('FilterMenu'));
                    }
                }
                else {
                    var cols = gObj.getColumns();
                    var sortBtnParent = gObj.createElement('div', { className: 'e-ressortbutton-parent' });
                    var filteredCols = [];
                    var isSort = this.action === enum_1.ResponsiveDialogAction.isSort;
                    var isFilter = this.action === enum_1.ResponsiveDialogAction.isFilter;
                    if (isFilter) {
                        for (var i = 0; i < gObj.filterSettings.columns.length; i++) {
                            filteredCols.push(gObj.filterSettings.columns[parseInt(i.toString(), 10)].field);
                        }
                    }
                    for (var i = 0; i < cols.length; i++) {
                        if (!cols[parseInt(i.toString(), 10)].visible || (!cols[parseInt(i.toString(), 10)].allowSorting && isSort)
                            || (!cols[parseInt(i.toString(), 10)].allowFiltering && isFilter)) {
                            continue;
                        }
                        var cDiv = gObj.createElement('div', { className: 'e-responsivecoldiv' });
                        cDiv.setAttribute('data-e-mappingname', cols[parseInt(i.toString(), 10)].field);
                        cDiv.setAttribute('data-e-mappinguid', cols[parseInt(i.toString(), 10)].uid);
                        var span = gObj.createElement('span', { innerHTML: cols[parseInt(i.toString(), 10)].headerText, className: 'e-res-header-text' });
                        cDiv.appendChild(span);
                        this.customColumnDiv.appendChild(cDiv);
                        if (isSort) {
                            var fields = this.getSortedFieldsAndDirections('field');
                            var index = fields.indexOf(cols[parseInt(i.toString(), 10)].field);
                            var button = gObj.createElement('button', { id: gObj.element.id + cols[parseInt(i.toString(), 10)].field + 'sortbutton' });
                            var clone = sortBtnParent.cloneNode();
                            clone.appendChild(button);
                            cDiv.appendChild(clone);
                            var btnObj = new ej2_buttons_1.Button({
                                cssClass: this.parent.cssClass ? 'e-ressortbutton' + ' ' + this.parent.cssClass : 'e-ressortbutton'
                            });
                            btnObj.appendTo(button);
                            var buttonInnerText = void 0;
                            if ((!ej2_base_1.isNullOrUndefined(this.parent.sortSettings.columns[parseInt(index.toString(), 10)]))) {
                                buttonInnerText = (this.parent.sortSettings.columns[parseInt(index.toString(), 10)].direction === 'Ascending') ?
                                    this.parent.localeObj.getConstant('AscendingText') : this.parent.localeObj.getConstant('DescendingText');
                            }
                            button.innerHTML = index > -1 ? buttonInnerText : this.parent.localeObj.getConstant('NoneText');
                            button.onclick = function (e) {
                                _this.sortButtonClickHandler(e.target);
                            };
                        }
                        if (isFilter && filteredCols.indexOf(cols[parseInt(i.toString(), 10)].field) > -1) {
                            var divIcon = gObj.createElement('div', { className: 'e-icons e-res-icon e-filtersetdiv' });
                            var iconSpan = gObj.createElement('span', { className: 'e-icons e-res-icon e-filterset' });
                            iconSpan.setAttribute('colType', cols[parseInt(i.toString(), 10)].type);
                            divIcon.appendChild(iconSpan);
                            cDiv.appendChild(divIcon);
                        }
                    }
                }
                ej2_base_1.EventHandler.add(this.customColumnDiv, ej2_base_1.Browser.isDevice ? 'touchend' : 'click', this.customFilterColumnClickHandler, this);
                return this.customColumnDiv;
            }
        };
        ResponsiveDialogRenderer.prototype.getSortedFieldsAndDirections = function (name) {
            var fields = [];
            for (var i = 0; i < this.parent.sortSettings.columns.length; i++) {
                fields.push(this.parent.sortSettings.columns[parseInt(i.toString(), 10)]["" + name]);
            }
            return fields;
        };
        ResponsiveDialogRenderer.prototype.sortButtonClickHandler = function (target) {
            if (target) {
                var columndiv = util_1.parentsUntil(target, 'e-responsivecoldiv');
                var field = columndiv.getAttribute('data-e-mappingname');
                if (!this.parent.allowMultiSorting) {
                    this.sortPredicate = [];
                    this.sortedCols = [];
                    this.isSortApplied = false;
                    this.resetSortButtons(target);
                }
                var txt = target.textContent;
                var directionTxt = txt === this.parent.localeObj.getConstant('NoneText') ? this.parent.localeObj.getConstant('AscendingText')
                    : txt === this.parent.localeObj.getConstant('AscendingText') ? this.parent.localeObj.getConstant('DescendingText')
                        : this.parent.localeObj.getConstant('NoneText');
                var direction = directionTxt === this.parent.localeObj.getConstant('AscendingText') ? 'Ascending'
                    : directionTxt === this.parent.localeObj.getConstant('DescendingText') ? 'Descending' : 'None';
                target.innerHTML = directionTxt;
                this.setSortedCols(field, direction);
            }
        };
        ResponsiveDialogRenderer.prototype.resetSortButtons = function (target) {
            var buttons = [].slice.call(this.customColumnDiv.getElementsByClassName('e-ressortbutton'));
            for (var i = 0; i < buttons.length; i++) {
                if (buttons[parseInt(i.toString(), 10)] !== target) {
                    buttons[parseInt(i.toString(), 10)].innerHTML = this.parent.localeObj.getConstant('NoneText');
                }
            }
        };
        ResponsiveDialogRenderer.prototype.setSortedCols = function (field, direction) {
            var fields = this.getCurrentSortedFields();
            var index = fields.indexOf(field);
            if (this.parent.allowMultiSorting && index > -1) {
                this.sortedCols.splice(index, 1);
                this.sortPredicate.splice(index, 1);
            }
            this.isSortApplied = true;
            Eif (direction !== 'None') {
                this.sortedCols.push(field);
                this.sortPredicate.push({ field: field, direction: direction });
            }
        };
        ResponsiveDialogRenderer.prototype.getCurrentSortedFields = function () {
            var fields = [];
            for (var i = 0; i < this.sortedCols.length; i++) {
                fields.push(this.sortedCols[parseInt(i.toString(), 10)]);
            }
            return fields;
        };
        ResponsiveDialogRenderer.prototype.customFilterColumnClickHandler = function (e) {
            var gObj = this.parent;
            var target = e.target;
            if (util_1.parentsUntil(target, 'columnmenudiv') && this.action === enum_1.ResponsiveDialogAction.isColMenu && !util_1.parentsUntil(target, 'e-disabled')) {
                var column = this.menuCol ? this.menuCol : this.filteredCol;
                if (util_1.parentsUntil(target, 'e-responsiveautofitalldiv')) {
                    gObj.autoFitColumns([]);
                    this.closeCustomFilter();
                }
                else if (util_1.parentsUntil(target, 'e-responsiveautofitdiv')) {
                    gObj.autoFitColumns(column.field);
                    this.closeCustomFilter();
                }
                else Iif (util_1.parentsUntil(target, 'e-responsivegroupdiv')) {
                    gObj.groupColumn(column.field);
                    this.closeCustomFilter();
                }
                else Iif (util_1.parentsUntil(target, 'e-responsiveungroupdiv')) {
                    gObj.ungroupColumn(column.field);
                    this.closeCustomFilter();
                }
                else if (util_1.parentsUntil(target, 'e-responsiveascendingdiv')) {
                    gObj.sortColumn(column.field, 'Ascending');
                    this.closeCustomFilter();
                }
                else if (util_1.parentsUntil(target, 'e-responsivedescendingdiv')) {
                    gObj.sortColumn(column.field, 'Descending');
                    this.closeCustomFilter();
                }
                else if (util_1.parentsUntil(target, 'e-responsivecolumndiv')) {
                    gObj.notify(events.renderResponsiveChangeAction, { action: 5 });
                    gObj.showResponsiveCustomColumnChooser();
                }
                else Eif (util_1.parentsUntil(target, 'e-responsivefilterdiv')) {
                    gObj.notify(events.renderResponsiveChangeAction, { action: 3 });
                    this.isRowResponsive = true;
                    this.isCustomDialog = false;
                    Eif (gObj.filterModule) {
                        gObj.filterModule.responsiveDialogRenderer.showResponsiveDialog(column);
                    }
                }
                e.preventDefault();
            }
            if (this.action !== enum_1.ResponsiveDialogAction.isFilter) {
                return;
            }
            Eif (gObj.filterSettings.type !== 'FilterBar') {
                if (target.classList.contains('e-responsivecoldiv') || target.parentElement.classList.contains('e-responsivecoldiv')) {
                    var field = target.getAttribute('data-e-mappingname');
                    Eif (!field) {
                        field = target.parentElement.getAttribute('data-e-mappingname');
                    }
                    if (field) {
                        var col = gObj.getColumnByField(field);
                        this.isRowResponsive = true;
                        this.showResponsiveDialog(col);
                    }
                }
                else Eif (target.classList.contains('e-filterset') || target.parentElement.classList.contains('e-filtersetdiv')) {
                    var colDiv = util_1.parentsUntil(target, 'e-responsivecoldiv');
                    Eif (colDiv) {
                        var field = colDiv.getAttribute('data-e-mappingname');
                        var col = gObj.getColumnByField(field);
                        Iif (col.filter.type === 'Menu' || (!col.filter.type && gObj.filterSettings.type === 'Menu')) {
                            this.isDialogClose = true;
                        }
                        this.parent.filterModule.filterModule.clearCustomFilter(col);
                        this.removeCustomDlgFilterEle(target);
                    }
                }
            }
        };
        ResponsiveDialogRenderer.prototype.showResponsiveDialog = function (col, column) {
            if ((this.isCustomDialog && this.action === enum_1.ResponsiveDialogAction.isFilter && !this.isRowResponsive) ||
                (column && this.action === enum_1.ResponsiveDialogAction.isColMenu)) {
                this.menuCol = column;
                this.renderCustomFilterDialog(null, column);
            }
            else {
                this.filteredCol = col;
                this.renderResponsiveDialog(col);
                if (this.parent.enableAdaptiveUI && col) {
                    this.parent.filterModule.setFilterModel(col);
                    this.parent.filterModule.filterModule.openDialog(this.parent.filterModule.createOptions(col, undefined));
                }
                if (this.action === enum_1.ResponsiveDialogAction.isColumnChooser) {
                    this.parent.notify(events.renderResponsiveColumnChooserDiv, { action: 'open' });
                }
                if (this.action === enum_1.ResponsiveDialogAction.isSort) {
                    var args = {
                        cancel: false, dialogObj: this.customResponsiveDlg, requestType: 'beforeOpenAptiveSortDialog'
                    };
                    this.parent.trigger(events.beforeOpenAdaptiveDialog, args);
                    Iif (args.cancel) {
                        return;
                    }
                }
                this.customResponsiveDlg.show(true);
                this.customResponsiveDlg.element.style.maxHeight = '100%';
                this.setTopToChildDialog(this.customResponsiveDlg.element);
                if (this.parent.enableAdaptiveUI && this.parent.filterSettings && (this.parent.filterSettings.type === 'CheckBox'
                    || this.parent.filterSettings.type === 'Excel') && this.parent.filterSettings.enableInfiniteScrolling
                    && this.parent.filterSettings.loadingIndicator === 'Shimmer') {
                    var filterBase = this.parent.filterSettings.type === 'CheckBox' ? this.parent.filterModule.filterModule.checkBoxBase : this.parent.filterModule.filterModule.excelFilterBase;
                    filterBase.showMask();
                }
            }
        };
        ResponsiveDialogRenderer.prototype.setTopToChildDialog = function (dialogEle) {
            var child = dialogEle.querySelector('.e-dialog');
            if (child) {
                var top_1 = dialogEle.querySelector('.e-dlg-header-content').getBoundingClientRect().height;
                child.style.top = top_1 + 'px';
            }
        };
        ResponsiveDialogRenderer.prototype.renderCustomFilterDialog = function (col, column) {
            var gObj = this.parent;
            var isColMenu = this.action === enum_1.ResponsiveDialogAction.isColMenu;
            Iif (this.action === enum_1.ResponsiveDialogAction.isFilter && gObj.filterSettings.type === 'FilterBar') {
                return;
            }
            var colMenu = isColMenu ? 'e-customcolumnmenudiv ' : '';
            var outerDiv = this.parent.createElement('div', {
                id: gObj.element.id + (isColMenu ? 'customcolumnmenu' : 'customfilter'),
                className: this.parent.cssClass ? colMenu +
                    'e-customfilterdiv e-responsive-dialog ' + this.parent.cssClass : colMenu + 'e-customfilterdiv e-responsive-dialog'
            });
            this.parent.element.appendChild(outerDiv);
            this.customFilterDlg = this.getDialogOptions(col, true, null, column);
            var args = {
                cancel: false, dialogObj: this.customFilterDlg, requestType: 'beforeOpenAptiveFilterDialog'
            };
            this.parent.trigger(events.beforeOpenAdaptiveDialog, args);
            Iif (args.cancel) {
                return;
            }
            this.customFilterDlg.appendTo(outerDiv);
            this.customFilterDlg.show(true);
            this.customFilterDlg.element.style.maxHeight = '100%';
        };
        ResponsiveDialogRenderer.prototype.getDialogOptions = function (col, isCustomFilter, id, column) {
            var options = new ej2_popups_1.Dialog({
                isModal: true,
                showCloseIcon: true,
                closeOnEscape: false,
                locale: this.parent.locale,
                target: this.parent.adaptiveDlgTarget ? this.parent.adaptiveDlgTarget : document.body,
                visible: false,
                enableRtl: this.parent.enableRtl,
                content: this.renderResponsiveContent(col, column),
                open: this.dialogOpen.bind(this),
                created: this.dialogCreated.bind(this),
                close: this.beforeDialogClose.bind(this),
                width: '100%',
                height: '100%',
                animationSettings: { effect: 'None' },
                cssClass: this.parent.cssClass ? this.parent.cssClass : ''
            });
            var isStringTemplate = 'isStringTemplate';
            options["" + isStringTemplate] = true;
            if (isCustomFilter) {
                options.header = this.renderResponsiveHeader(col, undefined, true);
                var colMenu = this.action === enum_1.ResponsiveDialogAction.isColMenu ? 'e-customcolumnmenu ' : '';
                options.cssClass = colMenu + 'e-customfilter';
            }
            else {
                options.header = this.renderResponsiveHeader(col);
                options.cssClass = this.parent.rowRenderingMode === 'Vertical' && this.action === enum_1.ResponsiveDialogAction.isFilter
                    ? 'e-res' + id + ' e-row-responsive-filter' : 'e-res' + id;
            }
            return options;
        };
        ResponsiveDialogRenderer.prototype.renderResponsiveDialog = function (col) {
            var gObj = this.parent;
            Iif (this.action === enum_1.ResponsiveDialogAction.isFilter && gObj.filterSettings.type === 'FilterBar') {
                return;
            }
            var id = this.action === enum_1.ResponsiveDialogAction.isFilter ? 'filter' : 'sort';
            id = this.action === enum_1.ResponsiveDialogAction.isColumnChooser ? 'columnchooser' : id;
            var outerDiv = this.parent.createElement('div', {
                id: gObj.element.id + 'responsive' + id,
                className: this.parent.cssClass ?
                    'e-res' + id + 'div e-responsive-dialog ' + this.parent.cssClass : 'e-res' + id + 'div e-responsive-dialog'
            });
            this.parent.element.appendChild(outerDiv);
            this.customResponsiveDlg = this.getDialogOptions(col, false, id);
            this.customResponsiveDlg.appendTo(outerDiv);
        };
        ResponsiveDialogRenderer.prototype.dialogCreated = function () {
            util_1.addBiggerDialog(this.parent);
        };
        ResponsiveDialogRenderer.prototype.dialogOpen = function () {
            if (this.action === enum_1.ResponsiveDialogAction.isSort && this.parent.allowMultiSorting) {
                for (var i = 0; i < this.parent.sortSettings.columns.length; i++) {
                    this.sortedCols.push(this.parent.sortSettings.columns[parseInt(i.toString(), 10)].field);
                    var sortField = this.parent.sortSettings.columns[parseInt(i.toString(), 10)].field;
                    var sortDirection = this.parent.sortSettings.columns[parseInt(i.toString(), 10)].direction;
                    this.sortPredicate.push({ field: sortField, direction: sortDirection });
                }
            }
        };
        ResponsiveDialogRenderer.prototype.beforeDialogClose = function (args) {
            this.isDialogClose = args.element && !args.element.querySelector('.e-xl-customfilterdiv')
                && args.element.classList.contains('e-resfilterdiv');
            if (this.action === enum_1.ResponsiveDialogAction.isFilter) {
                if (args.element.classList.contains('e-resfilterdiv')) {
                    this.parent.filterModule.filterModule.closeResponsiveDialog(this.isCustomDlgRender);
                }
                else Eif (args.element.classList.contains('e-customfilterdiv')) {
                    this.closeCustomFilter();
                }
                Iif (this.parent.rowRenderingMode === 'Horizontal' && this.parent.showColumnMenu) {
                    this.parent.notify(events.renderResponsiveChangeAction, { action: 4 });
                    var custom = document.querySelector('.e-resfilter');
                    if (custom) {
                        ej2_base_1.remove(custom);
                    }
                }
            }
            else if (this.action === enum_1.ResponsiveDialogAction.isSort) {
                this.closeCustomDialog();
            }
            else if (this.action === enum_1.ResponsiveDialogAction.isColMenu) {
                this.closeCustomFilter();
                var custom = document.querySelector('.e-rescolummenu');
                Iif (custom) {
                    ej2_base_1.remove(custom);
                }
            }
            else Eif (this.action === enum_1.ResponsiveDialogAction.isColumnChooser) {
                this.parent.notify(events.renderResponsiveColumnChooserDiv, { action: 'clear' });
                var custom = document.querySelector('.e-rescolumnchooser');
                Eif (custom) {
                    ej2_base_1.remove(custom);
                }
                Iif (this.parent.rowRenderingMode === 'Horizontal' && this.parent.showColumnMenu) {
                    this.parent.notify(events.renderResponsiveChangeAction, { action: 4 });
                }
                this.isCustomDialog = false;
                this.isDialogClose = false;
            }
            this.parent.off(events.enterKeyHandler, this.keyHandler);
        };
        ResponsiveDialogRenderer.prototype.sortColumn = function () {
            if (!this.isSortApplied) {
                this.closeCustomDialog();
                return;
            }
            if (this.sortPredicate.length) {
                this.parent.setProperties({ sortSettings: { columns: [] } }, true);
            }
            for (var i = 0; i < this.sortPredicate.length; i++) {
                this.parent.sortColumn(this.sortPredicate[parseInt(i.toString(), 10)].field, this.sortPredicate[parseInt(i.toString(), 10)].direction, this.parent.allowMultiSorting);
            }
            if (!this.sortPredicate.length) {
                this.parent.clearSorting();
            }
            this.closeCustomDialog();
        };
        ResponsiveDialogRenderer.prototype.getHeaderTitle = function (args, col) {
            var gObj = this.parent;
            var title;
            if (this.action === enum_1.ResponsiveDialogAction.isEdit) {
                title = gObj.localeObj.getConstant('EditFormTitle') + args.primaryKeyValue[0];
            }
            else if (this.action === enum_1.ResponsiveDialogAction.isAdd) {
                title = gObj.localeObj.getConstant('AddFormTitle');
            }
            else if (this.action === enum_1.ResponsiveDialogAction.isFilter) {
                title = col ? col.headerText || col.field : gObj.localeObj.getConstant('FilterTitle');
            }
            else if (this.action === enum_1.ResponsiveDialogAction.isSort) {
                title = gObj.localeObj.getConstant('Sort');
            }
            else if (this.action === enum_1.ResponsiveDialogAction.isColMenu) {
                title = gObj.localeObj.getConstant('ColumnMenu');
            }
            else Eif (this.action === enum_1.ResponsiveDialogAction.isColumnChooser) {
                title = gObj.localeObj.getConstant('ChooseColumns');
            }
            return title;
        };
        ResponsiveDialogRenderer.prototype.getDialogName = function (action) {
            var name;
            if (action === enum_1.ResponsiveDialogAction.isAdd || action === enum_1.ResponsiveDialogAction.isEdit) {
                name = 'dialogEdit_wrapper_title';
            }
            else if (action === enum_1.ResponsiveDialogAction.isFilter) {
                name = 'responsive_filter_dialog_wrapper';
            }
            else if (action === enum_1.ResponsiveDialogAction.isColumnChooser) {
                name = 'responsive_column_chooser_dialog_wrapper';
            }
            return name;
        };
        ResponsiveDialogRenderer.prototype.getButtonText = function (action) {
            var text;
            if (action === enum_1.ResponsiveDialogAction.isAdd || action === enum_1.ResponsiveDialogAction.isEdit) {
                text = 'Save';
            }
            else Eif (action === enum_1.ResponsiveDialogAction.isFilter || this.action === enum_1.ResponsiveDialogAction.isSort ||
                action === enum_1.ResponsiveDialogAction.isColumnChooser || this.action === enum_1.ResponsiveDialogAction.isColumnChooser) {
                text = 'OKButton';
            }
            return text;
        };
        ResponsiveDialogRenderer.prototype.renderResponsiveHeader = function (col, args, isCustomFilter) {
            var _this = this;
            var gObj = this.parent;
            gObj.on(events.enterKeyHandler, this.keyHandler, this);
            var id = gObj.element.id + this.getDialogName(this.action);
            var header = gObj.createElement('div', { className: 'e-res-custom-element' });
            var titleDiv = gObj.createElement('div', { className: 'e-dlg-custom-header', id: id });
            titleDiv.innerHTML = this.getHeaderTitle(args, col);
            header.appendChild(titleDiv);
            var saveBtn = gObj.createElement('button');
            if (!isCustomFilter) {
                this.saveBtn = new ej2_buttons_1.Button({
                    cssClass: this.parent.cssClass ?
                        'e-primary e-flat e-res-apply-btn' + ' ' + this.parent.cssClass : 'e-primary e-flat e-res-apply-btn'
                });
                saveBtn.innerHTML = gObj.localeObj.getConstant(this.getButtonText(this.action));
                this.saveBtn.appendTo(saveBtn);
                saveBtn.onclick = function (e) {
                    _this.dialogHdrBtnClickHandler();
                };
            }
            var isSort = this.action === enum_1.ResponsiveDialogAction.isSort;
            var isFilter = this.action === enum_1.ResponsiveDialogAction.isFilter;
            if (isFilter || isSort) {
                var id_1 = isSort ? 'sort' : 'filter';
                var clearBtn = gObj.createElement('button');
                this.filterClearBtn = new ej2_buttons_1.Button({
                    cssClass: this.parent.cssClass ? 'e-primary e-flat e-res-' + id_1 + '-clear-btn' + ' ' + this.parent.cssClass
                        : 'e-primary e-flat e-res-' + id_1 + '-clear-btn'
                });
                if (isFilter) {
                    var span = gObj.createElement('span', { className: 'e-btn-icon e-icon-filter-clear e-icons' });
                    clearBtn.appendChild(span);
                }
                else {
                    clearBtn.innerHTML = gObj.localeObj.getConstant('Clear');
                }
                header.appendChild(clearBtn);
                this.filterClearBtn.appendTo(clearBtn);
                clearBtn.onclick = function (e) {
                    if ((util_1.parentsUntil(e.target, 'e-customfilter'))) {
                        _this.parent.filterModule.clearFiltering();
                        _this.removeCustomDlgFilterEle();
                    }
                    else {
                        if (isFilter) {
                            _this.filterClear();
                        }
                        else {
                            _this.resetSortButtons();
                            _this.sortedCols = [];
                            _this.sortPredicate = [];
                            _this.isSortApplied = true;
                        }
                    }
                };
                header.appendChild(clearBtn);
            }
            if (!isCustomFilter) {
                header.appendChild(saveBtn);
            }
            return header;
        };
        ResponsiveDialogRenderer.prototype.filterClear = function () {
            this.parent.filterModule.filterModule.clearCustomFilter(this.filteredCol);
            this.parent.filterModule.filterModule.closeResponsiveDialog();
        };
        ResponsiveDialogRenderer.prototype.removeCustomFilterElement = function () {
            var elem = document.getElementById(this.parent.element.id + 'customcolumnmenu');
            if (elem) {
                ej2_base_1.remove(elem);
                var custom = document.querySelector('.e-customfilter');
                Eif (custom) {
                    ej2_base_1.remove(custom);
                }
            }
            var custommenu = document.querySelector('.e-rescolumnchooser');
            if (custommenu) {
                ej2_base_1.remove(custommenu);
            }
        };
        ResponsiveDialogRenderer.prototype.dialogHdrBtnClickHandler = function () {
            if (this.action === enum_1.ResponsiveDialogAction.isEdit || this.action === enum_1.ResponsiveDialogAction.isAdd) {
                this.parent.endEdit();
            }
            else if (this.action === enum_1.ResponsiveDialogAction.isFilter) {
                this.parent.filterModule.filterModule.applyCustomFilter({ col: this.filteredCol, isCustomFilter: this.isCustomDlgRender });
                this.removeCustomFilterElement();
            }
            else if (this.action === enum_1.ResponsiveDialogAction.isSort) {
                this.sortColumn();
                this.removeCustomFilterElement();
            }
            else Eif (this.action === enum_1.ResponsiveDialogAction.isColumnChooser) {
                this.parent.notify(events.renderResponsiveColumnChooserDiv, { action: 'confirm' });
                this.removeCustomFilterElement();
                this.isCustomDialog = false;
                this.isDialogClose = false;
            }
        };
        ResponsiveDialogRenderer.prototype.closeCustomDialog = function () {
            if (this.isCustomDlgRender) {
                var mainfilterdiv = this.customResponsiveDlg.element.querySelector('.e-mainfilterdiv');
                ej2_base_1.remove(mainfilterdiv);
                return;
            }
            this.isRowResponsive = false;
            this.isCustomDlgRender = false;
            this.destroyCustomFilterDialog();
        };
        ResponsiveDialogRenderer.prototype.destroyCustomFilterDialog = function () {
            if (!this.customResponsiveDlg) {
                return;
            }
            var elem = document.getElementById(this.customResponsiveDlg.element.id);
            if (this.customResponsiveDlg && !this.customResponsiveDlg.isDestroyed && elem) {
                this.customResponsiveDlg.destroy();
                ej2_base_1.remove(elem);
            }
            this.closeCustomFilter();
            if (this.action === enum_1.ResponsiveDialogAction.isSort) {
                this.sortPredicate = [];
                this.sortedCols = [];
                this.isSortApplied = false;
            }
        };
        ResponsiveDialogRenderer.prototype.closeCustomFilter = function () {
            if (!this.isDialogClose && this.customFilterDlg) {
                var customEle = document.getElementById(this.customFilterDlg.element.id);
                if (this.customFilterDlg && !this.customFilterDlg.isDestroyed && customEle) {
                    this.customFilterDlg.destroy();
                    ej2_base_1.remove(customEle);
                }
            }
            this.isCustomDialog = false;
            this.isDialogClose = false;
        };
        ResponsiveDialogRenderer.prototype.removeCustomDlgFilterEle = function (target) {
            if (target) {
                if (target.parentElement.classList.contains('e-filtersetdiv')) {
                    ej2_base_1.remove(target.parentElement);
                }
                else {
                    ej2_base_1.remove(target);
                }
            }
            else {
                var child = this.customColumnDiv.children;
                for (var i = 0; i < child.length; i++) {
                    target = child[parseInt(i.toString(), 10)].querySelector('.e-filtersetdiv');
                    if (target) {
                        ej2_base_1.remove(target);
                        i--;
                    }
                }
            }
        };
        ResponsiveDialogRenderer.prototype.keyHandler = function (e) {
            Iif (e.keyCode === 13 && ((this.action === enum_1.ResponsiveDialogAction.isFilter
                && e.target.classList.contains('e-searchinput'))
                || (this.action === enum_1.ResponsiveDialogAction.isEdit || this.action === enum_1.ResponsiveDialogAction.isAdd))) {
                this.dialogHdrBtnClickHandler();
            }
        };
        ResponsiveDialogRenderer.prototype.editComplate = function (args) {
            if (args.requestType === 'save' || args.requestType === 'cancel') {
                this.parent.off(events.enterKeyHandler, this.keyHandler);
            }
        };
        ResponsiveDialogRenderer.prototype.removeEventListener = function () {
            Iif (this.customColumnDiv) {
                ej2_base_1.EventHandler.remove(this.customColumnDiv, ej2_base_1.Browser.isDevice ? 'touchend' : 'click', this.customFilterColumnClickHandler);
            }
            util_1.addRemoveEventListener(this.parent, this.evtHandlers, true, this);
            this.parent.removeEventListener(events.actionComplete, this.onActionCompleteFn);
        };
        return ResponsiveDialogRenderer;
    }());
    exports.ResponsiveDialogRenderer = ResponsiveDialogRenderer;
});