all files / common/actions/ keyboard.js

48.57% Statements 68/140
39.06% Branches 50/128
73.33% Functions 11/15
48.57% Lines 68/140
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   219×                     219× 219× 219×           13×                                                                                                                                                                                                                                                                       210× 210× 210×                
define(["require", "exports", "@syncfusion/ej2-base", "../base/css-constant", "@syncfusion/ej2-popups"], function (require, exports, ej2_base_1, cls, ej2_popups_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var CommonKeyboardInteraction = (function () {
        function CommonKeyboardInteraction(parent) {
            this.keyConfigs = {
                shiftF: 'shift+F',
                shiftS: 'shift+S',
                shiftE: 'shift+E',
                delete: 'delete',
                enter: 'enter',
                escape: 'escape',
                upArrow: 'upArrow',
                downArrow: 'downArrow',
                altJ: 'alt+J'
            };
            this.parent = parent;
            this.parent.element.tabIndex = this.parent.element.tabIndex === -1 ? 0 : this.parent.element.tabIndex;
            this.keyboardModule = new ej2_base_1.KeyboardEvents(this.parent.element, {
                keyAction: this.keyActionHandler.bind(this),
                keyConfigs: this.keyConfigs,
                eventName: 'keydown'
            });
        }
        CommonKeyboardInteraction.prototype.keyActionHandler = function (e) {
            switch (e.action) {
                case 'shiftF':
                    this.processFilter(e);
                    break;
                case 'shiftS':
                    this.processSort(e);
                    break;
                case 'shiftE':
                    this.processEdit(e);
                    break;
                case 'delete':
                    this.processDelete(e);
                    break;
                case 'enter':
                    this.processEnter(e);
                    break;
                case 'escape':
                    this.processClose(e);
                    break;
                case 'upArrow':
                case 'downArrow':
                    this.processFilterNodeSelection(e);
                    break;
                case 'altJ':
                    this.processComponentFocus(e);
            }
        };
        CommonKeyboardInteraction.prototype.processComponentFocus = function (e) {
            if (this.parent.element) {
                this.parent.element.focus();
                e.stopPropagation();
                e.preventDefault();
                return;
            }
        };
        CommonKeyboardInteraction.prototype.getButtonElement = function (target) {
            var allPivotButtons = [].slice.call(this.parent.element.querySelectorAll('.' + cls.PIVOT_BUTTON_CLASS));
            for (var i = 0, len = allPivotButtons.length; i < len; i++) {
                if (allPivotButtons[i].getAttribute('data-uid') === target.getAttribute('data-uid')) {
                    return allPivotButtons[i];
                }
            }
            return target;
        };
        CommonKeyboardInteraction.prototype.processEnter = function (e) {
            var target = e.target;
            if (target && ej2_base_1.closest(target, '.' + cls.PIVOT_BUTTON_CLASS)) {
                Eif (target.querySelector('.' + cls.AXISFIELD_ICON_CLASS) && ej2_base_1.closest(target, '.' + cls.VALUE_AXIS_CLASS)) {
                    target.querySelector('.' + cls.AXISFIELD_ICON_CLASS).click();
                }
                else if (target.querySelector('.' + cls.CALC_EDIT)) {
                    target.querySelector('.' + cls.CALC_EDIT).click();
                }
                else if (target.querySelector('.' + cls.SORT_CLASS) &&
                    !ej2_base_1.closest(target, '.' + cls.VALUE_AXIS_CLASS) && !ej2_base_1.closest(target, '.' + cls.AXIS_FILTER_CLASS)) {
                    target.querySelector('.' + cls.SORT_CLASS).click();
                    this.getButtonElement(target).focus();
                }
                else if (target.querySelector('.' + cls.FILTER_COMMON_CLASS) && !ej2_base_1.closest(target, '.' + cls.VALUE_AXIS_CLASS)) {
                    target.querySelector('.' + cls.FILTER_COMMON_CLASS).click();
                }
                e.preventDefault();
                return;
            }
        };
        CommonKeyboardInteraction.prototype.processSort = function (e) {
            var target = e.target;
            Eif (target && ej2_base_1.closest(target, '.' + cls.PIVOT_BUTTON_CLASS) && target.querySelector('.' + cls.SORT_CLASS) &&
                !ej2_base_1.closest(target, '.' + cls.VALUE_AXIS_CLASS) && !ej2_base_1.closest(target, '.' + cls.AXIS_FILTER_CLASS)) {
                target.querySelector('.' + cls.SORT_CLASS).click();
                this.getButtonElement(target).focus();
                e.preventDefault();
                return;
            }
        };
        CommonKeyboardInteraction.prototype.processEdit = function (e) {
            var target = e.target;
            if (target && ej2_base_1.closest(target, '.' + cls.PIVOT_BUTTON_CLASS) && target.querySelector('.' + cls.CALC_EDIT)) {
                target.querySelector('.' + cls.CALC_EDIT).click();
                e.preventDefault();
                return;
            }
        };
        CommonKeyboardInteraction.prototype.processFilter = function (e) {
            var target = e.target;
            Eif (target && ej2_base_1.closest(target, '.' + cls.PIVOT_BUTTON_CLASS) && target.querySelector('.' + cls.FILTER_COMMON_CLASS) &&
                !ej2_base_1.closest(target, '.' + cls.VALUE_AXIS_CLASS)) {
                target.querySelector('.' + cls.FILTER_COMMON_CLASS).click();
                if (this.parent && this.parent.control && this.parent.moduleName === 'pivotview' &&
                    this.parent.control.grid && this.parent.control.showGroupingBar &&
                    this.parent.control.groupingBarModule && ej2_base_1.closest(target, '.' + cls.GROUP_ROW_CLASS) &&
                    this.parent.filterDialog && this.parent.filterDialog.dialogPopUp &&
                    !this.parent.filterDialog.dialogPopUp.isDestroyed && this.parent.filterDialog.dialogPopUp.element) {
                    var dialogElement_1 = this.parent.filterDialog.dialogPopUp.element;
                    var isExcelFilter_1 = this.parent.filterDialog.allowExcelLikeFilter;
                    clearTimeout(this.timeOutObj);
                    this.timeOutObj = setTimeout(function () {
                        Eif (dialogElement_1 && dialogElement_1.classList.contains('e-popup-open')) {
                            Iif (isExcelFilter_1 && dialogElement_1.querySelector('.e-dlg-closeicon-btn')) {
                                dialogElement_1.querySelector('.e-dlg-closeicon-btn').focus();
                            }
                            else Eif (dialogElement_1.querySelector('input')) {
                                dialogElement_1.querySelector('input').focus();
                            }
                        }
                    });
                }
                e.preventDefault();
                return;
            }
        };
        CommonKeyboardInteraction.prototype.processFilterNodeSelection = function (e) {
            var target = e.target;
            if (target && ej2_base_1.closest(target, '.' + cls.SELECT_ALL_CLASS) && e.keyCode === 40) {
                var memberEditorTree = ej2_base_1.closest(target, '.' + cls.EDITOR_TREE_WRAPPER_CLASS).querySelector('.' + cls.EDITOR_TREE_CONTAINER_CLASS);
                if (memberEditorTree && memberEditorTree.querySelector('li')) {
                    var firstLi = memberEditorTree.querySelector('li');
                    if (memberEditorTree.querySelector('li#_active')) {
                        ej2_base_1.removeClass([memberEditorTree.querySelector('li#_active')], ['e-node-focus']);
                        memberEditorTree.querySelector('li#_active').removeAttribute('id');
                    }
                    firstLi.setAttribute('id', '_active');
                    ej2_base_1.addClass([firstLi], ['e-node-focus']);
                    firstLi.focus();
                    e.preventDefault();
                    return;
                }
            }
            else if (target && ej2_base_1.closest(target, '.' + cls.EDITOR_TREE_CONTAINER_CLASS) && e.keyCode === 38) {
                var memberEditorTree = ej2_base_1.closest(target, '.' + cls.EDITOR_TREE_CONTAINER_CLASS);
                if (memberEditorTree.querySelector('li#_active.e-node-focus') && memberEditorTree.querySelector('li') &&
                    memberEditorTree.querySelector('li').classList.contains('e-prev-active-node') &&
                    memberEditorTree.querySelector('li') === memberEditorTree.querySelector('li#_active.e-node-focus')) {
                    ej2_base_1.removeClass(memberEditorTree.querySelectorAll('li.e-prev-active-node'), 'e-prev-active-node');
                    var allMemberEditorTree = ej2_base_1.closest(target, '.' + cls.EDITOR_TREE_WRAPPER_CLASS).querySelector('.' + cls.SELECT_ALL_CLASS);
                    if (allMemberEditorTree && allMemberEditorTree.querySelector('li')) {
                        var firstLi = allMemberEditorTree.querySelector('li');
                        firstLi.setAttribute('id', '_active');
                        ej2_base_1.addClass([firstLi], ['e-node-focus']);
                        firstLi.focus();
                        e.preventDefault();
                        return;
                    }
                }
            }
            else if (target && target.id === this.parent.parentID + '_inputbox') {
                if (e.action === 'upArrow') {
                    target.parentElement.querySelector('.e-spin-up').click();
                }
                else if (e.action === 'downArrow') {
                    target.parentElement.querySelector('.e-spin-down').click();
                }
            }
        };
        CommonKeyboardInteraction.prototype.processDelete = function (e) {
            var target = e.target;
            Eif (target && ej2_base_1.closest(target, '.' + cls.PIVOT_BUTTON_CLASS) && target.querySelector('.' + cls.REMOVE_CLASS)) {
                target.querySelector('.' + cls.REMOVE_CLASS).click();
                e.preventDefault();
                return;
            }
        };
        CommonKeyboardInteraction.prototype.processClose = function (e) {
            var target = e.target;
            if (target && ej2_base_1.closest(target, '.e-popup.e-popup-open')) {
                var dialogInstance = ej2_base_1.getInstance(ej2_base_1.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;
                }
            }
        };
        CommonKeyboardInteraction.prototype.destroy = function () {
            Eif (this.keyboardModule) {
                this.keyboardModule.destroy();
                this.keyboardModule = null;
            }
            else {
                return;
            }
        };
        return CommonKeyboardInteraction;
    }());
    exports.CommonKeyboardInteraction = CommonKeyboardInteraction;
});