2011-05-10 17:29:28 +02:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-maniphest-transaction-preview
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
|
|
|
* javelin-util
|
2012-04-14 16:05:58 +02:00
|
|
|
* javelin-json
|
|
|
|
* javelin-stratcom
|
2011-05-10 17:29:28 +02:00
|
|
|
* phabricator-shaped-request
|
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('maniphest-transaction-preview', function(config) {
|
|
|
|
|
|
|
|
var comments = JX.$(config.comments);
|
2011-05-11 13:17:48 +02:00
|
|
|
var action = JX.$(config.action);
|
2011-05-10 17:29:28 +02:00
|
|
|
|
|
|
|
var callback = function(r) {
|
|
|
|
JX.DOM.setContent(JX.$(config.preview), JX.$H(r));
|
|
|
|
};
|
|
|
|
|
|
|
|
var getdata = function() {
|
2011-05-11 13:17:48 +02:00
|
|
|
var selected = action.value;
|
|
|
|
|
|
|
|
var value = null;
|
|
|
|
try {
|
|
|
|
var control = JX.$(config.map[selected]);
|
|
|
|
var input = ([]
|
|
|
|
.concat(JX.DOM.scry(control, 'select'))
|
|
|
|
.concat(JX.DOM.scry(control, 'input')))[0];
|
2012-04-14 16:05:58 +02:00
|
|
|
if (JX.DOM.isType(input, 'input')) {
|
|
|
|
// Avoid reading 'value'(s) out of the tokenizer free text input.
|
|
|
|
if (input.type != 'hidden') {
|
|
|
|
value = null;
|
|
|
|
// Get the tokenizer and all that delicious data
|
|
|
|
} else {
|
|
|
|
var tokenizer_dom = JX.$(config.tokenizers[selected].id);
|
|
|
|
var tokenizer = JX.Stratcom.getData(tokenizer_dom).tokenizer;
|
|
|
|
value = JX.JSON.stringify(JX.keys(tokenizer.getTokens()));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
value = input.value;
|
2011-05-11 13:17:48 +02:00
|
|
|
}
|
|
|
|
} catch (_ignored_) {
|
|
|
|
// Ignored.
|
|
|
|
}
|
|
|
|
|
2011-05-10 17:29:28 +02:00
|
|
|
return {
|
2011-05-11 13:17:48 +02:00
|
|
|
comments : comments.value,
|
|
|
|
action : selected,
|
|
|
|
value : value || ''
|
2011-05-10 17:29:28 +02:00
|
|
|
};
|
2013-05-19 02:04:22 +02:00
|
|
|
};
|
2011-05-10 17:29:28 +02:00
|
|
|
|
|
|
|
var request = new JX.PhabricatorShapedRequest(config.uri, callback, getdata);
|
|
|
|
var trigger = JX.bind(request, request.trigger);
|
|
|
|
|
|
|
|
JX.DOM.listen(comments, 'keydown', null, trigger);
|
2011-05-11 13:17:48 +02:00
|
|
|
JX.DOM.listen(action, 'change', null, trigger);
|
2011-05-10 17:29:28 +02:00
|
|
|
|
2011-12-07 22:49:56 +01:00
|
|
|
request.start();
|
2011-05-10 17:29:28 +02:00
|
|
|
});
|