2011-02-02 00:52:04 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-differential-edit-inline-comments
|
|
|
|
* @requires javelin-lib-dev
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
var pos = JX.$V(top).add(1 + JX.$V.getDim(target).x, 0);
|
|
|
|
var dim = JX.$V.getDim(code).add(-4, 0);
|
|
|
|
dim.y = (JX.$V(bot).y - pos.y) + JX.$V.getDim(bot).y;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
copyRows(table, JX.$N('div', JX.HTML(r.markup)), anchor);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
var target = insert.nextSibling;
|
|
|
|
while (target &&
|
|
|
|
(!JX.DOM.isType(target, 'tr')
|
|
|
|
|| target.className.indexOf('inline') !== -1)) {
|
|
|
|
target = target.nextSibling;
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|