1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00
phorge-phorge/webroot/rsrc/js/application/conpherence/behavior-pontificate.js
epriestley ef30820cf4 Decrease fragility of conpherence-pontificate behavior
Summary:
Currently, this behavior binds a ton of IDs. This makes the behavior fragile: if it is invoked on a page without all the right elements, some `JX.$()` tends to explode.

Instead, don't assume anything is present on the page. This allows the behavior to be invoked on other pages (like the "New Conpherence" page) or pages without some elements (like some future thread-only mobile view) without creating JS errors.

Test Plan:
Added comments, added comments with files. Viewed "New conphenrece" page.

NOTE: Control+Enter is currently broken, but this diff didn't change that behavior.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D5468
2013-03-31 14:41:13 -07:00

54 lines
1.5 KiB
JavaScript

/**
* @provides javelin-behavior-conpherence-pontificate
* @requires javelin-behavior
* javelin-dom
* javelin-util
* javelin-workflow
* javelin-stratcom
*/
JX.behavior('conpherence-pontificate', function(config) {
var onsubmit = function(e) {
e.kill();
var form = e.getNode('tag:form');
var root = e.getNode('conpherence-layout');
var messages = JX.DOM.find(root, 'div', 'conpherence-messages');
var header = JX.DOM.find(root, 'div', 'conpherence-header');
var files = null;
try {
files = JX.DOM.find(root, 'div', 'conpherence-widget-files');
} catch (ex) {
// Ignore, this view may not have a Files widget.
}
JX.Workflow.newFromForm(form)
.setHandler(JX.bind(this, function(r) {
// add the new transactions, probably just our post but who knows
JX.DOM.appendContent(messages, JX.$H(r.transactions));
messages.scrollTop = messages.scrollHeight;
JX.DOM.setContent(header, JX.$H(r.header));
try {
JX.DOM.replace(
JX.$(r.conpherence_phid + '-nav-item'),
JX.$H(r.nav_item));
} catch (ex) {
// Ignore; this view may not have a menu.
}
if (files) {
JX.DOM.setContent(files, JX.$H(r.file_widget));
}
var textarea = JX.DOM.find(form, 'textarea');
textarea.value = '';
}))
.start();
};
JX.Stratcom.listen('click', 'conpherence-pontificate', onsubmit);
});