2019-01-02 10:24:12 +00:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
|
|
|
// Copyright (C) 2013 - 2019, The pgAdmin Development Team
|
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2018-02-27 11:18:36 +00:00
|
|
|
import $ from 'jquery';
|
|
|
|
import Mousetrap from 'mousetrap';
|
|
|
|
import { findAndSetFocus } from './utils';
|
|
|
|
import { parseShortcutValue } from './utils';
|
|
|
|
|
|
|
|
class dialogTabNavigator {
|
2019-01-22 10:58:32 +00:00
|
|
|
constructor(dialogContainer, backwardShortcut, forwardShortcut) {
|
2018-02-27 11:18:36 +00:00
|
|
|
|
2019-01-22 10:58:32 +00:00
|
|
|
this.dialogContainer = dialogContainer;
|
2018-02-27 11:18:36 +00:00
|
|
|
|
|
|
|
this.tabSwitching = false;
|
|
|
|
|
2019-01-22 10:58:32 +00:00
|
|
|
this.tabs = this.dialogContainer.find('.nav-tabs');
|
2018-02-27 11:18:36 +00:00
|
|
|
|
|
|
|
if (this.tabs.length > 0 ) {
|
|
|
|
this.tabs = this.tabs[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dialogTabBackward = parseShortcutValue(backwardShortcut);
|
|
|
|
this.dialogTabForward = parseShortcutValue(forwardShortcut);
|
|
|
|
|
2019-01-22 10:58:32 +00:00
|
|
|
Mousetrap(this.dialogContainer[0]).bind(this.dialogTabBackward, this.onKeyboardEvent.bind(this));
|
|
|
|
Mousetrap(this.dialogContainer[0]).bind(this.dialogTabForward, this.onKeyboardEvent.bind(this));
|
2018-02-27 11:18:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
onKeyboardEvent(event, shortcut) {
|
2019-01-22 10:58:32 +00:00
|
|
|
var currentTabPane = this.dialogContainer
|
2018-02-27 11:18:36 +00:00
|
|
|
.find('.tab-content:first > .tab-pane.active:first'),
|
|
|
|
childTabData = this.isActivePaneHasChildTabs(currentTabPane);
|
|
|
|
|
|
|
|
if (this.tabSwitching) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.tabSwitching = true;
|
|
|
|
|
|
|
|
if(childTabData) {
|
|
|
|
var res = this.navigate(shortcut, childTabData.childTab,
|
2019-07-11 09:14:01 +00:00
|
|
|
childTabData.childTabPane, event);
|
2018-02-27 11:18:36 +00:00
|
|
|
|
|
|
|
if (!res) {
|
2019-07-11 09:14:01 +00:00
|
|
|
this.navigate(shortcut, this.tabs, currentTabPane, event);
|
2018-02-27 11:18:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-07-11 09:14:01 +00:00
|
|
|
this.navigate(shortcut, this.tabs, currentTabPane, event);
|
2018-02-27 11:18:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isActivePaneHasChildTabs(currentTabPane) {
|
|
|
|
var childTab = currentTabPane.find('.nav-tabs:first'),
|
|
|
|
childTabPane;
|
|
|
|
|
|
|
|
if (childTab.length > 0) {
|
|
|
|
childTabPane = currentTabPane
|
|
|
|
.find('.tab-content:first > .tab-pane.active:first');
|
|
|
|
|
|
|
|
return {
|
|
|
|
'childTab': childTab,
|
|
|
|
'childTabPane': childTabPane,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-07-11 09:14:01 +00:00
|
|
|
navigate(shortcut, tabs, tab_pane, event) {
|
|
|
|
if (shortcut == this.dialogTabBackward) {
|
|
|
|
return this.navigateBackward(tabs, tab_pane, event);
|
|
|
|
} else if (shortcut == this.dialogTabForward) {
|
|
|
|
return this.navigateForward(tabs, tab_pane, event);
|
2018-02-27 11:18:36 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-11 09:14:01 +00:00
|
|
|
navigateBackward(tabs, tab_pane, event) {
|
2018-02-27 11:18:36 +00:00
|
|
|
var self = this,
|
|
|
|
nextTabPane,
|
|
|
|
innerTabContainer,
|
2019-01-22 10:58:32 +00:00
|
|
|
prevtab = $(tabs).find('li').has('a.active').prev('li');
|
2018-02-27 11:18:36 +00:00
|
|
|
|
|
|
|
if (prevtab.length > 0) {
|
|
|
|
prevtab.find('a').tab('show');
|
|
|
|
|
|
|
|
nextTabPane = tab_pane.prev();
|
|
|
|
innerTabContainer = nextTabPane
|
|
|
|
.find('.tab-content:first > .tab-pane.active:first');
|
|
|
|
|
|
|
|
if (innerTabContainer.length > 0) {
|
|
|
|
findAndSetFocus(innerTabContainer);
|
|
|
|
} else {
|
|
|
|
findAndSetFocus(nextTabPane);
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
self.tabSwitching = false;
|
|
|
|
}, 200);
|
|
|
|
|
2019-07-11 09:14:01 +00:00
|
|
|
event.stopPropagation();
|
2018-02-27 11:18:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.tabSwitching = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-11 09:14:01 +00:00
|
|
|
navigateForward(tabs, tab_pane, event) {
|
2018-02-27 11:18:36 +00:00
|
|
|
var self = this,
|
|
|
|
nextTabPane,
|
|
|
|
innerTabContainer,
|
2019-01-22 10:58:32 +00:00
|
|
|
nexttab = $(tabs).find('li').has('a.active').next('li');
|
2018-02-27 11:18:36 +00:00
|
|
|
|
|
|
|
if(nexttab.length > 0) {
|
|
|
|
nexttab.find('a').tab('show');
|
|
|
|
|
|
|
|
nextTabPane = tab_pane.next();
|
|
|
|
innerTabContainer = nextTabPane
|
|
|
|
.find('.tab-content:first > .tab-pane.active:first');
|
|
|
|
|
|
|
|
if (innerTabContainer.length > 0) {
|
|
|
|
findAndSetFocus(innerTabContainer);
|
|
|
|
} else {
|
|
|
|
findAndSetFocus(nextTabPane);
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
self.tabSwitching = false;
|
|
|
|
}, 200);
|
|
|
|
|
2019-07-11 09:14:01 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
|
2018-02-27 11:18:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
this.tabSwitching = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
detach() {
|
2019-01-22 10:58:32 +00:00
|
|
|
Mousetrap(this.dialogContainer[0]).unbind(this.dialogTabBackward);
|
|
|
|
Mousetrap(this.dialogContainer[0]).unbind(this.dialogTabForward);
|
2018-02-27 11:18:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
dialogTabNavigator: dialogTabNavigator,
|
2019-01-22 10:58:32 +00:00
|
|
|
};
|