all files / actions/ keyboard.js

88.02% Statements 191/217
83.15% Branches 232/279
88.89% Functions 8/9
88.43% Lines 191/216
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   1137× 1137× 1137×   1155×   390× 390×   76× 76× 76× 76×   76×     76× 76×     38×         76×             76×                         11× 11×     11× 11× 11×   11×       11×                                                                                                                                       17× 17×   17×                                                                         11× 11× 11× 11×       11× 11×                                 11×                                  
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var FocusModule = (function () {
        function FocusModule(parent) {
            this.parent = parent;
            this.activeElement = null;
            this.previousActiveElement = null;
        }
        FocusModule.prototype.getActiveElement = function (isPreviousActiveElement) {
            return isPreviousActiveElement ? this.previousActiveElement : this.activeElement;
        };
        FocusModule.prototype.setActiveElement = function (element) {
            this.previousActiveElement = this.activeElement;
            this.activeElement = element;
        };
        FocusModule.prototype.onKeyPress = function (e) {
            var ganttObj = this.parent;
            var ele = e.target;
            var expandedRecords = ganttObj.getExpandedRecords(ganttObj.currentViewData);
            if (ej2_base_1.isNullOrUndefined(this.parent.focusModule.getActiveElement()) && (e.action === 'expandAll' || e.action === 'collapseAll')) {
                var focussedElement = this.parent.element.querySelector('.e-treegrid');
                focussedElement.focus();
            }
            if (!this.parent.isEdit && !ej2_base_1.isNullOrUndefined(ele) && ele.closest('.e-headercell') && (e.key === 'Enter') && this.parent.sortModule
                && this.parent.allowSorting) {
                e.action = 'enter';
                this.parent.treeGrid.grid.notify('key-pressed', e);
            }
            var targetElement = this.parent.focusModule.getActiveElement();
            if (e.action === 'home' || e.action === 'end' || e.action === 'downArrow' || e.action === 'upArrow' || e.action === 'delete' ||
                e.action === 'rightArrow' || e.action === 'leftArrow' || e.action === 'focusTask' || e.action === 'focusSearch' ||
                e.action === 'expandAll' || e.action === 'collapseAll' || e.action === 'undo' || e.action === 'redo' || e.action === 'selectAll') {
                Iif (!ej2_base_1.isNullOrUndefined(ganttObj.editModule) && !ej2_base_1.isNullOrUndefined(ganttObj.editModule.cellEditModule) &&
                    ganttObj.editModule.cellEditModule.isCellEdit === true) {
                    return;
                }
            }
            if (ganttObj.isAdaptive) {
                Eif (e.action === 'addRowDialog' || e.action === 'editRowDialog' || e.action === 'delete'
                    || e.action === 'addRow') {
                    Iif (ganttObj.selectionModule && ganttObj.selectionSettings.type === 'Multiple') {
                        ganttObj.selectionModule.hidePopUp();
                        document.getElementsByClassName('e-gridpopup')[0].style.display = 'none';
                    }
                }
            }
            switch (e.action) {
                case 'home':
                    if (ganttObj.selectionModule && ganttObj.selectionSettings.mode !== 'Cell') {
                        if (ganttObj.selectedRowIndex === 0) {
                            return;
                        }
                        Eif (ganttObj.selectionModule && ganttObj.selectionModule.getCellSelectedRecords().length === 0) {
                            ganttObj.selectionModule.selectRow(0, false, true);
                        }
                    }
                    break;
                case 'end':
                    Eif (ganttObj.selectionModule && ganttObj.selectionSettings.mode !== 'Cell') {
                        var currentSelectingRecord = expandedRecords[expandedRecords.length - 1];
                        Iif (ganttObj.selectedRowIndex === ganttObj.flatData.indexOf(currentSelectingRecord)) {
                            return;
                        }
                        Eif (ganttObj.selectionModule && ganttObj.selectionModule.getCellSelectedRecords().length === 0) {
                            ganttObj.selectionModule.selectRow(ganttObj.flatData.indexOf(currentSelectingRecord), false, true);
                        }
                    }
                    break;
                case 'downArrow':
                case 'upArrow':
                    {
                        var searchElement = ganttObj.element.querySelector('#' + ganttObj.element.id + '_searchbar');
                        Iif (searchElement && searchElement.parentElement.classList.contains('e-input-focus')) {
                            ganttObj.selectionModule.clearSelection();
                        }
                        Eif (!ganttObj.element.classList.contains('e-scroll-disabled')) {
                            this.upDownKeyNavigate(e);
                            if (!ej2_base_1.isNullOrUndefined(targetElement) && !ej2_base_1.isNullOrUndefined(targetElement.closest('.e-chart-row'))) {
                                ganttObj.ganttChartModule.manageFocus(this.getActiveElement(), 'remove', true, e.action);
                            }
                            Iif (ganttObj.selectionSettings && ganttObj.selectionSettings.mode === 'Both' && e.target instanceof HTMLElement && e.target.classList.contains('e-cellselectionbackground')) {
                                e.target.classList.remove('e-cellselectionbackground');
                            }
                        }
                        break;
                    }
                case 'expandAll':
                    ganttObj.ganttChartModule.expandCollapseAll('expand');
                    break;
                case 'collapseAll':
                    ganttObj.ganttChartModule.expandCollapseAll('collapse');
                    break;
                case 'expandRow':
                case 'collapseRow':
                    this.expandCollapseKey(e);
                    break;
                case 'saveRequest':
                    if (!ej2_base_1.isNullOrUndefined(ganttObj.editModule) && !ej2_base_1.isNullOrUndefined(ganttObj.editModule.cellEditModule) &&
                        ganttObj.editModule.cellEditModule.isCellEdit) {
                        var col = ganttObj.editModule.cellEditModule.editedColumn;
                        if (col.field === ganttObj.columnMapping.duration && !ej2_base_1.isNullOrUndefined(col.edit) &&
                            !ej2_base_1.isNullOrUndefined(col.edit.read)) {
                            var textBox = e.target.ej2_instances[0];
                            var textValue = e.target.value;
                            var tempValue = void 0;
                            Eif (col.field === ganttObj.columnMapping.duration) {
                                Eif (!ej2_base_1.isNullOrUndefined(col.edit) && !ej2_base_1.isNullOrUndefined(col.edit.read)) {
                                    tempValue = col.edit.read();
                                }
                                Eif (textValue !== tempValue.toString()) {
                                    textBox.value = textValue;
                                    textBox.dataBind();
                                }
                            }
                        }
                        Iif (ganttObj.editModule.dialogModule.dialogObj && ej2_base_1.getValue('dialogOpen', ganttObj.editModule.dialogModule.dialogObj)) {
                            return;
                        }
                        ganttObj.treeGrid.grid.saveCell();
                        var focussedElement = ganttObj.element.querySelector('.e-treegrid');
                        focussedElement.focus();
                    }
                    if (!ej2_base_1.isNullOrUndefined(targetElement)
                        && !ej2_base_1.isNullOrUndefined(targetElement.closest('.e-chart-row'))) {
                        var target = e.target;
                        var taskbarElement = targetElement.querySelector('.e-gantt-parent-taskbar,' +
                            '.e-gantt-child-taskbar,.e-gantt-milestone');
                        Eif (taskbarElement) {
                            this.parent.ganttChartModule.onTaskbarClick(e, target, taskbarElement);
                        }
                    }
                    break;
                case 'cancelRequest':
                    Eif (!ej2_base_1.isNullOrUndefined(ganttObj.editModule) && !ej2_base_1.isNullOrUndefined(ganttObj.editModule.cellEditModule)) {
                        ganttObj.editModule.cellEditModule.isCellEdit = false;
                        Eif (!ej2_base_1.isNullOrUndefined(ganttObj.toolbarModule)) {
                            ganttObj.toolbarModule.refreshToolbarItems();
                        }
                    }
                    break;
                case 'addRow':
                    {
                        Iif (ganttObj.editModule && ganttObj.editModule.cellEditModule && ganttObj.editModule.cellEditModule.isCellEdit) {
                            e.stopPropagation();
                        }
                        else if (ej2_base_1.isNullOrUndefined(document.getElementById(this.parent.element.id + '_dialog'))) {
                            e.preventDefault();
                            ganttObj.addRecord(undefined, this.parent.editSettings.newRowPosition, this.parent.selectedRowIndex);
                            var focussedElement = ganttObj.element;
                            focussedElement.focus();
                        }
                        break;
                    }
                case 'addRowDialog':
                    e.preventDefault();
                    Eif (ganttObj.editModule && ganttObj.editModule.dialogModule && ganttObj.editSettings.allowAdding) {
                        Iif (ganttObj.editModule.dialogModule.dialogObj && ej2_base_1.getValue('dialogOpen', ganttObj.editModule.dialogModule.dialogObj)) {
                            return;
                        }
                        ganttObj.editModule.dialogModule.openAddDialog();
                    }
                    break;
                case 'editRowDialog':
                    {
                        e.preventDefault();
                        var focussedTreeElement = ganttObj.element.querySelector('.e-treegrid');
                        focussedTreeElement.focus();
                        Eif (ganttObj.editModule && ganttObj.editModule.dialogModule && ganttObj.editSettings.allowEditing) {
                            Iif (ganttObj.editModule.dialogModule.dialogObj && ej2_base_1.getValue('dialogOpen', ganttObj.editModule.dialogModule.dialogObj)) {
                                return;
                            }
                            ganttObj.editModule.dialogModule.openToolbarEditDialog();
                        }
                        break;
                    }
                case 'delete':
                    Eif (ganttObj.selectionModule && ganttObj.editModule && ganttObj.editModule.dialogModule &&
                        (!ganttObj.editModule.dialogModule.dialogObj || (ganttObj.editModule.dialogModule.dialogObj &&
                            !ganttObj.editModule.dialogModule.dialogObj.visible)) && (!ganttObj.editSettings.allowTaskbarEditing
                        || (ganttObj.editSettings.allowTaskbarEditing && !ganttObj.editModule.taskbarEditModule.touchEdit))) {
                        Eif ((ganttObj.selectionSettings.mode !== 'Cell' && ganttObj.selectionModule.selectedRowIndexes.length)
                            || (ganttObj.selectionSettings.mode === 'Cell' && ganttObj.selectionModule.getSelectedRowCellIndexes().length)) {
                            if (!ej2_base_1.isNullOrUndefined(e.target)) {
                                Iif (e.target['tagName'] !== 'INPUT') {
                                    ganttObj.editModule.startDeleteAction();
                                }
                            }
                            else {
                                ganttObj.editModule.startDeleteAction();
                            }
                        }
                    }
                    break;
                case 'focusTask':
                    {
                        e.preventDefault();
                        var selectedId = void 0;
                        Eif (ganttObj.selectionModule) {
                            var currentViewData = ganttObj.currentViewData;
                            if (ganttObj.selectionSettings.mode !== 'Cell' &&
                                !ej2_base_1.isNullOrUndefined(currentViewData[ganttObj.selectedRowIndex])) {
                                selectedId = ganttObj.currentViewData[ganttObj.selectedRowIndex].ganttProperties.rowUniqueID;
                            }
                            else Iif (ganttObj.selectionSettings.mode === 'Cell' &&
                                ganttObj.selectionModule.getSelectedRowCellIndexes().length > 0) {
                                var selectCellIndex = ganttObj.selectionModule.getSelectedRowCellIndexes();
                                selectedId = currentViewData[selectCellIndex[selectCellIndex.length - 1].rowIndex].ganttProperties.rowUniqueID;
                            }
                        }
                        if (selectedId) {
                            ganttObj.scrollToTask(selectedId.toString());
                        }
                        break;
                    }
                case 'focusSearch':
                    {
                        Eif (ganttObj.element.querySelector('#' + ganttObj.element.id + '_searchbar')) {
                            var searchElement = ganttObj.element.querySelector('#' + ganttObj.element.id + '_searchbar');
                            searchElement.setAttribute('tabIndex', '-1');
                            searchElement.focus();
                        }
                        break;
                    }
                case 'tab':
                case 'shiftTab':
                    Eif (!ganttObj.element.classList.contains('e-scroll-disabled')) {
                        ganttObj.ganttChartModule.onTabAction(e);
                    }
                    break;
                case 'contextMenu':
                    {
                        var contextMenu = document.getElementById(this.parent.element.id +
                            '_contextmenu').ej2_instances[0];
                        var containerPosition = this.parent.getOffsetRect(e.target);
                        var top_1 = containerPosition.top + (containerPosition.height / 2);
                        var left = containerPosition.left + (containerPosition.width / 2);
                        this.setActiveElement(e.target);
                        contextMenu.open(top_1, left);
                        e.preventDefault();
                        break;
                    }
                case 'undo':
                    {
                        Eif (this.parent.undoRedoModule && this.parent.undoRedoModule['getUndoCollection'].length > 0) {
                            this.parent.undo();
                        }
                        break;
                    }
                case 'redo':
                    {
                        Eif (this.parent.undoRedoModule && this.parent.undoRedoModule['getRedoCollection'].length > 0) {
                            this.parent.redo();
                        }
                        break;
                    }
                case 'selectAll':
                    {
                        e.preventDefault();
                        var ganttRow = [].slice.call(this.parent.ganttChartModule.chartBodyContent.querySelector('tbody').children);
                        Eif (ganttRow.length > 0) {
                            var firstRowIndex = ganttRow[0].getAttribute('data-rowindex');
                            var lastRowIndex = ganttRow[ganttRow.length - 1].getAttribute('data-rowindex');
                            Eif (!ej2_base_1.isNullOrUndefined(firstRowIndex)) {
                                firstRowIndex = Number(firstRowIndex);
                            }
                            Eif (!ej2_base_1.isNullOrUndefined(lastRowIndex)) {
                                lastRowIndex = Number(lastRowIndex);
                            }
                            Eif (!ej2_base_1.isNullOrUndefined(firstRowIndex) && !ej2_base_1.isNullOrUndefined(lastRowIndex)) {
                                this.parent.selectionModule.selectRowsByRange(firstRowIndex, lastRowIndex);
                            }
                        }
                        break;
                    }
                default:
                    {
                        var eventArgs = {
                            requestType: 'keyPressed',
                            action: e.action,
                            keyEvent: e
                        };
                        ganttObj.trigger('actionComplete', eventArgs);
                        break;
                    }
            }
        };
        FocusModule.prototype.upDownKeyNavigate = function (e) {
            e.preventDefault();
            var ganttObj = this.parent;
            var expandedRecords;
            if ((e.action === 'downArrow' || e.action === 'upArrow') && this.parent.selectionModule && this.parent.allowSelection && this.parent.virtualScrollModule && this.parent.enableVirtualization) {
                expandedRecords = ganttObj.getExpandedRecords(ganttObj.flatData);
            }
            else {
                expandedRecords = ganttObj.getExpandedRecords(ganttObj.currentViewData);
            }
            Eif (ganttObj.selectionModule) {
                if (ganttObj.selectionSettings.mode !== 'Cell' && ganttObj.selectedRowIndex !== -1) {
                    var selectedItem = void 0;
                    if ((e.action === 'downArrow' || e.action === 'upArrow') && this.parent.selectionModule && this.parent.allowSelection && this.parent.virtualScrollModule && this.parent.enableVirtualization) {
                        selectedItem = ganttObj.flatData[ganttObj.selectedRowIndex];
                    }
                    else {
                        selectedItem = ganttObj.currentViewData[ganttObj.selectedRowIndex];
                    }
                    var focussedElement = ganttObj.element.querySelector('.e-focused');
                    Iif (focussedElement) {
                        ej2_base_1.removeClass([focussedElement], 'e-focused');
                    }
                    var selectingRowIndex = expandedRecords.indexOf(selectedItem);
                    var currentSelectingRecord = e.action === 'downArrow' ? expandedRecords[selectingRowIndex + 1] :
                        expandedRecords[selectingRowIndex - 1];
                    var activeElement = this.parent['args'];
                    Eif (document.activeElement !== activeElement) {
                        if ((e.action === 'downArrow' || e.action === 'upArrow') && this.parent.selectionModule && this.parent.allowSelection && this.parent.virtualScrollModule && this.parent.enableVirtualization) {
                            ganttObj.selectionModule.selectRow(ganttObj.flatData.indexOf(currentSelectingRecord), false, true);
                        }
                        else {
                            ganttObj.selectionModule.selectRow(ganttObj.currentViewData.indexOf(currentSelectingRecord), false, true);
                        }
                    }
                }
                else if (ganttObj.selectionSettings.mode === 'Cell' && ganttObj.selectionModule.getSelectedRowCellIndexes().length > 0) {
                    var selectCellIndex = ganttObj.selectionModule.getSelectedRowCellIndexes();
                    var selectedCellItem = selectCellIndex[selectCellIndex.length - 1];
                    var currentCellIndex = selectedCellItem.cellIndexes[selectedCellItem.cellIndexes.length - 1];
                    var selectedItem = ganttObj.currentViewData[selectedCellItem.rowIndex];
                    var selectingRowIndex = expandedRecords.indexOf(selectedItem);
                    var currentSelectingRecord = e.action === 'downArrow' ? expandedRecords[selectingRowIndex + 1] :
                        expandedRecords[selectingRowIndex - 1];
                    var cellInfo = {
                        rowIndex: ganttObj.currentViewData.indexOf(currentSelectingRecord),
                        cellIndex: currentCellIndex
                    };
                    ganttObj.selectionModule.selectCell(cellInfo);
                }
                this.parent.ganttChartModule.focusedRowIndex = this.parent.selectedRowIndex;
            }
        };
        FocusModule.prototype.expandCollapseKey = function (e) {
            var ganttObj = this.parent;
            Eif (ganttObj.selectionModule && ganttObj.selectedRowIndex !== -1) {
                var selectedRowIndex_1;
                if (ganttObj.selectionSettings.mode !== 'Cell') {
                    selectedRowIndex_1 = ganttObj.selectedRowIndex;
                }
                else Iif (ganttObj.selectionSettings.mode === 'Cell' && ganttObj.selectionModule.getSelectedRowCellIndexes().length > 0) {
                    var selectCellIndex = ganttObj.selectionModule.getSelectedRowCellIndexes();
                    selectedRowIndex_1 = selectCellIndex[selectCellIndex.length - 1].rowIndex;
                }
                Iif (this.parent.virtualScrollModule && this.parent.enableVirtualization) {
                    selectedRowIndex_1 = this.parent.currentViewData.findIndex(function (obj) { return obj.ganttProperties.rowUniqueID ===
                        selectedRowIndex_1.toString(); }) + 1;
                }
                if (e.action === 'expandRow') {
                    ganttObj.expandByIndex(selectedRowIndex_1);
                }
                else {
                    ganttObj.collapseByIndex(selectedRowIndex_1);
                }
            }
        };
        return FocusModule;
    }());
    exports.FocusModule = FocusModule;
});