1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12:41 +01:00
phorge-phorge/webroot/rsrc/js/application/differential/behavior-dropdown-menus.js
vrana 9c2b67e2dc Add button to reveal all files in Differential
Summary: D2216 tried to ask the user, this one is explicit.

Test Plan: Click the button

Reviewers: epriestley, lucian

Reviewed By: epriestley

CC: aran, Koolvin

Differential Revision: https://secure.phabricator.com/D2600
2012-05-30 10:44:37 -07:00

118 lines
3.3 KiB
JavaScript

/**
* @provides javelin-behavior-differential-dropdown-menus
* @requires javelin-behavior
* javelin-dom
* javelin-util
* javelin-stratcom
* phabricator-dropdown-menu
* phabricator-menu-item
*/
JX.behavior('differential-dropdown-menus', function(config) {
function show_more(container) {
var nodes = JX.DOM.scry(container, 'tr', 'context-target');
for (var ii = 0; ii < nodes.length; ii++) {
var show = JX.DOM.scry(nodes[ii], 'a', 'show-more');
for (var jj = 0; jj < show.length; jj++) {
if (JX.Stratcom.getData(show[jj]).type != 'all') {
continue;
}
var event_data = {
context : nodes[ii],
show : show[jj]
};
JX.Stratcom.invoke('differential-reveal-context', null, event_data);
}
}
}
function build_menu(button, data) {
function link_to(name, uri) {
var item = new JX.PhabricatorMenuItem(
name,
JX.bind(null, window.open, uri),
uri);
item.setDisabled(!uri);
return item;
}
var reveal_item = new JX.PhabricatorMenuItem('', function () {
show_more(JX.$(data.containerID));
});
var diffusion_item;
if (data.diffusionURI) {
// Show this only if we have a link, since when this appears in Diffusion
// it is otherwise potentially confusing.
diffusion_item = link_to('Browse in Diffusion', data.diffusionURI);
}
var menu = new JX.PhabricatorDropdownMenu(buttons[ii])
.addItem(reveal_item);
if (diffusion_item) {
menu.addItem(diffusion_item);
}
menu.addItem(link_to('View Standalone', data.standaloneURI));
if (data.leftURI) {
menu.addItem(link_to('Show Raw File (Left)', data.leftURI));
}
if (data.rightURI) {
menu.addItem(link_to('Show Raw File (Right)', data.rightURI));
}
if (data.editor) {
menu.addItem(new JX.PhabricatorMenuItem(
'Open in Editor',
JX.bind(null, location.assign, data.editor), // Open in the same window.
data.editor));
}
if (data.editorConfigure) {
menu.addItem(link_to('Configure Editor', data.editorConfigure));
}
menu.listen(
'open',
function() {
// When the user opens the menu, check if there are any "Show More"
// links in the changeset body. If there aren't, disable the "Show
// Entire File" menu item since it won't change anything.
var nodes = JX.DOM.scry(JX.$(data.containerID), 'a', 'show-more');
if (nodes.length) {
reveal_item.setDisabled(false);
reveal_item.setName('Show Entire File');
} else {
reveal_item.setDisabled(true);
reveal_item.setName('Entire File Shown');
}
});
}
var buttons = JX.DOM.scry(window.document, 'a', 'differential-view-options');
for (var ii = 0; ii < buttons.length; ii++) {
build_menu(buttons[ii], JX.Stratcom.getData(buttons[ii]));
}
JX.Stratcom.listen(
'click',
'differential-reveal-all',
function(e) {
var containers = JX.DOM.scry(
JX.$('differential-review-stage'),
'div',
'differential-changeset');
for (var i=0; i < containers.length; i++) {
show_more(containers[i]);
}
e.kill();
});
});