diff --git a/web/pgadmin/browser/static/js/keyboard.js b/web/pgadmin/browser/static/js/keyboard.js index 3499f004..e4e1da1d 100644 --- a/web/pgadmin/browser/static/js/keyboard.js +++ b/web/pgadmin/browser/static/js/keyboard.js @@ -1,16 +1,16 @@ import _ from 'underscore'; -import pgAdmin from 'sources/pgadmin'; +import pgAdmin from '../../../static/js/pgadmin'; import $ from 'jquery'; import Mousetrap from 'mousetrap'; -import * as commonUtils from 'sources/utils'; -import dialogTabNavigator from 'sources/dialog_tab_navigator'; +import * as commonUtils from '../../../static/js/utils'; +import dialogTabNavigator from '../../../static/js/dialog_tab_navigator'; const pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {}; pgBrowser.keyboardNavigation = pgBrowser.keyboardNavigation || {}; _.extend(pgBrowser.keyboardNavigation, { - init: function () { + init: function() { Mousetrap.reset(); if (pgBrowser.preferences_cache.length > 0) { this.keyboardShortcut = { @@ -53,17 +53,17 @@ _.extend(pgBrowser.keyboardNavigation, { this.bindShortcuts(); } }, - bindShortcuts: function () { + bindShortcuts: function() { const self = this; - _.each(self.shortcutMethods, function (keyCombo, callback) { + _.each(self.shortcutMethods, (keyCombo, callback) => { self._bindWithMousetrap(keyCombo.shortcuts, self[callback], keyCombo.bindElem); }); }, - _bindWithMousetrap: function (shortcuts, callback, bindElem) { + _bindWithMousetrap: function(shortcuts, callback, bindElem) { const self = this; if (bindElem) { const elem = document.querySelector(bindElem); - Mousetrap(elem).bind(shortcuts, function () { + Mousetrap(elem).bind(shortcuts, function() { callback.apply(this, arguments); }.bind(elem)); } else { @@ -72,14 +72,14 @@ _.extend(pgBrowser.keyboardNavigation, { }); } }, - bindMainMenu: function (e, combo) { + bindMainMenu: function(event, combo) { const shortcut_obj = this.keyboardShortcut; if (combo === shortcut_obj.file_shortcut) $('#mnu_file a.dropdown-toggle').dropdown('toggle'); if (combo === shortcut_obj.object_shortcut) $('#mnu_obj a.dropdown-toggle').first().dropdown('toggle'); if (combo === shortcut_obj.tools_shortcut) $('#mnu_tools a.dropdown-toggle').dropdown('toggle'); if (combo === shortcut_obj.help_shortcut) $('#mnu_help a.dropdown-toggle').dropdown('toggle'); }, - bindRightPanel: function (e, combo) { + bindRightPanel: function(event, combo) { let allPanels = pgAdmin.Browser.docker.findPanels(); let activePanel = 0; let nextPanel = allPanels.length; @@ -88,7 +88,7 @@ _.extend(pgBrowser.keyboardNavigation, { let activePanelFlag = false; let shortcut_obj = this.keyboardShortcut; - _.each(pgAdmin.Browser.docker.findPanels(), function (panel, index) { + _.each(pgAdmin.Browser.docker.findPanels(), (panel, index) => { if (panel.isVisible() && !activePanelFlag && panel._type !== 'browser') { activePanelId = index; activePanelFlag = true; @@ -99,65 +99,65 @@ _.extend(pgBrowser.keyboardNavigation, { else if (combo === shortcut_obj.tabbed_panel_forward) activePanel = (activePanelId < nextPanel) ? activePanelId + 1 : nextPanel; pgAdmin.Browser.docker.findPanels()[activePanel].focus(); - setTimeout(function () { + setTimeout(() => { if (document.activeElement instanceof HTMLIFrameElement) { document.activeElement.blur(); } }, 1000); }, - bindMainMenuLeft: function (e) { + bindMainMenuLeft: function(event) { let prevMenu; - if ($(e.target).hasClass('menu-link')) { // Menu items - prevMenu = $(e.target).parent().parent().parent().prev('.dropdown'); + if ($(event.target).hasClass('menu-link')) { // Menu items + prevMenu = $(event.target).parent().parent().parent().prev('.dropdown'); } - else if ($(e.target).parent().hasClass('dropdown-submenu')) { // Sub menu - $(e.target).parent().toggleClass('open'); + else if ($(event.target).parent().hasClass('dropdown-submenu')) { // Sub menu + $(event.target).parent().toggleClass('open'); return; } else { //Menu headers - prevMenu = $(e.target).parent().prev('.dropdown'); + prevMenu = $(event.target).parent().prev('.dropdown'); } if (prevMenu.hasClass('hide')) prevMenu = prevMenu.prev('.dropdown'); // Skip hidden menus prevMenu.find('a:first').dropdown('toggle'); }, - bindMainMenuRight: function (e) { + bindMainMenuRight: function(event) { let nextMenu; - if ($(e.target).hasClass('menu-link')) { // Menu items - nextMenu = $(e.target).parent().parent().parent().next('.dropdown'); + if ($(event.target).hasClass('menu-link')) { // Menu items + nextMenu = $(event.target).parent().parent().parent().next('.dropdown'); } - else if ($(e.target).parent().hasClass('dropdown-submenu')) { // Sub menu - $(e.target).parent().toggleClass('open'); + else if ($(event.target).parent().hasClass('dropdown-submenu')) { // Sub menu + $(event.target).parent().toggleClass('open'); return; } else { //Menu headers - nextMenu = $(e.target).parent().next('.dropdown'); + nextMenu = $(event.target).parent().next('.dropdown'); } if (nextMenu.hasClass('hide')) nextMenu = nextMenu.next('.dropdown'); // Skip hidden menus nextMenu.find('a:first').dropdown('toggle'); }, - bindMainMenuUpDown: function (e, combo) { + bindMainMenuUpDown: function(event, combo) { // Handle Sub-menus - if (combo === 'up' && $(e.target).parent().prev().prev('.dropdown-submenu').length > 0) { - $(e.target).parent().prev().prev('.dropdown-submenu').find('a:first').focus(); + if (combo === 'up' && $(event.target).parent().prev().prev('.dropdown-submenu').length > 0) { + $(event.target).parent().prev().prev('.dropdown-submenu').find('a:first').focus(); } else { - if ($(e.target).parent().hasClass('dropdown-submenu')) { - $(e.target).parent().parent().parent().find('a:first').dropdown('toggle'); - $(e.target).parent().parent().children().eq(2).find('a:first').focus(); + if ($(event.target).parent().hasClass('dropdown-submenu')) { + $(event.target).parent().parent().parent().find('a:first').dropdown('toggle'); + $(event.target).parent().parent().children().eq(2).find('a:first').focus(); } } }, - bindLeftTree: function () { + bindLeftTree: function() { const tree = this.getTreeDetails(); $('#tree').focus(); tree.t.focus(tree.i); tree.t.select(tree.i); }, - bindSubMenuQueryTool: function () { + bindSubMenuQueryTool: function() { const tree = this.getTreeDetails(); if (!tree.d) @@ -166,7 +166,7 @@ _.extend(pgBrowser.keyboardNavigation, { // Call data grid method to render query tool pgAdmin.DataGrid.show_query_tool('', tree.i); }, - bindSubMenuViewData: function () { + bindSubMenuViewData: function() { const tree = this.getTreeDetails(); if (!tree.d) @@ -175,7 +175,7 @@ _.extend(pgBrowser.keyboardNavigation, { // Call data grid method to render view data pgAdmin.DataGrid.show_data_grid({'mnuid': 1}, tree.i); }, - bindSubMenuProperties: function () { + bindSubMenuProperties: function() { const tree = this.getTreeDetails(); if (!tree.d || pgAdmin.Browser.Nodes[tree.t.itemData(tree.i)._type].collection_node === true) @@ -186,7 +186,7 @@ _.extend(pgBrowser.keyboardNavigation, { pgAdmin.Browser.Nodes[tree.t.itemData(tree.i)._type], {action: 'edit'} ); }, - bindSubMenuCreate: function () { + bindSubMenuCreate: function() { const tree = this.getTreeDetails(); if (!tree.d || pgAdmin.Browser.Nodes[tree.t.itemData(tree.i)._type].collection_node === true) @@ -197,7 +197,7 @@ _.extend(pgBrowser.keyboardNavigation, { pgAdmin.Browser.Nodes[tree.t.itemData(tree.i)._type], {action: 'create'} ); }, - bindSubMenuDelete: function () { + bindSubMenuDelete: function() { const tree = this.getTreeDetails(); if (!tree.d || pgAdmin.Browser.Nodes[tree.t.itemData(tree.i)._type].collection_node === true) @@ -206,25 +206,24 @@ _.extend(pgBrowser.keyboardNavigation, { // Call delete object callback pgAdmin.Browser.Node.callbacks.delete_obj.call(pgAdmin.Browser.Nodes[tree.t.itemData(tree.i)._type]); }, - bindSubMenuRefresh: function (e) { - e.preventDefault(); + bindSubMenuRefresh: function(event) { + event.preventDefault(); const tree = pgBrowser.keyboardNavigation.getTreeDetails(); // Call refresh object callback pgAdmin.Browser.Node.callbacks.refresh.call(pgAdmin.Browser.Nodes[tree.t.itemData(tree.i)._type]); }, - bindContextMenu: function (e) { + bindContextMenu: function(event) { const tree = this.getTreeDetails(); - const left = $(e.srcElement).find('.aciTreeEntry').position().left + 70; - const top = $(e.srcElement).find('.aciTreeEntry').position().top + 70; - e = window.event; + const left = $(event.srcElement).find('.aciTreeEntry').position().left + 70; + const top = $(event.srcElement).find('.aciTreeEntry').position().top + 70; tree.t.blur(tree.i); $('#tree').blur(); // Call context menu and set position tree.i.children().contextMenu({x: left, y: top}); }, - bindDirectDebugging: function () { + bindDirectDebugging: function() { const tree = this.getTreeDetails(); const type = tree.t.itemData(tree.i)._type; @@ -236,18 +235,18 @@ _.extend(pgBrowser.keyboardNavigation, { pgAdmin.Tools.Debugger.get_function_information(pgAdmin.Browser.Nodes[type]); } }, - getTreeDetails: function () { - const t = pgAdmin.Browser.tree; - const i = t.selected().length > 0 ? t.selected() : t.first(); - const d = i && i.length === 1 ? t.itemData(i) : undefined; + getTreeDetails: function() { + const aciTree = pgAdmin.Browser.tree; + const selectedTreeNode = aciTree.selected().length > 0 ? aciTree.selected() : aciTree.first(); + const selectedTreeNodeData = selectedTreeNode && selectedTreeNode.length === 1 ? aciTree.itemData(selectedTreeNode) : undefined; return { - t: t, - i: i, - d: d, + t: aciTree, + i: selectedTreeNode, + d: selectedTreeNodeData, }; }, - getDialogTabNavigator: function (dialog) { + getDialogTabNavigator: function(dialog) { const backward_shortcut = pgBrowser.get_preference('browser', 'dialog_tab_backward').value; const forward_shortcut = pgBrowser.get_preference('browser', 'dialog_tab_forward').value; -- 2.16.2