1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 07:12:41 +01:00
phorge-phorge/webroot/rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js
epriestley cbe13b3065 When editing a tab panel from a dashboard, redirect back to the dashboard
Summary:
Depends on D20396. Ref T13272. Currently, using the dropdowns to edit a tab panel from a dashboard redirects you to the tab panel page.

Instead, redirect back to the context page (usually, a dashboard -- but theoretically a containing tab panel, since you can put tab panels inside tab panels).

Also, fix some JS issues with non-integer panel keys. I've moved panel keys from "0, 1, 2, ..." to having arbitrary keys to make some operations less flimsy/error-prone, but this needs some JS tweaks.

Test Plan: Edited a tab panel from a dashboard, got sent sensibly back to the dashboard.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13272

Differential Revision: https://secure.phabricator.com/D20397
2019-04-12 06:13:12 -07:00

52 lines
1.5 KiB
JavaScript

/**
* @provides javelin-behavior-dashboard-tab-panel
* @requires javelin-behavior
* javelin-dom
* javelin-stratcom
*/
JX.behavior('dashboard-tab-panel', function() {
JX.Stratcom.listen('click', 'dashboard-tab-panel-tab', function(e) {
// On dashboard panels in edit mode, the user may click the dropdown caret
// within a tab to open the context menu. If they do, this click should
// just open the menu, not select the tab. For now, pass the event here
// to let the menu handler act on it.
if (JX.Stratcom.pass(e)) {
return;
}
e.kill();
var selected_key = e.getNodeData('dashboard-tab-panel-tab').panelKey;
var root = e.getNode('dashboard-tab-panel-container');
var data = JX.Stratcom.getData(root);
var ii;
// Give the tab the user clicked a selected style, and remove it from
// the other tabs.
var tabs = JX.DOM.scry(root, 'li', 'dashboard-tab-panel-tab');
for (ii = 0; ii < tabs.length; ii++) {
var tab = tabs[ii];
var tab_data = JX.Stratcom.getData(tab);
var is_selected = (tab_data.panelKey === selected_key);
JX.DOM.alterClass(tabs[ii], 'phui-list-item-selected', is_selected);
}
// Switch the visible content to correspond to whatever the user clicked.
for (ii = 0; ii < data.panels.length; ii++) {
var panel = data.panels[ii];
var node = JX.$(panel.panelContentID);
if (panel.panelKey == selected_key) {
JX.DOM.show(node);
} else {
JX.DOM.hide(node);
}
}
});
});