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-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-04-26 19:30:41 +02:00
|
|
|
* javelin-vector
|
2015-04-02 22:41:48 +02:00
|
|
|
* phabricator-title
|
2014-02-18 00:57:13 +01:00
|
|
|
* phabricator-shaped-request
|
2015-03-10 20:20:29 +01:00
|
|
|
* conpherence-thread-manager
|
2013-01-25 02:23:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('conpherence-menu', function(config) {
|
2013-05-29 21:46:06 +02:00
|
|
|
/**
|
|
|
|
* State for displayed thread.
|
|
|
|
*/
|
|
|
|
var _thread = {
|
2013-04-01 21:43:21 +02:00
|
|
|
selected: null,
|
2013-05-29 21:46:06 +02:00
|
|
|
visible: null,
|
|
|
|
node: null
|
2013-04-01 21:43:21 +02:00
|
|
|
};
|
|
|
|
|
2015-03-10 20:20:29 +01:00
|
|
|
// TODO - move more logic into the ThreadManager
|
|
|
|
var threadManager = new JX.ConpherenceThreadManager();
|
2015-03-10 21:53:30 +01:00
|
|
|
threadManager.setWillLoadThreadCallback(function() {
|
|
|
|
markThreadLoading(true);
|
|
|
|
});
|
|
|
|
threadManager.setDidLoadThreadCallback(function(r) {
|
|
|
|
var header = JX.$H(r.header);
|
|
|
|
var messages = JX.$H(r.messages);
|
|
|
|
var form = JX.$H(r.form);
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var header_root = JX.DOM.find(root, 'div', 'conpherence-header-pane');
|
|
|
|
var messages_root = JX.DOM.find(root, 'div', 'conpherence-messages');
|
|
|
|
var form_root = JX.DOM.find(root, 'div', 'conpherence-form');
|
|
|
|
JX.DOM.setContent(header_root, header);
|
|
|
|
JX.DOM.setContent(messages_root, messages);
|
|
|
|
JX.DOM.setContent(form_root, form);
|
|
|
|
|
|
|
|
markThreadLoading(false);
|
|
|
|
|
|
|
|
didRedrawThread(true);
|
|
|
|
});
|
|
|
|
threadManager.setDidUpdateThreadCallback(function(r) {
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var messages_root = JX.DOM.find(root, 'div', 'conpherence-message-pane');
|
|
|
|
var messages = JX.DOM.find(messages_root, 'div', 'conpherence-messages');
|
|
|
|
JX.DOM.appendContent(messages, JX.$H(r.transactions));
|
|
|
|
messages.scrollTop = messages.scrollHeight;
|
2015-03-10 20:20:29 +01:00
|
|
|
});
|
|
|
|
threadManager.setWillSendMessageCallback(function () {
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var form_root = JX.DOM.find(root, 'div', 'conpherence-form');
|
|
|
|
markThreadLoading(true);
|
|
|
|
JX.DOM.alterClass(form_root, 'loading', true);
|
|
|
|
});
|
|
|
|
threadManager.setDidSendMessageCallback(function (r) {
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var form_root = JX.DOM.find(root, 'div', 'conpherence-form');
|
|
|
|
var messages_root = JX.DOM.find(root, 'div', 'conpherence-message-pane');
|
|
|
|
var messages = JX.DOM.find(messages_root, 'div', 'conpherence-messages');
|
|
|
|
var fileWidget = null;
|
|
|
|
try {
|
|
|
|
fileWidget = JX.DOM.find(root, 'div', 'widgets-files');
|
|
|
|
} catch (ex) {
|
|
|
|
// Ignore; maybe no files widget
|
|
|
|
}
|
|
|
|
JX.DOM.appendContent(messages, JX.$H(r.transactions));
|
|
|
|
messages.scrollTop = messages.scrollHeight;
|
|
|
|
|
|
|
|
if (fileWidget) {
|
|
|
|
JX.DOM.setContent(
|
|
|
|
fileWidget,
|
|
|
|
JX.$H(r.file_widget)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
var textarea = JX.DOM.find(form_root, 'textarea');
|
|
|
|
textarea.value = '';
|
|
|
|
markThreadLoading(false);
|
|
|
|
|
|
|
|
setTimeout(function() { JX.DOM.focus(textarea); }, 100);
|
|
|
|
});
|
|
|
|
threadManager.start();
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
/**
|
|
|
|
* Current role of this behavior. The two possible roles are to show a 'list'
|
|
|
|
* of threads or a specific 'thread'. On devices, this behavior stays in the
|
|
|
|
* 'list' role indefinitely, treating clicks normally and the next page
|
|
|
|
* loads the behavior with role = 'thread'. On desktop, this behavior
|
|
|
|
* auto-loads a thread as part of the 'list' role. As the thread loads the
|
|
|
|
* role is changed to 'thread'.
|
|
|
|
*/
|
|
|
|
var _currentRole = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When _oldDevice is null the code is executing for the first time.
|
|
|
|
*/
|
|
|
|
var _oldDevice = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes this behavior based on all the configuraton jonx and the
|
|
|
|
* result of JX.Device.getDevice();
|
|
|
|
*/
|
|
|
|
function init() {
|
|
|
|
_currentRole = config.role;
|
|
|
|
|
|
|
|
if (_currentRole == 'thread') {
|
|
|
|
markThreadsLoading(true);
|
|
|
|
} else {
|
|
|
|
markThreadLoading(true);
|
2013-04-01 21:44:00 +02:00
|
|
|
}
|
2013-05-29 21:46:06 +02:00
|
|
|
markWidgetLoading(true);
|
|
|
|
onDeviceChange();
|
2013-04-01 21:44:00 +02:00
|
|
|
}
|
2013-05-29 21:46:06 +02:00
|
|
|
init();
|
2013-04-01 21:44:00 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
/**
|
|
|
|
* Selecting threads
|
|
|
|
*/
|
|
|
|
function selectThreadByID(id, update_page_data) {
|
|
|
|
var thread = JX.$(id);
|
|
|
|
selectThread(thread, update_page_data);
|
|
|
|
}
|
2013-04-01 21:43:21 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
function selectThread(node, update_page_data) {
|
|
|
|
if (_thread.node) {
|
|
|
|
JX.DOM.alterClass(_thread.node, 'conpherence-selected', false);
|
2013-04-01 21:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
JX.DOM.alterClass(node, 'conpherence-selected', true);
|
|
|
|
JX.DOM.alterClass(node, 'hide-unread-count', true);
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
_thread.node = node;
|
2013-04-01 21:43:21 +02:00
|
|
|
|
|
|
|
var data = JX.Stratcom.getData(node);
|
2013-05-29 21:46:06 +02:00
|
|
|
_thread.selected = data.threadID;
|
2013-04-01 21:43:21 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
if (update_page_data) {
|
|
|
|
updatePageData(data);
|
2013-04-16 01:27:41 +02:00
|
|
|
}
|
2013-04-10 20:37:04 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
redrawThread();
|
2013-04-01 21:43:21 +02:00
|
|
|
}
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
function updatePageData(data) {
|
|
|
|
var uri_suffix = _thread.selected + '/';
|
2013-04-16 01:27:41 +02:00
|
|
|
if (data.use_base_uri) {
|
|
|
|
uri_suffix = '';
|
|
|
|
}
|
2013-05-29 21:46:06 +02:00
|
|
|
JX.History.replace(config.baseURI + uri_suffix);
|
2013-04-16 01:27:41 +02:00
|
|
|
if (data.title) {
|
2015-04-02 22:41:48 +02:00
|
|
|
JX.Title.setTitle(data.title);
|
2013-05-29 21:46:06 +02:00
|
|
|
} else if (_thread.node) {
|
|
|
|
var threadData = JX.Stratcom.getData(_thread.node);
|
2015-04-02 22:41:48 +02:00
|
|
|
JX.Title.setTitle(threadData.title);
|
2013-04-16 01:27:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'conpherence-update-page-data',
|
|
|
|
null,
|
|
|
|
function (e) {
|
2013-05-29 21:46:06 +02:00
|
|
|
updatePageData(e.getData());
|
2013-04-16 01:27:41 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
function redrawThread() {
|
|
|
|
if (!_thread.node) {
|
2013-04-01 21:43:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-04-01 21:52:56 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
if (_thread.visible == _thread.selected) {
|
2013-04-01 21:43:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
var data = JX.Stratcom.getData(_thread.node);
|
2013-04-01 21:43:21 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
if (_thread.visible !== null || !config.hasThread) {
|
2015-03-10 21:53:30 +01:00
|
|
|
threadManager.setLoadThreadURI('/conpherence/' + data.threadID + '/');
|
|
|
|
threadManager.loadThreadByID(data.threadID);
|
2013-05-29 21:46:06 +02:00
|
|
|
} else if (config.hasThread) {
|
2015-03-10 21:53:30 +01:00
|
|
|
// we loaded the thread via the server so let the thread manager know
|
|
|
|
threadManager.setLoadedThreadID(config.selectedThreadID);
|
|
|
|
threadManager.setLoadedThreadPHID(config.selectedThreadPHID);
|
|
|
|
threadManager.setLatestTransactionID(config.latestTransactionID);
|
2015-03-25 19:48:22 +01:00
|
|
|
threadManager.setCanEditLoadedThread(config.canEditSelectedThread);
|
2013-05-29 21:46:06 +02:00
|
|
|
_scrollMessageWindow();
|
2015-02-26 00:14:27 +01:00
|
|
|
_focusTextarea();
|
2013-04-08 20:13:35 +02:00
|
|
|
} else {
|
2013-05-29 21:46:06 +02:00
|
|
|
didRedrawThread();
|
2013-04-01 21:52:56 +02:00
|
|
|
}
|
2013-04-01 21:43:21 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
if (_thread.visible !== null || !config.hasWidgets) {
|
2013-05-29 23:35:34 +02:00
|
|
|
reloadWidget(data);
|
2013-04-16 01:27:41 +02:00
|
|
|
} else {
|
2013-05-29 21:46:06 +02:00
|
|
|
JX.Stratcom.invoke(
|
|
|
|
'conpherence-update-widgets',
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
widget : getDefaultWidget(),
|
|
|
|
buildSelectors : false,
|
|
|
|
toggleWidget : true,
|
|
|
|
threadID : _thread.selected
|
|
|
|
});
|
2013-04-01 21:52:56 +02:00
|
|
|
}
|
2013-04-01 21:43:21 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
_thread.visible = _thread.selected;
|
2013-04-01 21:43:21 +02:00
|
|
|
}
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
function markThreadsLoading(loading) {
|
2013-04-16 01:27:41 +02:00
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
2013-05-29 21:46:06 +02:00
|
|
|
var menu = JX.DOM.find(root, 'div', 'conpherence-menu-pane');
|
|
|
|
JX.DOM.alterClass(menu, 'loading', loading);
|
2013-04-16 01:27:41 +02:00
|
|
|
}
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
function markThreadLoading(loading) {
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var header_root = JX.DOM.find(root, 'div', 'conpherence-header-pane');
|
|
|
|
var messages_root = JX.DOM.find(root, 'div', 'conpherence-message-pane');
|
|
|
|
var form_root = JX.DOM.find(root, 'div', 'conpherence-form');
|
|
|
|
|
|
|
|
JX.DOM.alterClass(header_root, 'loading', loading);
|
|
|
|
JX.DOM.alterClass(messages_root, 'loading', loading);
|
|
|
|
JX.DOM.alterClass(form_root, 'loading', loading);
|
|
|
|
|
|
|
|
try {
|
|
|
|
var textarea = JX.DOM.find(form, 'textarea');
|
|
|
|
textarea.disabled = loading;
|
|
|
|
var button = JX.DOM.find(form, 'button');
|
|
|
|
button.disabled = loading;
|
|
|
|
} catch (ex) {
|
|
|
|
// haven't loaded it yet!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function markWidgetLoading(loading) {
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var widgets_root = JX.DOM.find(root, 'div', 'conpherence-widget-pane');
|
|
|
|
|
|
|
|
JX.DOM.alterClass(widgets_root, 'loading', loading);
|
|
|
|
}
|
|
|
|
|
2013-05-29 23:35:34 +02:00
|
|
|
function reloadWidget(data) {
|
|
|
|
markWidgetLoading(true);
|
|
|
|
if (!data.widget) {
|
|
|
|
data.widget = getDefaultWidget();
|
|
|
|
}
|
|
|
|
var widget_uri = config.baseURI + 'widget/' + data.threadID + '/';
|
|
|
|
new JX.Workflow(widget_uri, {})
|
|
|
|
.setHandler(JX.bind(null, onWidgetResponse, data.threadID, data.widget))
|
|
|
|
.start();
|
|
|
|
}
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'conpherence-reload-widget',
|
|
|
|
null,
|
|
|
|
function (e) {
|
|
|
|
var data = e.getData();
|
|
|
|
if (data.threadID != _thread.selected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reloadWidget(data);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
function onWidgetResponse(thread_id, widget, response) {
|
2013-05-29 21:46:06 +02:00
|
|
|
// we got impatient and this is no longer the right answer :/
|
|
|
|
if (_thread.selected != thread_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var widgets_root = JX.DOM.find(root, 'div', 'conpherence-widgets-holder');
|
|
|
|
JX.DOM.setContent(widgets_root, JX.$H(response.widgets));
|
|
|
|
|
2013-05-24 19:50:18 +02:00
|
|
|
JX.Stratcom.invoke(
|
2013-05-29 21:46:06 +02:00
|
|
|
'conpherence-update-widgets',
|
2013-05-24 19:50:18 +02:00
|
|
|
null,
|
|
|
|
{
|
2013-05-29 23:35:34 +02:00
|
|
|
widget : widget,
|
2013-05-29 21:46:06 +02:00
|
|
|
buildSelectors : true,
|
|
|
|
toggleWidget : true,
|
|
|
|
threadID : _thread.selected
|
2013-05-24 19:50:18 +02:00
|
|
|
});
|
2013-05-29 21:46:06 +02:00
|
|
|
|
|
|
|
markWidgetLoading(false);
|
2013-05-24 19:50:18 +02:00
|
|
|
}
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
function getDefaultWidget() {
|
2013-04-16 01:27:41 +02:00
|
|
|
var device = JX.Device.getDevice();
|
2013-05-24 19:50:18 +02:00
|
|
|
var widget = 'conpherence-message-pane';
|
|
|
|
if (device == 'desktop') {
|
|
|
|
widget = 'widgets-people';
|
2013-04-16 01:27:41 +02:00
|
|
|
}
|
2013-05-24 19:50:18 +02:00
|
|
|
return widget;
|
2013-02-15 23:01:27 +01:00
|
|
|
}
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
/**
|
|
|
|
* This function is a wee bit tricky. Internally, we want to scroll the
|
|
|
|
* message window and let other stuff - notably widgets - redraw / build if
|
|
|
|
* necessary. Externally, we want a hook to scroll the message window
|
|
|
|
* - notably when the widget selector is used to invoke the message pane.
|
|
|
|
* The following three functions get 'er done.
|
|
|
|
*/
|
2015-02-26 00:14:27 +01:00
|
|
|
function didRedrawThread(build_device_widget_selector) {
|
|
|
|
_scrollMessageWindow();
|
|
|
|
_focusTextarea();
|
|
|
|
JX.Stratcom.invoke(
|
|
|
|
'conpherence-did-redraw-thread',
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
widget : getDefaultWidget(),
|
|
|
|
threadID : _thread.selected,
|
|
|
|
buildDeviceWidgetSelector : build_device_widget_selector
|
|
|
|
});
|
2013-05-29 21:46:06 +02:00
|
|
|
}
|
|
|
|
function _scrollMessageWindow() {
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var messages_root = JX.DOM.find(root, 'div', 'conpherence-messages');
|
|
|
|
messages_root.scrollTop = messages_root.scrollHeight;
|
|
|
|
}
|
2015-02-26 00:14:27 +01:00
|
|
|
function _focusTextarea() {
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var form_root = JX.DOM.find(root, 'div', 'conpherence-form');
|
2015-03-25 02:38:16 +01:00
|
|
|
try {
|
|
|
|
var textarea = JX.DOM.find(form_root, 'textarea');
|
|
|
|
// We may have a draft so do this JS trick so we end up focused at the
|
|
|
|
// end of the draft.
|
|
|
|
var textarea_value = textarea.value;
|
|
|
|
textarea.value = '';
|
|
|
|
JX.DOM.focus(textarea);
|
|
|
|
textarea.value = textarea_value;
|
|
|
|
} catch (ex) {
|
|
|
|
// no textarea? no problem
|
|
|
|
}
|
2015-02-26 00:14:27 +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,
|
2014-06-23 19:27:47 +02:00
|
|
|
function () {
|
2013-05-29 21:46:06 +02:00
|
|
|
_scrollMessageWindow();
|
2013-04-16 01:27:41 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
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-05-29 21:46:06 +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)
|
|
|
|
);
|
2015-02-26 00:14:27 +01:00
|
|
|
selectThreadByID(r.conpherence_phid + '-nav-item');
|
2013-04-08 22:41:34 +02:00
|
|
|
} catch (ex) {
|
|
|
|
// Ignore; this view may not have a menu.
|
|
|
|
}
|
|
|
|
}))
|
2013-03-08 19:40:06 +01:00
|
|
|
.start();
|
|
|
|
});
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
var _loadingTransactionID = null;
|
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');
|
2013-05-29 21:46:06 +02:00
|
|
|
if (data.oldest_transaction_id == _loadingTransactionID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_loadingTransactionID = data.oldest_transaction_id;
|
|
|
|
var node = e.getNode('show-older-messages');
|
|
|
|
JX.DOM.setContent(node, 'Loading...');
|
|
|
|
JX.DOM.alterClass(node, 'conpherence-show-older-messages-loading', true);
|
|
|
|
|
|
|
|
var conf_id = _thread.selected;
|
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-05-29 21:46:06 +02:00
|
|
|
new JX.Workflow(config.baseURI + conf_id + '/', data)
|
|
|
|
.setHandler(function(r) {
|
|
|
|
JX.DOM.remove(node);
|
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));
|
2013-05-29 21:46:06 +02:00
|
|
|
}).start();
|
2013-03-08 19:40:06 +01:00
|
|
|
});
|
2013-02-15 23:01:27 +01:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
/**
|
|
|
|
* On devices, 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, changing the _currentRole from list to thread.
|
|
|
|
*/
|
|
|
|
function onDeviceChange() {
|
2013-04-02 15:44:31 +02:00
|
|
|
var new_device = JX.Device.getDevice();
|
2013-05-29 21:46:06 +02:00
|
|
|
if (new_device === _oldDevice) {
|
2013-04-02 15:44:31 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-05-24 19:50:18 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
if (_oldDevice === null) {
|
|
|
|
_oldDevice = new_device;
|
|
|
|
if (_currentRole == 'list') {
|
2013-05-24 19:50:18 +02:00
|
|
|
if (new_device != 'desktop') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2013-05-29 21:46:06 +02:00
|
|
|
loadThreads();
|
2013-05-24 19:50:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-04-16 01:27:41 +02:00
|
|
|
var update_toggled_widget =
|
2013-05-29 21:46:06 +02:00
|
|
|
new_device == 'desktop' || _oldDevice == 'desktop';
|
|
|
|
_oldDevice = new_device;
|
2013-04-02 15:44:31 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
if (_thread.visible !== null && update_toggled_widget) {
|
|
|
|
JX.Stratcom.invoke(
|
|
|
|
'conpherence-did-redraw-thread',
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
widget : getDefaultWidget(),
|
|
|
|
threadID : _thread.selected
|
|
|
|
});
|
2013-04-01 21:43:21 +02:00
|
|
|
}
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
if (_currentRole == 'list' && new_device == 'desktop') {
|
|
|
|
// this selects a thread and loads it
|
|
|
|
didLoadThreads();
|
|
|
|
_currentRole = 'thread';
|
2013-05-24 19:50:18 +02:00
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
JX.DOM.alterClass(root, 'conpherence-role-list', false);
|
|
|
|
JX.DOM.alterClass(root, 'conpherence-role-thread', true);
|
2013-04-01 21:43:21 +02:00
|
|
|
}
|
|
|
|
}
|
2013-05-29 21:46:06 +02:00
|
|
|
JX.Stratcom.listen('phabricator-device-change', null, onDeviceChange);
|
2013-04-01 21:43:21 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
function loadThreads() {
|
|
|
|
markThreadsLoading(true);
|
|
|
|
var uri = config.baseURI + 'thread/' + config.selectedThreadID + '/';
|
2013-04-01 21:52:56 +02:00
|
|
|
new JX.Workflow(uri)
|
2013-05-29 21:46:06 +02:00
|
|
|
.setHandler(onLoadThreadsResponse)
|
2013-04-01 21:52:56 +02:00
|
|
|
.start();
|
|
|
|
}
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
function onLoadThreadsResponse(r) {
|
2013-04-01 21:52:56 +02:00
|
|
|
var layout = JX.$(config.layoutID);
|
|
|
|
var menu = JX.DOM.find(layout, 'div', 'conpherence-menu-pane');
|
|
|
|
JX.DOM.setContent(menu, JX.$H(r));
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
config.selectedID && selectThreadByID(config.selectedID);
|
|
|
|
|
|
|
|
markThreadsLoading(false);
|
2013-04-01 21:52:56 +02:00
|
|
|
}
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
function didLoadThreads() {
|
2013-04-01 21:52:56 +02:00
|
|
|
// If there's no thread selected yet, select the current thread or the
|
|
|
|
// first thread.
|
2013-05-29 21:46:06 +02:00
|
|
|
if (!_thread.selected) {
|
2013-04-01 21:52:56 +02:00
|
|
|
if (config.selectedID) {
|
2013-05-29 21:46:06 +02:00
|
|
|
selectThreadByID(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) {
|
2013-05-29 21:46:06 +02:00
|
|
|
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-05-30 21:42:55 +02:00
|
|
|
markThreadLoading(false);
|
|
|
|
markWidgetLoading(false);
|
2013-04-01 21:52:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-16 07:41:36 +01:00
|
|
|
}
|
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
['click'],
|
2015-03-31 21:45:32 +02:00
|
|
|
'conpherence-menu-see-more',
|
|
|
|
function (e) {
|
|
|
|
e.kill();
|
|
|
|
var sigil = e.getNodeData('conpherence-menu-see-more').moreSigil;
|
|
|
|
var root = JX.$('conpherence-menu-pane');
|
|
|
|
var more = JX.DOM.scry(root, 'li', sigil);
|
|
|
|
for (var i = 0; i < more.length; i++) {
|
|
|
|
JX.DOM.alterClass(more[i], 'hidden', false);
|
|
|
|
}
|
|
|
|
JX.DOM.hide(e.getNode('conpherence-menu-see-more'));
|
|
|
|
});
|
2013-04-26 19:30:41 +02:00
|
|
|
|
2014-02-18 00:57:13 +01:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
['keydown'],
|
|
|
|
'conpherence-pontificate',
|
2015-03-11 23:54:07 +01:00
|
|
|
function (e) {
|
|
|
|
threadManager.handleDraftKeydown(e);
|
|
|
|
});
|
2014-02-18 00:57:13 +01:00
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
});
|