2013-04-01 00:19:14 +02:00
|
|
|
/**
|
2013-01-25 02:23:05 +01:00
|
|
|
* @provides javelin-behavior-conpherence-menu
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
2013-04-08 22:41:34 +02:00
|
|
|
* javelin-util
|
2013-03-08 19:40:06 +01:00
|
|
|
* javelin-request
|
2013-01-25 02:23:05 +01:00
|
|
|
* javelin-stratcom
|
2013-03-08 19:40:06 +01:00
|
|
|
* javelin-workflow
|
2013-04-01 21:43:21 +02:00
|
|
|
* javelin-behavior-device
|
2013-04-01 00:19:14 +02:00
|
|
|
* javelin-history
|
2013-01-25 02:23:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('conpherence-menu', function(config) {
|
|
|
|
|
2013-04-01 21:43:21 +02:00
|
|
|
var thread = {
|
|
|
|
selected: null,
|
|
|
|
node: null,
|
|
|
|
visible: null
|
|
|
|
};
|
|
|
|
|
2013-04-16 01:27:41 +02:00
|
|
|
function selectthreadid(id, updatePageData) {
|
2013-04-01 21:44:00 +02:00
|
|
|
var threads = JX.DOM.scry(document.body, 'a', 'conpherence-menu-click');
|
|
|
|
for (var ii = 0; ii < threads.length; ii++) {
|
|
|
|
var data = JX.Stratcom.getData(threads[ii]);
|
|
|
|
if (data.id == id) {
|
2013-04-16 01:27:41 +02:00
|
|
|
selectthread(threads[ii], updatePageData);
|
2013-04-01 21:44:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-16 01:27:41 +02:00
|
|
|
function selectthread(node, updatePageData) {
|
2013-04-01 21:43:21 +02:00
|
|
|
|
|
|
|
if (thread.node) {
|
|
|
|
JX.DOM.alterClass(thread.node, 'conpherence-selected', false);
|
2013-04-08 20:13:35 +02:00
|
|
|
// keep the unread-count hidden still. big TODO once we ajax in updates
|
|
|
|
// to threads to make this work right and move threads between read /
|
|
|
|
// unread
|
2013-04-01 21:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
JX.DOM.alterClass(node, 'conpherence-selected', true);
|
|
|
|
JX.DOM.alterClass(node, 'hide-unread-count', true);
|
|
|
|
|
|
|
|
thread.node = node;
|
|
|
|
|
|
|
|
var data = JX.Stratcom.getData(node);
|
2013-04-01 21:44:00 +02:00
|
|
|
thread.selected = data.id;
|
2013-04-01 21:43:21 +02:00
|
|
|
|
2013-04-16 01:27:41 +02:00
|
|
|
if (updatePageData) {
|
|
|
|
updatepagedata(data);
|
|
|
|
}
|
2013-04-10 20:37:04 +02:00
|
|
|
|
2013-04-01 21:43:21 +02:00
|
|
|
redrawthread();
|
|
|
|
}
|
|
|
|
|
2013-04-16 01:27:41 +02:00
|
|
|
function updatepagedata(data) {
|
|
|
|
var uri_suffix = thread.selected + '/';
|
|
|
|
if (data.use_base_uri) {
|
|
|
|
uri_suffix = '';
|
|
|
|
}
|
|
|
|
JX.History.replace(config.base_uri + uri_suffix);
|
|
|
|
if (data.title) {
|
|
|
|
document.title = data.title;
|
2013-04-23 01:18:18 +02:00
|
|
|
} else if (thread.node) {
|
|
|
|
var threadData = JX.Stratcom.getData(thread.node);
|
|
|
|
document.title = threadData.title;
|
2013-04-16 01:27:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'conpherence-update-page-data',
|
|
|
|
null,
|
|
|
|
function (e) {
|
|
|
|
updatepagedata(e.getData());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2013-04-08 20:13:35 +02:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
'conpherence-selectthread',
|
|
|
|
null,
|
|
|
|
function (e) {
|
|
|
|
var node = JX.$(e.getData().id);
|
|
|
|
selectthread(node);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2013-04-01 21:43:21 +02:00
|
|
|
function redrawthread() {
|
|
|
|
if (!thread.node) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-01 21:52:56 +02:00
|
|
|
|
2013-04-01 21:43:21 +02:00
|
|
|
if (thread.visible == thread.selected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = JX.Stratcom.getData(thread.node);
|
|
|
|
|
2013-04-01 21:52:56 +02:00
|
|
|
if (thread.visible !== null || !config.hasThread) {
|
2013-04-01 03:28:15 +02:00
|
|
|
var uri = config.base_uri + data.id + '/';
|
2013-04-01 21:52:56 +02:00
|
|
|
new JX.Workflow(uri, {})
|
|
|
|
.setHandler(onresponse)
|
|
|
|
.start();
|
2013-04-08 20:13:35 +02:00
|
|
|
} else {
|
|
|
|
didredrawthread();
|
2013-04-01 21:52:56 +02:00
|
|
|
}
|
2013-04-01 21:43:21 +02:00
|
|
|
|
2013-04-01 21:52:56 +02:00
|
|
|
if (thread.visible !== null || !config.hasWidgets) {
|
|
|
|
var widget_uri = config.base_uri + 'widget/' + data.id + '/';
|
|
|
|
new JX.Workflow(widget_uri, {})
|
|
|
|
.setHandler(onwidgetresponse)
|
|
|
|
.start();
|
2013-04-16 01:27:41 +02:00
|
|
|
} else {
|
|
|
|
updatetoggledwidget();
|
2013-04-01 21:52:56 +02:00
|
|
|
}
|
2013-04-01 21:43:21 +02:00
|
|
|
|
|
|
|
thread.visible = thread.selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onwidgetresponse(response) {
|
2013-04-16 01:27:41 +02:00
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var widgetsRoot = JX.DOM.find(root, 'div', 'conpherence-widget-pane');
|
|
|
|
JX.DOM.setContent(widgetsRoot, JX.$H(response.widgets));
|
|
|
|
updatetoggledwidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatetoggledwidget() {
|
|
|
|
var device = JX.Device.getDevice();
|
|
|
|
if (device != 'desktop') {
|
|
|
|
if (config.role == 'list') {
|
|
|
|
JX.Stratcom.invoke(
|
|
|
|
'conpherence-toggle-widget',
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
widget : 'conpherence-menu-pane'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
JX.Stratcom.invoke(
|
|
|
|
'conpherence-toggle-widget',
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
widget : 'conpherence-message-pane'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
JX.Stratcom.invoke(
|
|
|
|
'conpherence-toggle-widget',
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
widget : 'widgets-files'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2013-02-15 23:01:27 +01:00
|
|
|
}
|
|
|
|
|
2013-04-01 21:43:21 +02:00
|
|
|
function onresponse(response) {
|
2013-01-25 02:23:05 +01:00
|
|
|
var header = JX.$H(response.header);
|
|
|
|
var messages = JX.$H(response.messages);
|
|
|
|
var form = JX.$H(response.form);
|
2013-04-16 01:27:41 +02:00
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var headerRoot = JX.DOM.find(root, 'div', 'conpherence-header-pane');
|
|
|
|
var messagesRoot = JX.DOM.find(root, 'div', 'conpherence-messages');
|
|
|
|
var formRoot = JX.DOM.find(root, 'div', 'conpherence-form');
|
2013-01-25 02:23:05 +01:00
|
|
|
JX.DOM.setContent(headerRoot, header);
|
|
|
|
JX.DOM.setContent(messagesRoot, messages);
|
|
|
|
JX.DOM.setContent(formRoot, form);
|
2013-04-01 03:28:15 +02:00
|
|
|
|
|
|
|
didredrawthread();
|
|
|
|
}
|
|
|
|
|
|
|
|
function didredrawthread() {
|
2013-04-16 01:27:41 +02:00
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var messagesRoot = JX.DOM.find(root, 'div', 'conpherence-messages');
|
2013-04-01 03:28:15 +02:00
|
|
|
messagesRoot.scrollTop = messagesRoot.scrollHeight;
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
|
2013-04-16 01:27:41 +02:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
'conpherence-redraw-thread',
|
2013-04-23 01:18:18 +02:00
|
|
|
null,
|
2013-04-16 01:27:41 +02:00
|
|
|
function (e) {
|
|
|
|
didredrawthread();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
|
|
|
'conpherence-menu-click',
|
|
|
|
function(e) {
|
2013-04-01 00:19:14 +02:00
|
|
|
if (!e.isNormalClick()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-01 21:50:51 +02:00
|
|
|
// On devices, just follow the link normally.
|
|
|
|
if (JX.Device.getDevice() != 'desktop') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
e.kill();
|
2013-04-16 01:27:41 +02:00
|
|
|
selectthread(e.getNode('conpherence-menu-click'), true);
|
2013-04-01 21:43:21 +02:00
|
|
|
});
|
2013-01-25 02:23:05 +01:00
|
|
|
|
2013-03-08 19:40:06 +01:00
|
|
|
JX.Stratcom.listen('click', 'conpherence-edit-metadata', function (e) {
|
|
|
|
e.kill();
|
2013-04-08 22:41:34 +02:00
|
|
|
var root = e.getNode('conpherence-layout');
|
|
|
|
var form = JX.DOM.find(root, 'form', 'conpherence-pontificate');
|
2013-03-08 19:40:06 +01:00
|
|
|
var data = e.getNodeData('conpherence-edit-metadata');
|
2013-04-16 01:27:41 +02:00
|
|
|
var header = JX.DOM.find(root, 'div', 'conpherence-header-pane');
|
2013-04-10 20:37:04 +02:00
|
|
|
var messages = JX.DOM.find(root, 'div', 'conpherence-messages');
|
2013-04-08 22:41:34 +02:00
|
|
|
|
2013-03-08 19:40:06 +01:00
|
|
|
new JX.Workflow.newFromForm(form, data)
|
2013-04-08 22:41:34 +02:00
|
|
|
.setHandler(JX.bind(this, function(r) {
|
2013-04-10 20:37:04 +02:00
|
|
|
JX.DOM.appendContent(messages, JX.$H(r.transactions));
|
|
|
|
messages.scrollTop = messages.scrollHeight;
|
|
|
|
|
2013-03-08 19:40:06 +01:00
|
|
|
JX.DOM.setContent(
|
2013-04-08 22:41:34 +02:00
|
|
|
header,
|
2013-03-08 19:40:06 +01:00
|
|
|
JX.$H(r.header)
|
|
|
|
);
|
|
|
|
|
2013-04-08 22:41:34 +02:00
|
|
|
try {
|
|
|
|
// update the menu entry
|
|
|
|
JX.DOM.replace(
|
|
|
|
JX.$(r.conpherence_phid + '-nav-item'),
|
|
|
|
JX.$H(r.nav_item)
|
|
|
|
);
|
|
|
|
JX.Stratcom.invoke(
|
|
|
|
'conpherence-selectthread',
|
|
|
|
null,
|
|
|
|
{ id : r.conpherence_phid + '-nav-item' }
|
|
|
|
);
|
|
|
|
} catch (ex) {
|
|
|
|
// Ignore; this view may not have a menu.
|
|
|
|
}
|
|
|
|
}))
|
2013-03-08 19:40:06 +01:00
|
|
|
.start();
|
|
|
|
});
|
|
|
|
|
2013-02-15 23:01:27 +01:00
|
|
|
JX.Stratcom.listen('click', 'show-older-messages', function(e) {
|
|
|
|
e.kill();
|
2013-04-19 01:54:06 +02:00
|
|
|
var data = e.getNodeData('show-older-messages');
|
|
|
|
var oldest_transaction_id = data.oldest_transaction_id;
|
|
|
|
var conf_id = thread.selected;
|
2013-03-30 01:51:22 +01:00
|
|
|
JX.DOM.remove(e.getNode('show-older-messages'));
|
2013-04-16 01:27:41 +02:00
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var messages_root = JX.DOM.find(root, 'div', 'conpherence-messages');
|
2013-04-01 03:28:15 +02:00
|
|
|
new JX.Request(config.base_uri + conf_id + '/', function(r) {
|
2013-03-30 01:51:22 +01:00
|
|
|
var messages = JX.$H(r.messages);
|
2013-04-19 01:54:06 +02:00
|
|
|
JX.DOM.prependContent(
|
|
|
|
messages_root,
|
|
|
|
JX.$H(messages));
|
|
|
|
}).setData({ oldest_transaction_id : oldest_transaction_id }).send();
|
2013-03-08 19:40:06 +01:00
|
|
|
});
|
2013-02-15 23:01:27 +01:00
|
|
|
|
2013-04-01 21:43:21 +02:00
|
|
|
|
|
|
|
// On mobile, we just show a thread list, so we don't want to automatically
|
|
|
|
// select or load any threads. On Desktop, we automatically select the first
|
|
|
|
// thread.
|
|
|
|
|
2013-04-02 15:44:31 +02:00
|
|
|
var old_device = null;
|
2013-04-01 21:43:21 +02:00
|
|
|
function ondevicechange() {
|
2013-04-02 15:44:31 +02:00
|
|
|
var new_device = JX.Device.getDevice();
|
|
|
|
if (new_device === old_device) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-16 01:27:41 +02:00
|
|
|
var update_toggled_widget =
|
|
|
|
new_device == 'desktop' || old_device == 'desktop';
|
2013-04-02 15:44:31 +02:00
|
|
|
old_device = new_device;
|
|
|
|
|
2013-04-16 01:27:41 +02:00
|
|
|
if (thread.visible !== null && update_toggled_widget) {
|
|
|
|
updatetoggledwidget();
|
2013-04-01 21:43:21 +02:00
|
|
|
}
|
|
|
|
|
2013-04-01 21:52:56 +02:00
|
|
|
if (!config.hasThreadList) {
|
|
|
|
loadthreads();
|
|
|
|
} else {
|
|
|
|
didloadthreads();
|
2013-04-01 21:43:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JX.Stratcom.listen('phabricator-device-change', null, ondevicechange);
|
|
|
|
ondevicechange();
|
|
|
|
|
2013-04-01 21:52:56 +02:00
|
|
|
function loadthreads() {
|
2013-04-01 03:28:15 +02:00
|
|
|
var uri = config.base_uri + 'thread/' + config.selectedID + '/';
|
2013-04-01 21:52:56 +02:00
|
|
|
new JX.Workflow(uri)
|
|
|
|
.setHandler(onthreadresponse)
|
|
|
|
.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onthreadresponse(r) {
|
|
|
|
var layout = JX.$(config.layoutID);
|
|
|
|
var menu = JX.DOM.find(layout, 'div', 'conpherence-menu-pane');
|
|
|
|
JX.DOM.setContent(menu, JX.$H(r));
|
|
|
|
|
|
|
|
config.selectedID && selectthreadid(config.selectedID);
|
|
|
|
}
|
|
|
|
|
|
|
|
function didloadthreads() {
|
|
|
|
// If there's no thread selected yet, select the current thread or the
|
|
|
|
// first thread.
|
|
|
|
if (!thread.selected) {
|
|
|
|
if (config.selectedID) {
|
2013-04-16 01:27:41 +02:00
|
|
|
selectthreadid(config.selectedID, true);
|
2013-04-01 21:52:56 +02:00
|
|
|
} else {
|
2013-04-16 01:27:41 +02:00
|
|
|
var layout = JX.$(config.layoutID);
|
|
|
|
var threads = JX.DOM.scry(layout, 'a', 'conpherence-menu-click');
|
2013-04-01 21:52:56 +02:00
|
|
|
if (threads.length) {
|
|
|
|
selectthread(threads[0]);
|
2013-04-16 01:27:41 +02:00
|
|
|
} else {
|
|
|
|
var nothreads = JX.DOM.find(layout, 'div', 'conpherence-no-threads');
|
|
|
|
nothreads.style.display = 'block';
|
2013-04-01 21:52:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
redrawthread();
|
2013-03-16 07:41:36 +01:00
|
|
|
}
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
});
|