1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-04 20:52:43 +01:00
phorge-phorge/webroot/rsrc/js/application/maniphest/behavior-transaction-preview.js
Bob Trahan 6be9f6f3a8 Make Maniphest Transaction preview tokenizer aware
Summary:
...pretty sure the JS is too hack-tastic but it works...! :D

also fixed a small error from assert_instances_of change where a null value is all errors and what have you

Test Plan: played around with tasks in firefox and safari. made cc, owner, and project changes, as well as priority, etc.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran

Maniphest Tasks: T1074

Differential Revision: https://secure.phabricator.com/D2234
2012-04-14 07:05:58 -07:00

60 lines
1.7 KiB
JavaScript

/**
* @provides javelin-behavior-maniphest-transaction-preview
* @requires javelin-behavior
* javelin-dom
* javelin-util
* javelin-json
* javelin-stratcom
* phabricator-shaped-request
*/
JX.behavior('maniphest-transaction-preview', function(config) {
var comments = JX.$(config.comments);
var action = JX.$(config.action);
var callback = function(r) {
JX.DOM.setContent(JX.$(config.preview), JX.$H(r));
};
var getdata = function() {
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];
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;
}
} catch (_ignored_) {
// Ignored.
}
return {
comments : comments.value,
action : selected,
value : value || ''
};
}
var request = new JX.PhabricatorShapedRequest(config.uri, callback, getdata);
var trigger = JX.bind(request, request.trigger);
JX.DOM.listen(comments, 'keydown', null, trigger);
JX.DOM.listen(action, 'change', null, trigger);
request.start();
});