2011-02-02 00:52:04 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-differential-edit-inline-comments
|
Bring Javelin into Phabricator via git submodule, not copy-and-paste
Summary:
Javelin is currently embedded in Phabricator via copy-and-paste of prebuilt
packages. This is not so great.
Pull it in as a submodule instead and make all the Phabriator resources declare
proper dependency trees. Add Javelin linting.
Test Plan:
I tried to run through pretty much all the JS functionality on the site. This is
still a high-risk change, but I did a pretty thorough test
Differential: inline comments, revealing diffs, list tokenizers, comment
preview, editing/deleting comments, add review action.
Maniphest: list tokenizer, comment actions
Herald: rule editing, tokenizers, add/remove rows
Reviewed By: tomo
Reviewers: aran, tomo, mroch, jungejason, tuomaspelkonen
CC: aran, tomo, epriestley
Differential Revision: 223
2011-05-04 00:11:55 +02:00
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-stratcom
|
|
|
|
* javelin-dom
|
|
|
|
* javelin-workflow
|
|
|
|
* javelin-vector
|
2011-02-02 00:52:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('differential-edit-inline-comments', function(config) {
|
|
|
|
|
|
|
|
var selecting = false;
|
|
|
|
var reticle = JX.$N('div', {className: 'differential-reticle'});
|
|
|
|
JX.DOM.hide(reticle);
|
|
|
|
document.body.appendChild(reticle);
|
|
|
|
|
|
|
|
var origin = null;
|
|
|
|
var target = null;
|
|
|
|
var root = null;
|
|
|
|
var changeset = null;
|
|
|
|
var workflow = false;
|
|
|
|
var is_new = false;
|
|
|
|
|
|
|
|
function updateReticle() {
|
|
|
|
var top = origin;
|
|
|
|
var bot = target;
|
|
|
|
if (JX.$V(top).y > JX.$V(bot).y) {
|
|
|
|
var tmp = top;
|
|
|
|
top = bot;
|
|
|
|
bot = tmp;
|
|
|
|
}
|
|
|
|
var code = target.nextSibling;
|
|
|
|
|
Bring Javelin into Phabricator via git submodule, not copy-and-paste
Summary:
Javelin is currently embedded in Phabricator via copy-and-paste of prebuilt
packages. This is not so great.
Pull it in as a submodule instead and make all the Phabriator resources declare
proper dependency trees. Add Javelin linting.
Test Plan:
I tried to run through pretty much all the JS functionality on the site. This is
still a high-risk change, but I did a pretty thorough test
Differential: inline comments, revealing diffs, list tokenizers, comment
preview, editing/deleting comments, add review action.
Maniphest: list tokenizer, comment actions
Herald: rule editing, tokenizers, add/remove rows
Reviewed By: tomo
Reviewers: aran, tomo, mroch, jungejason, tuomaspelkonen
CC: aran, tomo, epriestley
Differential Revision: 223
2011-05-04 00:11:55 +02:00
|
|
|
var pos = JX.$V(top).add(1 + JX.Vector.getDim(target).x, 0);
|
|
|
|
var dim = JX.Vector.getDim(code).add(-4, 0);
|
|
|
|
dim.y = (JX.$V(bot).y - pos.y) + JX.Vector.getDim(bot).y;
|
2011-02-02 00:52:04 +01:00
|
|
|
|
|
|
|
pos.setPos(reticle);
|
|
|
|
dim.setDim(reticle);
|
|
|
|
|
|
|
|
JX.DOM.show(reticle);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideReticle() {
|
|
|
|
JX.DOM.hide(reticle);
|
|
|
|
}
|
|
|
|
|
|
|
|
function finishSelect() {
|
|
|
|
selecting = false;
|
|
|
|
workflow = false;
|
|
|
|
hideReticle();
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawInlineComment(table, anchor, r) {
|
Bring Javelin into Phabricator via git submodule, not copy-and-paste
Summary:
Javelin is currently embedded in Phabricator via copy-and-paste of prebuilt
packages. This is not so great.
Pull it in as a submodule instead and make all the Phabriator resources declare
proper dependency trees. Add Javelin linting.
Test Plan:
I tried to run through pretty much all the JS functionality on the site. This is
still a high-risk change, but I did a pretty thorough test
Differential: inline comments, revealing diffs, list tokenizers, comment
preview, editing/deleting comments, add review action.
Maniphest: list tokenizer, comment actions
Herald: rule editing, tokenizers, add/remove rows
Reviewed By: tomo
Reviewers: aran, tomo, mroch, jungejason, tuomaspelkonen
CC: aran, tomo, epriestley
Differential Revision: 223
2011-05-04 00:11:55 +02:00
|
|
|
copyRows(table, JX.$N('div', JX.$H(r.markup)), anchor);
|
2011-02-02 00:52:04 +01:00
|
|
|
finishSelect();
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
function isOnRight(node) {
|
2011-02-02 00:52:04 +01:00
|
|
|
return node.parentNode.firstChild != node;
|
|
|
|
}
|
2011-02-02 22:48:52 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
function isNewFile(node) {
|
|
|
|
var data = JX.Stratcom.getData(root);
|
|
|
|
return isOnRight(node) || (data.left != data.right);
|
|
|
|
}
|
2011-02-02 00:52:04 +01:00
|
|
|
|
|
|
|
function getRowNumber(th_node) {
|
|
|
|
try {
|
|
|
|
return parseInt(th_node.id.match(/^C\d+[ON]L(\d+)$/)[1], 10);
|
|
|
|
} catch (x) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-15 03:08:10 +02:00
|
|
|
function isInlineCommentNode(target) {
|
|
|
|
return target &&
|
|
|
|
(!JX.DOM.isType(target, 'tr')
|
|
|
|
|| target.className.indexOf('inline') !== -1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function findInlineCommentTarget(target) {
|
|
|
|
while (isInlineCommentNode(target)) {
|
|
|
|
target = target.nextSibling;
|
|
|
|
}
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2011-02-02 00:52:04 +01:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
'mousedown',
|
|
|
|
['differential-changeset', 'tag:th'],
|
|
|
|
function(e) {
|
|
|
|
if (workflow ||
|
|
|
|
selecting ||
|
|
|
|
getRowNumber(e.getTarget()) === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
selecting = true;
|
|
|
|
root = e.getNode('differential-changeset');
|
|
|
|
|
|
|
|
origin = target = e.getTarget();
|
|
|
|
|
|
|
|
var data = e.getNodeData('differential-changeset');
|
2011-02-02 01:42:36 +01:00
|
|
|
if (isOnRight(target)) {
|
|
|
|
changeset = data.left;
|
2011-02-02 00:52:04 +01:00
|
|
|
} else {
|
2011-02-02 01:42:36 +01:00
|
|
|
changeset = data.right;
|
2011-02-02 00:52:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateReticle();
|
|
|
|
|
|
|
|
e.kill();
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'mouseover',
|
|
|
|
['differential-changeset', 'tag:th'],
|
|
|
|
function(e) {
|
|
|
|
if (!selecting ||
|
|
|
|
workflow ||
|
|
|
|
(getRowNumber(e.getTarget()) === undefined) ||
|
2011-02-02 01:42:36 +01:00
|
|
|
(isOnRight(e.getTarget()) != isOnRight(origin)) ||
|
2011-02-02 00:52:04 +01:00
|
|
|
(e.getNode('differential-changeset') !== root)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
target = e.getTarget();
|
|
|
|
|
|
|
|
updateReticle();
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'mouseup',
|
|
|
|
null,
|
|
|
|
function(e) {
|
|
|
|
if (workflow || !selecting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var o = getRowNumber(origin);
|
|
|
|
var t = getRowNumber(target);
|
|
|
|
|
|
|
|
var insert;
|
|
|
|
var len;
|
|
|
|
if (t < o) {
|
|
|
|
len = (o - t);
|
|
|
|
o = t;
|
|
|
|
insert = origin.parentNode;
|
|
|
|
} else {
|
|
|
|
len = (t - o);
|
|
|
|
insert = target.parentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
op: 'new',
|
|
|
|
changeset: changeset,
|
|
|
|
number: o,
|
|
|
|
length: len,
|
2011-02-02 01:42:36 +01:00
|
|
|
is_new: isNewFile(target) ? 1 : 0,
|
2011-02-02 22:48:52 +01:00
|
|
|
on_right: isOnRight(target) ? 1 : 0
|
2011-02-02 00:52:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
workflow = true;
|
|
|
|
|
|
|
|
var w = new JX.Workflow(config.uri, data)
|
|
|
|
.setHandler(function(r) {
|
|
|
|
// Skip over any rows which contain inline feedback. Don't mimic this!
|
|
|
|
// We're shipping around raw HTML here for performance reasons, but
|
|
|
|
// normally you should use sigils to encode this kind of data on
|
|
|
|
// the document.
|
2011-04-15 03:08:10 +02:00
|
|
|
var target = findInlineCommentTarget(insert.nextSibling);
|
2011-02-02 00:52:04 +01:00
|
|
|
drawInlineComment(insert.parentNode, target, r);
|
|
|
|
finishSelect();
|
2011-02-02 01:42:36 +01:00
|
|
|
JX.Stratcom.invoke('differential-inline-comment-update');
|
2011-02-02 00:52:04 +01:00
|
|
|
})
|
|
|
|
.setCloseHandler(finishSelect);
|
|
|
|
|
|
|
|
|
|
|
|
w.listen('error', function(e) {
|
|
|
|
// TODO: uh, tell the user I guess
|
|
|
|
finishSelect();
|
|
|
|
JX.Stratcom.context().stop();
|
|
|
|
});
|
|
|
|
|
|
|
|
w.start();
|
|
|
|
|
|
|
|
e.kill();
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
['mouseover', 'mouseout'],
|
2011-02-02 01:42:36 +01:00
|
|
|
'differential-inline-comment',
|
2011-02-02 00:52:04 +01:00
|
|
|
function(e) {
|
|
|
|
if (selecting || workflow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e.getType() == 'mouseout') {
|
|
|
|
hideReticle();
|
|
|
|
} else {
|
|
|
|
root = e.getNode('differential-changeset');
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
var data = e.getNodeData('differential-inline-comment');
|
|
|
|
var change = e.getNodeData('differential-changeset');
|
2011-02-02 00:52:04 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
var prefix;
|
|
|
|
if (data.on_right) {
|
|
|
|
prefix = 'C' + (change.left) + 'NL';
|
2011-02-02 00:52:04 +01:00
|
|
|
} else {
|
2011-02-02 01:42:36 +01:00
|
|
|
prefix = 'C' + (change.right) + 'OL';
|
2011-02-02 00:52:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
origin = JX.$(prefix + data.number);
|
2011-02-02 01:42:36 +01:00
|
|
|
target = JX.$(prefix + (parseInt(data.number, 10) +
|
|
|
|
parseInt(data.length, 10)));
|
2011-02-02 00:52:04 +01:00
|
|
|
|
|
|
|
updateReticle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-04-15 03:08:10 +02:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
|
|
|
[['differential-inline-comment', 'differential-inline-reply']],
|
|
|
|
function(e) {
|
|
|
|
new JX.Workflow(config.uri, e.getNodeData('differential-inline-reply'))
|
|
|
|
.setHandler(function(r) {
|
|
|
|
var base_row =
|
|
|
|
findInlineCommentTarget(
|
|
|
|
e.getNode('differential-inline-comment')
|
|
|
|
.parentNode
|
|
|
|
.parentNode
|
|
|
|
);
|
|
|
|
drawInlineComment(base_row.parentNode, base_row, r);
|
|
|
|
JX.Stratcom.invoke('differential-inline-comment-update');
|
|
|
|
})
|
|
|
|
.start();
|
|
|
|
|
|
|
|
e.kill();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2011-02-02 00:52:04 +01:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
2011-02-02 19:10:25 +01:00
|
|
|
[['differential-inline-comment', 'differential-inline-delete'],
|
|
|
|
['differential-inline-comment', 'differential-inline-edit']],
|
2011-02-02 00:52:04 +01:00
|
|
|
function(e) {
|
|
|
|
var data = {
|
2011-02-02 19:10:25 +01:00
|
|
|
op: e.getNode('differential-inline-edit') ? 'edit' : 'delete',
|
|
|
|
id: e.getNodeData('differential-inline-comment').id,
|
Bring Javelin into Phabricator via git submodule, not copy-and-paste
Summary:
Javelin is currently embedded in Phabricator via copy-and-paste of prebuilt
packages. This is not so great.
Pull it in as a submodule instead and make all the Phabriator resources declare
proper dependency trees. Add Javelin linting.
Test Plan:
I tried to run through pretty much all the JS functionality on the site. This is
still a high-risk change, but I did a pretty thorough test
Differential: inline comments, revealing diffs, list tokenizers, comment
preview, editing/deleting comments, add review action.
Maniphest: list tokenizer, comment actions
Herald: rule editing, tokenizers, add/remove rows
Reviewed By: tomo
Reviewers: aran, tomo, mroch, jungejason, tuomaspelkonen
CC: aran, tomo, epriestley
Differential Revision: 223
2011-05-04 00:11:55 +02:00
|
|
|
on_right: e.getNodeData('differential-inline-comment').on_right
|
2011-02-02 00:52:04 +01:00
|
|
|
};
|
|
|
|
new JX.Workflow(config.uri, data)
|
|
|
|
.setHandler(function(r) {
|
2011-02-02 01:42:36 +01:00
|
|
|
var base_row = e.getNode('differential-inline-comment')
|
|
|
|
.parentNode
|
|
|
|
.parentNode;
|
2011-02-02 00:52:04 +01:00
|
|
|
if (data.op == 'edit' && r.markup) {
|
|
|
|
drawInlineComment(base_row.parentNode, base_row, r);
|
|
|
|
}
|
|
|
|
JX.DOM.remove(base_row);
|
|
|
|
JX.Stratcom.invoke('differential-inline-comment-update');
|
|
|
|
})
|
|
|
|
.start();
|
|
|
|
e.kill();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|