all files / common/popups/ drillthrough-dialog.js

78.32% Statements 242/309
65.46% Branches 127/194
86.36% Functions 19/22
78.32% Lines 242/309
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   257× 257× 257× 257×   29× 29× 29× 29× 29× 1346×   29× 29×           28× 28×       28× 28×             28×             26× 11×   11× 11× 11× 20× 20×   11× 11× 11× 11× 11× 19× 19× 97× 97× 21×       14× 14× 14× 14×   19×               19×   11× 11×                         11× 11×   11× 85× 85× 85× 79×   85×   11× 11×           11× 11× 11× 11× 11×     11× 11×           11×   26× 26×                           28× 28× 28× 28×     28× 13×                                                                                         15× 14×     15×               54× 28× 28× 28×   28×   54× 54× 28×   54×       28× 28× 28×       28× 21×         28× 24×           28× 28× 28× 28× 28×           28× 28× 13×   10×           28× 28× 28×                                 28×     28× 28×         28×     28×     28× 13× 13× 13× 13× 35×     35× 35× 13×         13×                     10×   13×               13× 36× 13×   36× 36×     36× 36× 14×   36×         13×       15×   28× 28× 28× 28× 28× 28×   29×   29× 29× 29×       29×                               29× 540× 540× 513× 513×   513× 145×   368×     368×       368×   513×     513×                         29×   28×           28×             28×                                 13× 13× 13× 13× 23× 23× 23× 23×   13×                                                         26×     26×         26×          
define(["require", "exports", "@syncfusion/ej2-popups", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../../common/base/css-constant", "@syncfusion/ej2-grids", "@syncfusion/ej2-grids", "../../common/base/constant", "@syncfusion/ej2-inputs", "../../base/util"], function (require, exports, ej2_popups_1, ej2_base_1, ej2_base_2, cls, ej2_grids_1, ej2_grids_2, events, ej2_inputs_1, util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var DrillThroughDialog = (function () {
        function DrillThroughDialog(parent) {
            this.indexString = [];
            this.isUpdated = false;
            this.parent = parent;
            this.engine = this.parent.dataType === 'olap' ? this.parent.olapEngineModule : this.parent.engineModule;
        }
        DrillThroughDialog.prototype.showDrillThroughDialog = function (eventArgs) {
            var _this = this;
            var gridData = eventArgs.rawData;
            var clonedData = [];
            var gridIndexObjects = {};
            for (var i = 0; i < eventArgs.rawData.length; i++) {
                clonedData.push(util_1.PivotUtil.frameHeaderWithKeys(eventArgs.rawData[i]));
            }
            try {
                if (this.parent.currentView === 'Table' && this.parent.editSettings.allowInlineEditing &&
                    this.parent.editSettings.allowEditing && eventArgs.rawData.length === 1) {
                    this.parent.actionObj.actionName = events.editRecord;
                    Iif (this.parent.actionBeginMethod()) {
                        return;
                    }
                    this.editCell(eventArgs, gridData);
                }
                else {
                    this.removeDrillThroughDialog();
                    var drillThroughDialog = ej2_base_2.createElement('div', {
                        id: this.parent.element.id + '_drillthrough',
                        className: cls.DRILLTHROUGH_DIALOG
                    });
                    this.parent.element.appendChild(drillThroughDialog);
                    this.dialogPopUp = new ej2_popups_1.Dialog({
                        animationSettings: { effect: 'Fade' },
                        allowDragging: false,
                        header: this.parent.localeObj.getConstant('details'),
                        content: this.createDrillThroughGrid(eventArgs, gridData),
                        cssClass: this.parent.cssClass,
                        beforeOpen: function () {
                            _this.drillThroughGrid.setProperties({
                                dataSource: _this.parent.editSettings.allowEditing ?
                                    _this.dataWithPrimarykey(eventArgs, gridData, gridIndexObjects) : gridData,
                                height: !_this.parent.editSettings.allowEditing ? 300 : 220
                            }, false);
                        },
                        beforeClose: function () {
                            if (_this.parent.editSettings.allowEditing && _this.isUpdated) {
                                if (_this.parent.dataSourceSettings.type === 'CSV') {
                                    _this.updateData(_this.drillThroughGrid.dataSource);
                                }
                                var gridIndexObjectsValue = Object.keys(gridIndexObjects);
                                var previousPosition = [];
                                for (var _i = 0, gridIndexObjectsValue_1 = gridIndexObjectsValue; _i < gridIndexObjectsValue_1.length; _i++) {
                                    var value = gridIndexObjectsValue_1[_i];
                                    previousPosition.push(gridIndexObjects[value]);
                                }
                                var count = Object.keys(gridIndexObjects).length;
                                var addItems = [];
                                var prevItems = [];
                                var index = 0;
                                for (var _a = 0, _b = _this.drillThroughGrid.dataSource; _a < _b.length; _a++) {
                                    var item = _b[_a];
                                    if (item['__index'] === '0' || item['__index'] === '') {
                                        for (var _c = 0, _d = _this.engine.fields; _c < _d.length; _c++) {
                                            var field = _d[_c];
                                            if (ej2_base_2.isNullOrUndefined(item[field])) {
                                                delete item[field];
                                            }
                                        }
                                        delete item['__index'];
                                        addItems.push(item);
                                    }
                                    else Eif (count > 0) {
                                        delete gridIndexObjects[item['__index'].toString()];
                                        prevItems.push(item);
                                        count--;
                                    }
                                    Iif (_this.parent.dataSourceSettings.mode === 'Server') {
                                        if (item['__index']) {
                                            delete item['__index'];
                                        }
                                        if (gridData[index]['__index']) {
                                            delete gridData[index]['__index'];
                                        }
                                    }
                                    index++;
                                }
                                count = 0;
                                Iif (_this.parent.dataSourceSettings.mode === 'Server') {
                                    var gridIndex = [];
                                    var keys = Object.keys(gridIndexObjects);
                                    for (var len = 0; len < keys.length; len++) {
                                        delete _this.parent.drillThroughValue.indexObject[gridIndexObjects[keys[len]]];
                                        gridIndex.push({ Key: keys[len], Value: gridIndexObjects[keys[len]] });
                                    }
                                    _this.parent.getEngine('updateRawData', null, null, null, null, null, null, null, {
                                        'addedData': addItems, 'removedData': gridIndex, 'updatedData': prevItems,
                                        indexObject: _this.parent.drillThroughValue.indexObject
                                    });
                                }
                                else {
                                    var items = [];
                                    var data = _this.parent.allowDataCompression
                                        ? _this.parent.engineModule.actualData : _this.parent.engineModule.data;
                                    for (var _e = 0, _f = data; _e < _f.length; _e++) {
                                        var item = _f[_e];
                                        delete item['__index'];
                                        if (gridIndexObjects[count.toString()] === undefined) {
                                            items.push(item);
                                        }
                                        count++;
                                    }
                                    items = items.concat(addItems);
                                    var eventArgs_1 = {
                                        currentData: _this.drillThroughGrid.dataSource,
                                        previousData: clonedData,
                                        previousPosition: previousPosition,
                                        cancel: false
                                    };
                                    _this.parent.trigger(events.editCompleted, eventArgs_1);
                                    Eif (!eventArgs_1.cancel) {
                                        _this.parent.setProperties({ dataSourceSettings: { dataSource: items } }, true);
                                        _this.engine.updateGridData(_this.parent.dataSourceSettings);
                                        _this.parent.pivotValues = _this.engine.pivotValues;
                                    }
                                }
                                _this.parent.actionObj.actionName = events.recordUpdated;
                                var actionInfo = {
                                    editInfo: {
                                        type: _this.drillThroughGrid.editSettings.mode, action: 'Update', currentData: _this.drillThroughGrid.dataSource,
                                        previousData: clonedData, previousPosition: previousPosition
                                    }
                                };
                                _this.parent.actionObj.actionInfo = actionInfo;
                            }
                            _this.isUpdated = false;
                            gridIndexObjects = {};
                        },
                        isModal: true,
                        visible: true,
                        showCloseIcon: true,
                        locale: this.parent.locale,
                        enableRtl: this.parent.enableRtl,
                        enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                        width: this.parent.isAdaptive ? '100%' : '60%',
                        position: { X: 'center', Y: 'center' },
                        closeOnEscape: !this.parent.editSettings.allowEditing,
                        target: document.body,
                        close: this.removeDrillThroughDialog.bind(this)
                    });
                    this.dialogPopUp.isStringTemplate = true;
                    this.dialogPopUp.appendTo(drillThroughDialog);
                    ej2_base_2.setStyleAttribute(this.dialogPopUp.element, { 'visibility': 'visible' });
                    var drillKeyConfigs = {
                        escape: 'escape'
                    };
                    if (this.parent.editSettings.allowEditing) {
                        this.drillthroughKeyboardModule = new ej2_base_2.KeyboardEvents(this.dialogPopUp.element, {
                            keyAction: this.drillthroughKeyActionHandler.bind(this),
                            keyConfigs: drillKeyConfigs,
                            eventName: 'keydown'
                        });
                    }
                }
            }
            catch (execption) {
                this.parent.actionFailureMethod(execption);
            }
        };
        DrillThroughDialog.prototype.editCell = function (eventArgs, gridData) {
            var _this = this;
            var gridResize = this.parent.gridSettings.allowResizing;
            var actualText = eventArgs.currentCell.actualText.toString();
            var indexObject = Number(Object.keys(eventArgs.currentCell.indexObject));
            eventArgs.currentTarget.firstElementChild.style.display = 'none';
            var cellValue = Number(eventArgs.rawData[0][actualText]);
            var previousData = util_1.PivotUtil.frameHeaderWithKeys(eventArgs.rawData[eventArgs.rawData.length - 1]);
            var currentData = eventArgs.rawData[eventArgs.rawData.length - 1];
            var actionInfo = {
                editInfo: { type: 'Inline editing', action: 'update', data: gridData }
            };
            this.parent.actionObj.actionInfo = actionInfo;
            var numericTextBox = new ej2_inputs_1.NumericTextBox({
                value: cellValue,
                enableRtl: this.parent.enableRtl,
                enabled: true,
                format: '####.##',
                locale: this.parent.locale,
                cssClass: this.parent.cssClass,
                change: function () {
                    var textBoxValue = ej2_base_2.isNullOrUndefined(numericTextBox.value) ? 0 : numericTextBox.value;
                    var indexValue = eventArgs.currentCell.indexObject[indexObject];
                    eventArgs.rawData[0][actualText] = textBoxValue;
                    _this.parent.engineModule.data[indexValue] = eventArgs.rawData[0];
                },
                blur: function () {
                    var eventArgs = {
                        currentData: [currentData],
                        previousData: [previousData],
                        previousPosition: [currentData.index],
                        cancel: false
                    };
                    _this.parent.trigger(events.editCompleted, eventArgs);
                    Eif (!eventArgs.cancel) {
                        Iif (_this.parent.dataSourceSettings.mode === 'Server') {
                            var dataIndex = {};
                            dataIndex[indexObject] = indexObject;
                            var prevItems = [currentData];
                            _this.parent.getEngine('updateRawData', null, null, null, null, null, null, null, {
                                'addedData': [], 'removedData': [], 'updatedData': prevItems,
                                indexObject: dataIndex
                            });
                        }
                        _this.parent.setProperties({ dataSourceSettings: { dataSource: _this.parent.engineModule.data } }, true);
                        _this.engine.updateGridData(_this.parent.dataSourceSettings);
                        _this.parent.pivotValues = _this.engine.pivotValues;
                        _this.parent.gridSettings.allowResizing = gridResize;
                    }
                }
            });
            var textBoxElement = ej2_base_2.createElement('input', {
                id: this.parent.element.id + '_inputbox'
            });
            eventArgs.currentTarget.appendChild(textBoxElement);
            numericTextBox.appendTo(textBoxElement);
            eventArgs.currentCell.value = numericTextBox.value;
            numericTextBox.focusIn();
            this.parent.gridSettings.allowResizing = false;
        };
        DrillThroughDialog.prototype.updateData = function (dataSource) {
            var dataPos = 0;
            var data = this.parent.allowDataCompression ?
                this.parent.engineModule.actualData : this.parent.engineModule.data;
            while (dataPos < dataSource.length) {
                var fields = Object.keys(dataSource[dataPos]);
                var keyPos = 0;
                var framedSet = [];
                while (keyPos < fields.length) {
                    if (!ej2_base_2.isNullOrUndefined(this.parent.engineModule.fieldKeys[fields[keyPos]])) {
                        framedSet[this.parent.engineModule.fieldKeys[fields[keyPos]]] =
                            ((dataSource)[dataPos])[fields[keyPos]];
                    }
                    keyPos++;
                }
                data[Number(dataSource[dataPos]['__index'])] = framedSet;
                dataPos++;
            }
            Iif (this.parent.allowDataCompression) {
                this.parent.engineModule.actualData = data;
            }
            else {
                this.parent.engineModule.data = data;
            }
        };
        DrillThroughDialog.prototype.removeDrillThroughDialog = function () {
            if (this.dialogPopUp && !this.dialogPopUp.isDestroyed) {
                this.parent.actionObj.actionName = events.drillThroughClosed;
                Eif (this.parent.actionObj.actionName) {
                    this.parent.actionCompleteMethod();
                }
                this.dialogPopUp.destroy();
            }
            var dialogElement = document.getElementById(this.parent.element.id + '_drillthrough');
            if (dialogElement) {
                ej2_base_2.remove(dialogElement);
            }
            Iif (document.getElementById(this.parent.element.id + '_drillthroughgrid_ccdlg')) {
                ej2_base_2.remove(document.getElementById(this.parent.element.id + '_drillthroughgrid_ccdlg'));
            }
        };
        DrillThroughDialog.prototype.createDrillThroughGrid = function (eventArgs, gridData) {
            var _this = this;
            var drillThroughBody = ej2_base_2.createElement('div', { id: this.parent.element.id + '_drillthroughbody', className: cls.DRILLTHROUGH_BODY_CLASS });
            var drillThroughBodyHeader = ej2_base_2.createElement('div', {
                id: this.parent.element.id +
                    '_drillthroughbodyheader', className: cls.DRILLTHROUGH_BODY_HEADER_CONTAINER_CLASS
            });
            if (eventArgs.rowHeaders !== '') {
                drillThroughBodyHeader.innerHTML = '<span class=' +
                    cls.DRILLTHROUGH_BODY_HEADER_COMMON_CLASS + '><span class=' + cls.DRILLTHROUGH_BODY_HEADER_CLASS + '>' +
                    this.parent.localeObj.getConstant('row') + '</span> : <span class=' +
                    cls.DRILLTHROUGH_BODY_HEADER_VALUE_CLASS + '>' + eventArgs.rowHeaders + '</span></span>';
            }
            if (eventArgs.columnHeaders !== '') {
                drillThroughBodyHeader.innerHTML = drillThroughBodyHeader.innerHTML + '<span class=' +
                    cls.DRILLTHROUGH_BODY_HEADER_COMMON_CLASS + '><span class=' +
                    cls.DRILLTHROUGH_BODY_HEADER_CLASS + '>' + this.parent.localeObj.getConstant('column') +
                    '</span> : <span class=' + cls.DRILLTHROUGH_BODY_HEADER_VALUE_CLASS + '>' +
                    eventArgs.columnHeaders + '</span></span>';
            }
            Eif (eventArgs.value !== '') {
                var measure = eventArgs.value.split('(')[0];
                var value = eventArgs.value.split('(')[1].split(')')[0];
                Eif (value !== '0') {
                    drillThroughBodyHeader.innerHTML = drillThroughBodyHeader.innerHTML + '<span class=' +
                        cls.DRILLTHROUGH_BODY_HEADER_COMMON_CLASS + '><span class=' +
                        cls.DRILLTHROUGH_BODY_HEADER_CLASS + '>' +
                        measure + '</span> : <span class=' + cls.DRILLTHROUGH_BODY_HEADER_VALUE_CLASS + '>' + value + '</span></span>';
                }
            }
            var toolbarItems = ['ColumnChooser'];
            if (this.parent.editSettings.allowEditing) {
                if (this.parent.editSettings.allowCommandColumns) {
                    toolbarItems = ['ColumnChooser', 'Add'];
                }
                else if (this.parent.editSettings.mode === 'Batch') {
                    toolbarItems = ['ColumnChooser', 'Add', 'Delete', 'Update', 'Cancel'];
                }
                else if (this.parent.editSettings.mode === 'Dialog') {
                    toolbarItems = ['ColumnChooser', 'Add', 'Edit', 'Delete'];
                }
                else {
                    toolbarItems = ['ColumnChooser', 'Add', 'Edit', 'Delete', 'Update', 'Cancel'];
                }
            }
            var drillThroughGrid = ej2_base_2.createElement('div', { id: this.parent.element.id + '_drillthroughgrid', className: cls.DRILLTHROUGH_GRID_CLASS });
            ej2_grids_1.Grid.Inject(ej2_grids_2.Selection, ej2_grids_1.Reorder, ej2_grids_1.Resize, ej2_grids_1.Toolbar, ej2_grids_1.ColumnChooser);
            this.drillThroughGrid = new ej2_grids_1.Grid({
                cssClass: this.parent.cssClass,
                gridLines: 'Default',
                allowResizing: true,
                allowReordering: true,
                showColumnChooser: true,
                enableHover: false,
                toolbar: toolbarItems,
                columns: eventArgs.gridColumns,
                locale: this.parent.locale,
                enableRtl: this.parent.enableRtl,
                enableVirtualization: !this.parent.editSettings.allowEditing,
                allowPaging: this.parent.editSettings.allowEditing,
                pageSettings: { pageSize: 20 },
                rowHeight: this.parent.gridSettings.rowHeight,
                height: '100%'
            });
            Iif (this.parent.dataType === 'olap') {
                this.formatData(gridData);
            }
            var dialogModule = this;
            this.parent.trigger(events.beginDrillThrough, {
                cellInfo: eventArgs,
                gridObj: this.drillThroughGrid,
                type: 'editing'
            });
            Iif (this.drillThroughGrid.allowExcelExport) {
                ej2_grids_1.Grid.Inject(ej2_grids_1.ExcelExport);
            }
            Iif (this.drillThroughGrid.allowPdfExport) {
                ej2_grids_1.Grid.Inject(ej2_grids_1.PdfExport);
            }
            if (this.parent.editSettings.allowEditing) {
                ej2_grids_1.Grid.Inject(ej2_grids_2.Edit, ej2_grids_2.Page);
                try {
                    this.drillThroughGrid.editSettings = this.parent.editSettings;
                    this.drillThroughGrid.actionBegin = function (args) {
                        var actionName = (args.requestType === 'save') ? events.saveEditedRecords :
                            (args.requestType === 'add') ? events.addNewRecord : (args.requestType === 'delete') ?
                                events.removeRecord : '';
                        _this.parent.actionObj.actionName = actionName;
                        if (_this.parent.actionObj.actionName) {
                            Iif (_this.parent.actionBeginMethod()) {
                                return;
                            }
                        }
                    };
                    if (this.parent.editSettings.allowCommandColumns) {
                        this.drillThroughGrid.editSettings.mode = 'Normal';
                        this.drillThroughGrid.editSettings.allowEditOnDblClick = false;
                        ej2_grids_1.Grid.Inject(ej2_grids_2.CommandColumn);
                        this.drillThroughGrid.columns.push({
                            headerText: this.parent.localeObj.getConstant('manageRecords'), width: 160, showInColumnChooser: false,
                            commands: [
                                { type: 'Edit', buttonOption: { iconCss: ' e-icons e-edit', cssClass: 'e-flat' + (this.parent.cssClass ? (' ' + this.parent.cssClass) : '') } },
                                { type: 'Delete', buttonOption: { iconCss: 'e-icons e-delete', cssClass: 'e-flat' + (this.parent.cssClass ? (' ' + this.parent.cssClass) : '') } },
                                { type: 'Save', buttonOption: { iconCss: 'e-icons e-update', cssClass: 'e-flat' + (this.parent.cssClass ? (' ' + this.parent.cssClass) : '') } },
                                { type: 'Cancel', buttonOption: { iconCss: 'e-icons e-cancel-icon', cssClass: 'e-flat' + (this.parent.cssClass ? (' ' + this.parent.cssClass) : '') } }
                            ]
                        });
                    }
                    else {
                        this.drillThroughGrid.editSettings.allowEditOnDblClick = this.parent.editSettings.allowEditOnDblClick;
                    }
                    this.drillThroughGrid.columns.push({
                        field: '__index', visible: false, isPrimaryKey: true, type: 'string', showInColumnChooser: false,
                        defaultValue: '0', validationRules: { required: true }
                    });
                }
                catch (execption) {
                    this.parent.actionFailureMethod(execption);
                }
                this.drillThroughGrid.actionComplete = function (args) {
                    if (args.requestType === 'batchsave' || args.requestType === 'save' || args.requestType === 'delete') {
                        dialogModule.isUpdated = true;
                    }
                    _this.parent.actionObj.actionName = _this.parent.getActionCompleteName();
                    var actionInfo = {
                        editInfo: { type: _this.drillThroughGrid.editSettings.mode, action: args.requestType, data: gridData }
                    };
                    _this.parent.actionObj.actionInfo = actionInfo;
                    if (_this.parent.actionObj.actionName) {
                        _this.parent.actionCompleteMethod();
                    }
                    if ((dialogModule.drillThroughGrid.editSettings.mode === 'Normal' && args.requestType === 'save' &&
                        dialogModule.drillThroughGrid.element.querySelectorAll('.e-tbar-btn:hover').length > 0 &&
                        !dialogModule.parent.editSettings.allowCommandColumns) || args.requestType === 'batchsave') {
                        dialogModule.dialogPopUp.hide();
                    }
                };
                this.drillThroughGrid.beforeBatchSave = function () {
                    dialogModule.isUpdated = true;
                };
            }
            else {
                ej2_grids_1.Grid.Inject(ej2_grids_2.VirtualScroll);
            }
            document.body.appendChild(drillThroughGrid);
            this.drillThroughGrid.isStringTemplate = true;
            this.drillThroughGrid.appendTo(drillThroughGrid);
            drillThroughBody.appendChild(drillThroughBodyHeader);
            drillThroughBody.appendChild(drillThroughGrid);
            return drillThroughBody;
        };
        DrillThroughDialog.prototype.frameGridColumns = function (rawData) {
            var keys = this.parent.dataType === 'olap' ? rawData[0] ? Object.keys(rawData[0]) : [] :
                Object.keys(this.engine.fieldList);
            var columns = [];
            var formatList = {};
            if (this.parent.dataSourceSettings.formatSettings.length > 0) {
                for (var i = 0; i < this.parent.dataSourceSettings.formatSettings.length; i++) {
                    formatList[this.parent.dataSourceSettings.formatSettings[i].name] =
                        this.parent.dataSourceSettings.formatSettings[i].format;
                }
            }
            Iif (this.parent.dataType === 'olap') {
                for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
                    var key = keys_1[_i];
                    columns.push({
                        field: key.replace(/_x005B_|_x0020_|_x005D_|_x0024_/g, '').replace('].[', '').split('.').reverse().join(''),
                        headerText: key.replace(/_x005B_|_x005D_|_x0024_/g, '').replace(/_x0020_/g, ' ').
                            replace('].[', '').split('.').reverse().join('.'),
                        width: 120,
                        visible: true,
                        validationRules: { required: true },
                        format: !ej2_base_2.isNullOrUndefined(formatList[key]) ? formatList[key] : null,
                        type: !ej2_base_2.isNullOrUndefined(formatList[key]) ? null : 'string'
                    });
                }
            }
            else {
                for (var _a = 0, keys_2 = keys; _a < keys_2.length; _a++) {
                    var key = keys_2[_a];
                    if (this.engine.fieldList[key].aggregateType !== 'CalculatedField') {
                        var editType = '';
                        var isDateField = ((this.engine.fieldList[key].type === 'date' || this.engine.fieldList[key].type === 'datetime')
                            && (this.isDateFieldExist(key) || (rawData[0] && rawData[0][key] && rawData[0][key].toString().indexOf(' ') === -1))) ? true : false;
                        if (this.engine.fieldList[key].type === 'number') {
                            editType = 'numericedit';
                        }
                        else Iif (this.engine.fieldList[key].type === 'date' && isDateField) {
                            editType = 'datepickeredit';
                        }
                        else Iif (this.engine.fieldList[key].type === 'datetime' && isDateField) {
                            editType = 'datetimepickeredit';
                        }
                        else {
                            editType = 'defaultedit';
                        }
                        var caption = this.parent.enableHtmlSanitizer ?
                            ej2_base_1.SanitizeHtmlHelper.sanitize(this.engine.fieldList[key].caption)
                            : this.engine.fieldList[key].caption;
                        columns.push({
                            field: key,
                            headerText: caption,
                            width: 120,
                            visible: this.engine.fieldList[key].isSelected,
                            validationRules: { required: true },
                            editType: editType,
                            format: !ej2_base_2.isNullOrUndefined(formatList[key]) ? formatList[key] : undefined,
                            type: !ej2_base_2.isNullOrUndefined(formatList[key]) ? null : 'string'
                        });
                    }
                }
            }
            return columns;
        };
        DrillThroughDialog.prototype.isDateFieldExist = function (key) {
            for (var len = 0; len < this.parent.dataSourceSettings.formatSettings.length; len++) {
                if (this.parent.dataSourceSettings.formatSettings[len].name === key &&
                    this.parent.dataSourceSettings.formatSettings[len].type.indexOf('date') > -1) {
                    return true;
                }
            }
            for (var len = 0; len < this.parent.dataSourceSettings.fieldMapping.length; len++) {
                if (this.parent.dataSourceSettings.fieldMapping[len].name === key &&
                    this.parent.dataSourceSettings.fieldMapping[len].dataType &&
                    this.parent.dataSourceSettings.fieldMapping[len].dataType.indexOf('date') > -1) {
                    return true;
                }
            }
            return false;
        };
        DrillThroughDialog.prototype.formatData = function (gridData) {
            var index = 0;
            while (index < gridData.length) {
                var data = gridData[index];
                var keys = Object.keys(gridData[index]);
                var newData = {};
                var i = 0;
                while (i < keys.length) {
                    var key = keys[i].replace(/_x005B_|_x0020_|_x005D_|_x0024_/g, '').replace('].[', '').split('.').reverse().join('');
                    newData[key] = data[keys[i]];
                    i++;
                }
                gridData[index] = newData;
                index++;
            }
        };
        DrillThroughDialog.prototype.dataWithPrimarykey = function (eventArgs, gridData, gridIndexObjects) {
            var indexString = this.indexString.length > 0 ? this.indexString : Object.keys(eventArgs.currentCell.indexObject);
            var rawData = gridData;
            var count = 0;
            for (var _i = 0, rawData_1 = rawData; _i < rawData_1.length; _i++) {
                var item = rawData_1[_i];
                item['__index'] = indexString[count];
                gridIndexObjects[indexString[count].toString()] = Number(indexString[count]);
                count++;
            }
            return rawData;
        };
        DrillThroughDialog.prototype.drillthroughKeyActionHandler = function (e) {
            switch (e.action) {
                case 'escape':
                    this.processClose(e);
                    break;
            }
        };
        DrillThroughDialog.prototype.processClose = function (e) {
            var target = e.target;
            if (target && ej2_base_2.closest(target, '.e-popup.e-popup-open')) {
                var dialogInstance = ej2_base_1.getInstance(ej2_base_2.closest(target, '.e-popup.e-popup-open'), ej2_popups_1.Dialog);
                if (dialogInstance && !dialogInstance.closeOnEscape) {
                    var button = dialogInstance.element.getAttribute('data-fieldName');
                    dialogInstance.hide();
                    if (this.parent.element) {
                        var pivotButtons = [].slice.call(this.parent.element.querySelectorAll('.e-pivot-button'));
                        for (var _i = 0, pivotButtons_1 = pivotButtons; _i < pivotButtons_1.length; _i++) {
                            var item = pivotButtons_1[_i];
                            if (item.getAttribute('data-uid') === button) {
                                item.focus();
                                break;
                            }
                        }
                    }
                    e.preventDefault();
                    return;
                }
            }
        };
        DrillThroughDialog.prototype.destroy = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            Iif (this.drillthroughKeyboardModule && !this.drillthroughKeyboardModule.isDestroyed) {
                this.drillthroughKeyboardModule.destroy();
                this.drillthroughKeyboardModule = null;
            }
            else {
                return;
            }
        };
        return DrillThroughDialog;
    }());
    exports.DrillThroughDialog = DrillThroughDialog;
});