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-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-01 21:44:00 +02:00
|
|
|
function selectthreadid(id) {
|
|
|
|
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) {
|
|
|
|
selectthread(threads[ii]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-01 21:43:21 +02:00
|
|
|
function selectthread(node) {
|
|
|
|
if (node === thread.node) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thread.node) {
|
|
|
|
JX.DOM.alterClass(thread.node, 'conpherence-selected', false);
|
|
|
|
JX.DOM.alterClass(thread.node, 'hide-unread-count', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01 21:44:00 +02:00
|
|
|
JX.History.replace(config.base_uri + data.id + '/');
|
2013-04-01 21:43:21 +02:00
|
|
|
|
|
|
|
redrawthread();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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-01 21:43:21 +02:00
|
|
|
|
|
|
|
thread.visible = thread.selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onwidgetresponse(response) {
|
2013-02-15 23:01:27 +01:00
|
|
|
var widgets = JX.$H(response.widgets);
|
|
|
|
var widgetsRoot = JX.$(config.widgets_pane);
|
|
|
|
JX.DOM.setContent(widgetsRoot, widgets);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
var headerRoot = JX.$(config.header);
|
|
|
|
var messagesRoot = JX.$(config.messages);
|
|
|
|
var formRoot = JX.$(config.form_pane);
|
|
|
|
var widgetsRoot = JX.$(config.widgets_pane);
|
2013-02-05 20:58:19 +01:00
|
|
|
var menuRoot = JX.$(config.menu_pane);
|
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() {
|
|
|
|
var messagesRoot = JX.$(config.messages);
|
|
|
|
messagesRoot.scrollTop = messagesRoot.scrollHeight;
|
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-01 21:43:21 +02:00
|
|
|
selectthread(e.getNode('conpherence-menu-click'));
|
|
|
|
});
|
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-03-16 07:41:36 +01:00
|
|
|
var root = JX.$(config.form_pane);
|
2013-03-08 19:40:06 +01:00
|
|
|
var form = JX.DOM.find(root, 'form');
|
|
|
|
var data = e.getNodeData('conpherence-edit-metadata');
|
|
|
|
new JX.Workflow.newFromForm(form, data)
|
|
|
|
.setHandler(function (r) {
|
|
|
|
// update the header
|
|
|
|
JX.DOM.setContent(
|
|
|
|
JX.$(config.header),
|
|
|
|
JX.$H(r.header)
|
|
|
|
);
|
|
|
|
|
2013-04-02 18:32:40 +02:00
|
|
|
// update the menu entry
|
2013-03-08 19:40:06 +01:00
|
|
|
JX.DOM.replace(
|
|
|
|
JX.$(r.conpherence_phid + '-nav-item'),
|
|
|
|
JX.$H(r.nav_item)
|
|
|
|
);
|
2013-04-02 18:32:40 +02:00
|
|
|
|
|
|
|
// update the people widget
|
|
|
|
JX.DOM.setContent(
|
|
|
|
JX.$(config.people_widget),
|
|
|
|
JX.$H(r.people_widget)
|
|
|
|
);
|
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-03-30 01:51:22 +01:00
|
|
|
var last_offset = e.getNodeData('show-older-messages').offset;
|
|
|
|
var conf_id = e.getNodeData('show-older-messages').ID;
|
|
|
|
JX.DOM.remove(e.getNode('show-older-messages'));
|
|
|
|
var messages_root = JX.$(config.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);
|
|
|
|
JX.DOM.prependContent(messages_root,
|
|
|
|
JX.$H(messages));
|
|
|
|
}).setData({ offset: last_offset+1 }).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;
|
|
|
|
}
|
|
|
|
old_device = new_device;
|
|
|
|
|
|
|
|
if (new_device != 'desktop') {
|
2013-04-01 21:43:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-01 21:52:56 +02:00
|
|
|
if (!config.hasThreadList) {
|
|
|
|
loadthreads();
|
2013-04-01 03:28:15 +02:00
|
|
|
didredrawthread();
|
2013-04-01 21:52:56 +02:00
|
|
|
} 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) {
|
|
|
|
selectthreadid(config.selectedID);
|
|
|
|
} else {
|
|
|
|
var threads = JX.DOM.scry(document.body, 'a', 'conpherence-menu-click');
|
|
|
|
if (threads.length) {
|
|
|
|
selectthread(threads[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
redrawthread();
|
2013-03-16 07:41:36 +01:00
|
|
|
}
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
});
|