mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 17:02:41 +01:00
9de39c12a2
Summary: Fixes T4846. These are one off (for now) since they have various crazy actions with them. I think this will get unified and more cleaned up when we refine the UI for taking multiple actions at once, etc. Test Plan: noted no "commented on x" in either maniphest or differential. starting making a comment and noted prevew showed. started adding a subscriber (added to tokenizer) and preview showed. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T4846 Differential Revision: https://secure.phabricator.com/D12936
114 lines
2.7 KiB
JavaScript
114 lines
2.7 KiB
JavaScript
/**
|
|
* @provides javelin-behavior-differential-feedback-preview
|
|
* @requires javelin-behavior
|
|
* javelin-stratcom
|
|
* javelin-dom
|
|
* javelin-request
|
|
* javelin-util
|
|
* phabricator-shaped-request
|
|
*/
|
|
|
|
JX.behavior('differential-feedback-preview', function(config) {
|
|
|
|
var action = JX.$(config.action);
|
|
var content = JX.$(config.content);
|
|
var previewTokenizers = {};
|
|
var field;
|
|
for (field in config.previewTokenizers) {
|
|
var tokenizer = JX.$(config.previewTokenizers[field]);
|
|
previewTokenizers[field] = JX.Stratcom.getData(tokenizer).tokenizer;
|
|
}
|
|
|
|
var callback = function(r) {
|
|
var preview = JX.$(config.preview);
|
|
var data = getdata();
|
|
var hide = true;
|
|
for (var field in data) {
|
|
if (field == 'action') {
|
|
continue;
|
|
}
|
|
if (data[field]) {
|
|
hide = false;
|
|
}
|
|
}
|
|
if (hide) {
|
|
JX.DOM.hide(preview);
|
|
} else {
|
|
JX.DOM.setContent(preview, JX.$H(r));
|
|
JX.Stratcom.invoke('differential-preview-update', null, {
|
|
container: preview
|
|
});
|
|
JX.DOM.show(preview);
|
|
}
|
|
};
|
|
|
|
var getdata = function() {
|
|
var data = {
|
|
content : content.value,
|
|
action : action.value
|
|
};
|
|
for (var field in previewTokenizers) {
|
|
data[field] = JX.keys(previewTokenizers[field].getTokens()).join(',');
|
|
}
|
|
return data;
|
|
};
|
|
|
|
var request = new JX.PhabricatorShapedRequest(config.uri, callback, getdata);
|
|
var trigger = JX.bind(request, request.trigger);
|
|
|
|
JX.DOM.listen(content, 'keydown', null, trigger);
|
|
JX.DOM.listen(action, 'change', null, trigger);
|
|
for (field in previewTokenizers) {
|
|
previewTokenizers[field].listen('change', trigger);
|
|
}
|
|
|
|
request.start();
|
|
|
|
function refreshInlinePreview() {
|
|
new JX.Request(config.inlineuri, function(r) {
|
|
var inline = JX.$(config.inline);
|
|
|
|
JX.DOM.setContent(inline, JX.$H(r));
|
|
JX.Stratcom.invoke('differential-preview-update', null, {
|
|
container: inline
|
|
});
|
|
|
|
updateLinks();
|
|
})
|
|
.setTimeout(5000)
|
|
.send();
|
|
}
|
|
|
|
function updateLinks() {
|
|
var inline = JX.$(config.inline);
|
|
|
|
var links = JX.DOM.scry(
|
|
inline,
|
|
'a',
|
|
'differential-inline-preview-jump');
|
|
|
|
for (var ii = 0; ii < links.length; ii++) {
|
|
var data = JX.Stratcom.getData(links[ii]);
|
|
try {
|
|
JX.$(data.anchor);
|
|
links[ii].href = '#' + data.anchor;
|
|
JX.DOM.setContent(links[ii], 'View');
|
|
} catch (ignored) {
|
|
// This inline comment isn't visible, e.g. on some other diff.
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
'differential-inline-comment-update',
|
|
null,
|
|
refreshInlinePreview);
|
|
|
|
JX.Stratcom.listen(
|
|
'differential-inline-comment-refresh',
|
|
null,
|
|
updateLinks);
|
|
|
|
refreshInlinePreview();
|
|
});
|