2012-01-05 01:52:13 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-differential-dropdown-menus
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
2012-01-05 23:41:11 +01:00
|
|
|
* javelin-util
|
2012-01-05 01:52:13 +01:00
|
|
|
* javelin-stratcom
|
|
|
|
* phabricator-dropdown-menu
|
|
|
|
* phabricator-menu-item
|
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('differential-dropdown-menus', function(config) {
|
|
|
|
|
2012-05-30 03:20:11 +02:00
|
|
|
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;
|
2012-01-06 05:29:16 +01:00
|
|
|
}
|
2012-05-30 03:20:11 +02:00
|
|
|
var event_data = {
|
|
|
|
context : nodes[ii],
|
|
|
|
show : show[jj]
|
|
|
|
};
|
|
|
|
JX.Stratcom.invoke('differential-reveal-context', null, event_data);
|
2012-01-06 05:29:16 +01:00
|
|
|
}
|
|
|
|
}
|
2012-05-30 03:20:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function build_menu(button, data) {
|
2012-01-05 23:41:11 +01:00
|
|
|
|
2012-01-06 05:29:16 +01:00
|
|
|
function link_to(name, uri) {
|
|
|
|
var item = new JX.PhabricatorMenuItem(
|
|
|
|
name,
|
2012-01-17 07:17:18 +01:00
|
|
|
JX.bind(null, window.open, uri),
|
|
|
|
uri);
|
2012-01-06 05:29:16 +01:00
|
|
|
item.setDisabled(!uri);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2012-05-30 03:20:11 +02:00
|
|
|
var reveal_item = new JX.PhabricatorMenuItem('', function () {
|
|
|
|
show_more(JX.$(data.containerID));
|
|
|
|
});
|
2012-01-05 01:52:13 +01:00
|
|
|
|
2012-03-20 03:57:41 +01:00
|
|
|
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);
|
2012-01-05 01:52:13 +01:00
|
|
|
}
|
|
|
|
|
2012-01-06 05:29:16 +01:00
|
|
|
var menu = new JX.PhabricatorDropdownMenu(buttons[ii])
|
2012-03-20 03:57:41 +01:00
|
|
|
.addItem(reveal_item);
|
|
|
|
|
2012-06-12 00:59:26 +02:00
|
|
|
var visible_item = new JX.PhabricatorMenuItem('', function () {
|
|
|
|
JX.Stratcom.invoke('differential-toggle-file', null, {
|
|
|
|
diff: JX.DOM.scry(JX.$(data.containerID), 'table', 'differential-diff'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
menu.addItem(visible_item);
|
|
|
|
|
2012-03-20 03:57:41 +01:00
|
|
|
if (diffusion_item) {
|
|
|
|
menu.addItem(diffusion_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
menu.addItem(link_to('View Standalone', data.standaloneURI));
|
|
|
|
|
2012-01-16 06:18:07 +01:00
|
|
|
if (data.leftURI) {
|
|
|
|
menu.addItem(link_to('Show Raw File (Left)', data.leftURI));
|
|
|
|
}
|
2012-03-20 03:57:41 +01:00
|
|
|
|
2012-01-16 06:18:07 +01:00
|
|
|
if (data.rightURI) {
|
|
|
|
menu.addItem(link_to('Show Raw File (Right)', data.rightURI));
|
|
|
|
}
|
2012-03-20 03:57:41 +01:00
|
|
|
|
2012-01-16 20:08:54 +01:00
|
|
|
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));
|
|
|
|
}
|
2012-03-20 03:57:41 +01:00
|
|
|
|
2012-01-16 20:08:54 +01:00
|
|
|
if (data.editorConfigure) {
|
|
|
|
menu.addItem(link_to('Configure Editor', data.editorConfigure));
|
|
|
|
}
|
2012-01-06 05:29:16 +01:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
2012-06-12 00:59:26 +02:00
|
|
|
|
2012-06-20 00:56:42 +02:00
|
|
|
var diffs = JX.DOM.scry(JX.$(data.containerID),
|
2012-06-12 00:59:26 +02:00
|
|
|
'table', 'differential-diff');
|
2012-06-20 00:56:42 +02:00
|
|
|
if (diffs.length > 1) {
|
|
|
|
JX.$E(
|
|
|
|
'More than one node with sigil "differential-diff" was found in "'+
|
|
|
|
data.containerID+'."');
|
|
|
|
} else if (diffs.length == 1) {
|
|
|
|
diff = diffs[0];
|
|
|
|
if (JX.Stratcom.getData(diff).hidden) {
|
|
|
|
visible_item.setName('Expand File');
|
|
|
|
} else {
|
|
|
|
visible_item.setName('Collapse File');
|
|
|
|
}
|
2012-06-12 00:59:26 +02:00
|
|
|
} else {
|
2012-06-20 00:56:42 +02:00
|
|
|
// Do nothing when there is no diff shown in the table. For example,
|
|
|
|
// the file is binary.
|
2012-06-12 00:59:26 +02:00
|
|
|
}
|
2012-01-06 05:29:16 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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]));
|
2012-01-05 01:52:13 +01:00
|
|
|
}
|
|
|
|
|
2012-05-30 03:20:11 +02:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2012-01-05 01:52:13 +01:00
|
|
|
});
|