Differential D17890 Diff 43052 webroot/rsrc/js/application/differential/behavior-edit-inline-comments.js
Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/differential/behavior-edit-inline-comments.js
Show First 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | var action_handler = function(op, e) { | ||||
updateReticleForComment(e); | updateReticleForComment(e); | ||||
handle_inline_action(node, op); | handle_inline_action(node, op); | ||||
}; | }; | ||||
var handle_inline_action = function(node, op) { | var handle_inline_action = function(node, op) { | ||||
var data = JX.Stratcom.getData(node); | var data = JX.Stratcom.getData(node); | ||||
// If you click an action in the preview at the bottom of the page, we | |||||
// find the corresponding node and simulate clicking that, if it's | |||||
// present on the page. This gives the editor a more consistent view | |||||
// of the document. | |||||
if (JX.Stratcom.hasSigil(node, 'differential-inline-comment-preview')) { | |||||
var nodes = JX.DOM.scry( | |||||
JX.DOM.getContentFrame(), | |||||
'div', | |||||
'differential-inline-comment'); | |||||
var found = false; | |||||
var node_data; | |||||
for (var ii = 0; ii < nodes.length; ++ii) { | |||||
if (nodes[ii] == node) { | |||||
// Don't match the preview itself. | |||||
continue; | |||||
} | |||||
node_data = JX.Stratcom.getData(nodes[ii]); | |||||
if (node_data.id == data.id) { | |||||
node = nodes[ii]; | |||||
data = node_data; | |||||
found = true; | |||||
break; | |||||
} | |||||
} | |||||
if (!found) { | |||||
switch (op) { | |||||
case 'delete': | |||||
new JX.DifferentialInlineCommentEditor(config.uri) | |||||
.deleteByID(data.id); | |||||
return; | |||||
} | |||||
} | |||||
if (op == 'delete') { | |||||
op = 'refdelete'; | |||||
} | |||||
} | |||||
var original = data.original; | var original = data.original; | ||||
var reply_phid = null; | var reply_phid = null; | ||||
if (op == 'reply') { | if (op == 'reply') { | ||||
// If the user hit "reply", the original text is empty (a new reply), not | // If the user hit "reply", the original text is empty (a new reply), not | ||||
// the text of the comment they're replying to. | // the text of the comment they're replying to. | ||||
original = ''; | original = ''; | ||||
reply_phid = data.phid; | reply_phid = data.phid; | ||||
} | } | ||||
var row = JX.DOM.findAbove(node, 'tr'); | var row = JX.DOM.findAbove(node, 'tr'); | ||||
var changeset_root = JX.DOM.findAbove( | var changeset_root = JX.DOM.findAbove( | ||||
node, | node, | ||||
'div', | 'div', | ||||
'differential-changeset'); | 'differential-changeset'); | ||||
var view = JX.DiffChangeset.getForNode(changeset_root); | var view = JX.DiffChangeset.getForNode(changeset_root); | ||||
if (op == 'edit') { | |||||
// This is now handled by DiffChangesetList. | |||||
editor = true; | |||||
} else { | |||||
editor = new JX.DifferentialInlineCommentEditor(config.uri) | editor = new JX.DifferentialInlineCommentEditor(config.uri) | ||||
.setTemplates(view.getUndoTemplates()) | .setTemplates(view.getUndoTemplates()) | ||||
.setOperation(op) | .setOperation(op) | ||||
.setID(data.id) | .setID(data.id) | ||||
.setChangesetID(data.changesetID) | .setChangesetID(data.changesetID) | ||||
.setLineNumber(data.number) | .setLineNumber(data.number) | ||||
.setLength(data.length) | .setLength(data.length) | ||||
.setOnRight(data.on_right) | .setOnRight(data.on_right) | ||||
.setOriginalText(original) | .setOriginalText(original) | ||||
.setRow(row) | .setRow(row) | ||||
.setTable(row.parentNode) | .setTable(row.parentNode) | ||||
.setReplyToCommentPHID(reply_phid) | .setReplyToCommentPHID(reply_phid) | ||||
.setRenderer(view.getRenderer()) | .setRenderer(view.getRenderer()) | ||||
.start(); | .start(); | ||||
} | |||||
set_link_state(true); | set_link_state(true); | ||||
}; | }; | ||||
for (var op in {'edit': 1, 'delete': 1, 'reply': 1}) { | for (var op in {'reply': 1}) { | ||||
JX.Stratcom.listen( | JX.Stratcom.listen( | ||||
'click', | 'click', | ||||
['differential-inline-comment', 'differential-inline-' + op], | ['differential-inline-comment', 'differential-inline-' + op], | ||||
JX.bind(null, action_handler, op)); | JX.bind(null, action_handler, op)); | ||||
} | } | ||||
JX.Stratcom.listen( | JX.Stratcom.listen( | ||||
'differential-inline-action', | 'differential-inline-action', | ||||
null, | null, | ||||
function(e) { | function(e) { | ||||
var data = e.getData(); | var data = e.getData(); | ||||
handle_inline_action(data.node, data.op); | handle_inline_action(data.node, data.op); | ||||
}); | }); | ||||
}); | }); |