2013-03-15 12:28:43 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-releeph-request-state-change
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
|
|
|
* javelin-stratcom
|
2014-04-18 15:44:45 +02:00
|
|
|
* javelin-workflow
|
|
|
|
* javelin-util
|
2013-03-15 12:28:43 +01:00
|
|
|
* phabricator-keyboard-shortcut
|
|
|
|
*/
|
|
|
|
|
2014-06-23 19:27:47 +02:00
|
|
|
JX.behavior('releeph-request-state-change', function() {
|
2013-03-15 12:28:43 +01:00
|
|
|
function getRequestHeaderNodes() {
|
2014-04-18 15:44:45 +02:00
|
|
|
return JX.DOM.scry(document.body, 'div', 'releeph-request-box');
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var keynav_cursor = -1;
|
|
|
|
|
|
|
|
function keynavJump(manager, delta) {
|
|
|
|
// Calculate this everytime, because the DOM changes.
|
|
|
|
var headers = getRequestHeaderNodes();
|
|
|
|
keynav_cursor += delta;
|
|
|
|
|
|
|
|
if (keynav_cursor < 0) {
|
|
|
|
keynav_cursor = -1;
|
2015-01-25 17:42:40 +01:00
|
|
|
JX.DOM.scrollToPosition(0, 0);
|
2013-03-15 12:28:43 +01:00
|
|
|
keynavMarkup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keynav_cursor >= headers.length) {
|
|
|
|
keynav_cursor = headers.length - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
var focus = headers[keynav_cursor];
|
|
|
|
manager.scrollTo(focus);
|
|
|
|
|
|
|
|
keynavMarkup();
|
|
|
|
}
|
|
|
|
|
|
|
|
function keynavMarkup() {
|
|
|
|
var headers = getRequestHeaderNodes();
|
2013-05-19 02:04:22 +02:00
|
|
|
for (var k in headers) {
|
|
|
|
JX.DOM.alterClass(headers[k], 'focus', k == keynav_cursor);
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function keynavAction(manager, action_name) {
|
|
|
|
var headers = getRequestHeaderNodes();
|
|
|
|
var header = headers[keynav_cursor];
|
|
|
|
|
|
|
|
if (keynav_cursor < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var sigil = action_name;
|
|
|
|
var button = JX.DOM.find(header, 'a', sigil);
|
|
|
|
if (button) {
|
|
|
|
button.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function keynavNavigateToRequestPage() {
|
|
|
|
var headers = getRequestHeaderNodes();
|
|
|
|
var header = headers[keynav_cursor];
|
2014-04-18 15:44:45 +02:00
|
|
|
window.open(JX.Stratcom.getData(header).uri);
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
new JX.KeyboardShortcut('j', 'Jump to next request.')
|
|
|
|
.setHandler(function(manager) {
|
|
|
|
keynavJump(manager, +1);
|
|
|
|
})
|
|
|
|
.register();
|
|
|
|
|
|
|
|
new JX.KeyboardShortcut('k', 'Jump to previous request.')
|
|
|
|
.setHandler(function(manager) {
|
|
|
|
keynavJump(manager, -1);
|
|
|
|
})
|
|
|
|
.register();
|
|
|
|
|
|
|
|
new JX.KeyboardShortcut('a', 'Approve the selected request.')
|
|
|
|
.setHandler(function(manager) {
|
|
|
|
keynavAction(manager, 'want');
|
|
|
|
})
|
|
|
|
.register();
|
|
|
|
|
|
|
|
new JX.KeyboardShortcut('r', 'Reject the selected request.')
|
|
|
|
.setHandler(function(manager) {
|
|
|
|
keynavAction(manager, 'pass');
|
|
|
|
})
|
|
|
|
.register();
|
|
|
|
|
2014-04-18 15:44:45 +02:00
|
|
|
new JX.KeyboardShortcut(
|
|
|
|
['g', 'return'],
|
2015-01-19 22:53:47 +01:00
|
|
|
'Open selected request\'s page in a new tab.')
|
2014-06-23 19:27:47 +02:00
|
|
|
.setHandler(function() {
|
2013-03-15 12:28:43 +01:00
|
|
|
keynavNavigateToRequestPage();
|
|
|
|
})
|
|
|
|
.register();
|
|
|
|
|
2014-04-18 15:44:45 +02:00
|
|
|
function onresponse(box, response) {
|
|
|
|
JX.DOM.replace(box, JX.$H(response.markup));
|
|
|
|
keynavMarkup();
|
2013-03-15 12:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
|
|
|
'releeph-request-state-change',
|
|
|
|
function(e) {
|
2014-04-18 15:44:45 +02:00
|
|
|
e.kill();
|
2013-03-15 12:28:43 +01:00
|
|
|
|
2014-04-18 15:44:45 +02:00
|
|
|
var box = e.getNode('releeph-request-box');
|
|
|
|
var link = e.getNode('releeph-request-state-change');
|
2013-03-15 12:28:43 +01:00
|
|
|
|
2014-04-18 15:44:45 +02:00
|
|
|
box.style.opacity = '0.5';
|
2013-03-15 12:28:43 +01:00
|
|
|
|
2014-04-18 15:44:45 +02:00
|
|
|
JX.Workflow.newFromLink(link)
|
|
|
|
.setData({render: true})
|
|
|
|
.setHandler(JX.bind(null, onresponse, box))
|
|
|
|
.start();
|
|
|
|
});
|
2013-03-15 12:28:43 +01:00
|
|
|
});
|