2013-03-06 00:45:36 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-conpherence-pontificate
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
2013-03-08 19:40:06 +01:00
|
|
|
* javelin-util
|
|
|
|
* javelin-workflow
|
2013-03-31 23:41:13 +02:00
|
|
|
* javelin-stratcom
|
2013-03-06 00:45:36 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('conpherence-pontificate', function(config) {
|
2014-06-11 22:52:15 +02:00
|
|
|
|
|
|
|
JX.Stratcom.listen('aphlict-receive-message', null, function(e) {
|
|
|
|
var message = e.getData();
|
|
|
|
|
|
|
|
if (message.type != 'message') {
|
|
|
|
// Not a message event.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: This is really, really gross.
|
|
|
|
var infonode = JX.DOM.find(document, 'input', 'latest-transaction-id');
|
|
|
|
var data = JX.Stratcom.getData(infonode);
|
|
|
|
|
|
|
|
var latest_id = infonode.value;
|
|
|
|
var thread_phid = data.threadPHID;
|
|
|
|
var thread_id = data.threadID;
|
|
|
|
|
|
|
|
if (message.threadPHID != thread_phid) {
|
|
|
|
// Message event for some thread other than the visible one.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message.messageID <= latest_id) {
|
|
|
|
// Message event for something we already know about.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
action: 'load',
|
|
|
|
latest_transaction_id: latest_id
|
|
|
|
};
|
|
|
|
|
|
|
|
new JX.Workflow('/conpherence/update/' + thread_id + '/')
|
|
|
|
.setData(params)
|
|
|
|
.setHandler(function(r) {
|
|
|
|
var messages = JX.DOM.find(document, 'div', 'conpherence-messages');
|
|
|
|
JX.DOM.appendContent(messages, JX.$H(r.transactions));
|
|
|
|
messages.scrollTop = messages.scrollHeight;
|
|
|
|
|
|
|
|
// TODO: Continued grossness from above.
|
|
|
|
infonode.value = r.latest_transaction_id;
|
|
|
|
})
|
|
|
|
.start();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-03-06 00:45:36 +01:00
|
|
|
var onsubmit = function(e) {
|
|
|
|
e.kill();
|
2013-03-31 23:41:13 +02:00
|
|
|
|
|
|
|
var form = e.getNode('tag:form');
|
|
|
|
|
|
|
|
var root = e.getNode('conpherence-layout');
|
2013-05-29 21:46:06 +02:00
|
|
|
var messages_root = JX.DOM.find(root, 'div', 'conpherence-message-pane');
|
|
|
|
var header_root = JX.DOM.find(root, 'div', 'conpherence-header-pane');
|
|
|
|
var form_root = JX.DOM.find(root, 'div', 'conpherence-form');
|
|
|
|
var messages = JX.DOM.find(messages_root, 'div', 'conpherence-messages');
|
2013-04-08 20:13:35 +02:00
|
|
|
var fileWidget = null;
|
|
|
|
try {
|
|
|
|
fileWidget = JX.DOM.find(root, 'div', 'widgets-files');
|
|
|
|
} catch (ex) {
|
|
|
|
// Ignore; maybe no files widget
|
|
|
|
}
|
2013-05-29 21:46:06 +02:00
|
|
|
JX.DOM.alterClass(form_root, 'loading', true);
|
2013-03-31 23:41:13 +02:00
|
|
|
|
2013-03-06 00:45:36 +01:00
|
|
|
JX.Workflow.newFromForm(form)
|
|
|
|
.setHandler(JX.bind(this, function(r) {
|
|
|
|
JX.DOM.appendContent(messages, JX.$H(r.transactions));
|
|
|
|
messages.scrollTop = messages.scrollHeight;
|
2013-03-31 23:41:13 +02:00
|
|
|
|
2013-04-08 20:13:35 +02:00
|
|
|
if (fileWidget) {
|
|
|
|
JX.DOM.setContent(
|
|
|
|
fileWidget,
|
|
|
|
JX.$H(r.file_widget)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-06-12 03:07:53 +02:00
|
|
|
var latest_transaction_dom = JX.DOM.find(
|
|
|
|
root,
|
|
|
|
'input',
|
|
|
|
'latest-transaction-id');
|
|
|
|
latest_transaction_dom.value = r.latest_transaction_id;
|
2013-03-06 00:45:36 +01:00
|
|
|
|
|
|
|
var textarea = JX.DOM.find(form, 'textarea');
|
|
|
|
textarea.value = '';
|
2013-04-10 20:37:04 +02:00
|
|
|
|
2013-04-16 01:27:41 +02:00
|
|
|
JX.Stratcom.invoke(
|
|
|
|
'conpherence-selectthread',
|
|
|
|
null,
|
|
|
|
{ id : r.conpherence_phid + '-nav-item' }
|
2013-05-29 21:46:06 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
JX.DOM.alterClass(form_root, 'loading', false);
|
2013-03-06 00:45:36 +01:00
|
|
|
}))
|
|
|
|
.start();
|
|
|
|
};
|
|
|
|
|
2013-03-31 23:41:33 +02:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
['submit', 'didSyntheticSubmit'],
|
|
|
|
'conpherence-pontificate',
|
|
|
|
onsubmit);
|
2013-03-06 00:45:36 +01:00
|
|
|
|
|
|
|
});
|