2013-01-25 02:23:05 +01:00
|
|
|
/**
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
|
|
|
* javelin-stratcom
|
2013-03-26 21:30:35 +01:00
|
|
|
* javelin-workflow
|
|
|
|
* javelin-util
|
|
|
|
* phabricator-notification
|
2013-04-16 01:27:41 +02:00
|
|
|
* javelin-behavior-device
|
2014-05-05 19:56:38 +02:00
|
|
|
* phuix-dropdown-menu
|
|
|
|
* phuix-action-list-view
|
|
|
|
* phuix-action-view
|
2015-03-10 20:20:29 +01:00
|
|
|
* conpherence-thread-manager
|
2013-03-26 21:30:35 +01:00
|
|
|
* @provides javelin-behavior-conpherence-widget-pane
|
2013-01-25 02:23:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('conpherence-widget-pane', function(config) {
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
/**
|
|
|
|
* There can be race conditions around loading the messages or the widgets
|
|
|
|
* first. Keep track of what widgets we've loaded with this variable.
|
|
|
|
*/
|
|
|
|
var _loadedWidgetsID = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* At any given time there can be only one selected widget. Keep track of
|
|
|
|
* which one it is by the user-facing name for ease of use with
|
|
|
|
* PhabricatorDropdownMenuItems.
|
|
|
|
*/
|
|
|
|
var _selectedWidgetName = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is potentially built each time the user switches conpherence threads
|
|
|
|
* or when the result JX.Device.getDevice() changes from desktop to some
|
|
|
|
* other value.
|
|
|
|
*/
|
|
|
|
var buildDeviceWidgetSelector = function (data) {
|
|
|
|
var device_header = _getDeviceWidgetHeader();
|
|
|
|
if (!device_header) {
|
|
|
|
return;
|
2013-05-24 19:50:18 +02:00
|
|
|
}
|
2013-05-29 21:46:06 +02:00
|
|
|
JX.DOM.show(device_header);
|
2014-05-05 19:56:38 +02:00
|
|
|
var device_menu = new JX.PHUIXDropdownMenu(device_header);
|
2013-05-29 21:46:06 +02:00
|
|
|
data.deviceMenu = true;
|
|
|
|
_buildWidgetSelector(device_menu, data);
|
|
|
|
};
|
2013-05-24 19:50:18 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
/**
|
|
|
|
* This is potentially built each time the user switches conpherence threads
|
|
|
|
* or when the result JX.Device.getDevice() changes from mobile or tablet to
|
|
|
|
* desktop.
|
|
|
|
*/
|
|
|
|
var buildDesktopWidgetSelector = function (data) {
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var widget_pane = JX.DOM.find(root, 'div', 'conpherence-widget-pane');
|
|
|
|
var widget_header = JX.DOM.find(widget_pane, 'a', 'widgets-selector');
|
2014-05-05 19:56:38 +02:00
|
|
|
|
|
|
|
var menu = new JX.PHUIXDropdownMenu(widget_header);
|
|
|
|
menu
|
|
|
|
.setAlign('left')
|
|
|
|
.setOffsetY(4);
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
data.deviceMenu = false;
|
|
|
|
_buildWidgetSelector(menu, data);
|
|
|
|
};
|
2013-05-24 19:50:18 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
/**
|
|
|
|
* Workhorse that actually builds the widget selector. Note some fancy bits
|
|
|
|
* where we listen for the "open" event and enable / disable widgets as
|
|
|
|
* appropos.
|
|
|
|
*/
|
|
|
|
var _buildWidgetSelector = function (menu, data) {
|
|
|
|
_loadedWidgetsID = data.threadID;
|
2014-05-05 19:56:38 +02:00
|
|
|
|
|
|
|
var list = new JX.PHUIXActionListView();
|
|
|
|
var map = {};
|
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
var widgets = config.widgetRegistry;
|
2013-05-24 19:50:18 +02:00
|
|
|
for (var widget in widgets) {
|
2013-05-29 21:46:06 +02:00
|
|
|
var widget_data = widgets[widget];
|
|
|
|
if (widget_data.deviceOnly && data.deviceMenu === false) {
|
2013-05-24 19:50:18 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-05 19:56:38 +02:00
|
|
|
|
2015-06-26 00:59:52 +02:00
|
|
|
var handler;
|
|
|
|
var href;
|
2016-09-13 00:19:24 +02:00
|
|
|
handler = JX.bind(null, function(widget, e) {
|
|
|
|
toggleWidget({widget: widget});
|
|
|
|
e.prevent();
|
|
|
|
menu.close();
|
|
|
|
}, widget);
|
2014-05-05 19:56:38 +02:00
|
|
|
var item = new JX.PHUIXActionView()
|
|
|
|
.setIcon(widget_data.icon || 'none')
|
|
|
|
.setName(widget_data.name)
|
2015-06-26 00:59:52 +02:00
|
|
|
.setHref(href)
|
|
|
|
.setHandler(handler);
|
2014-05-05 19:56:38 +02:00
|
|
|
map[widget_data.name] = item;
|
|
|
|
list.addItem(item);
|
2013-05-24 19:50:18 +02:00
|
|
|
}
|
2013-05-29 21:46:06 +02:00
|
|
|
|
2014-05-05 19:56:38 +02:00
|
|
|
menu
|
|
|
|
.setWidth(200)
|
|
|
|
.setContent(list.getNode());
|
|
|
|
|
|
|
|
menu.listen('open', function() {
|
|
|
|
for (var k in map) {
|
|
|
|
map[k].setDisabled((k == _selectedWidgetName));
|
|
|
|
}
|
|
|
|
});
|
2013-05-29 21:46:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Since this is not always on the page, avoid having a repeat
|
|
|
|
* try / catch block and consolidate into this helper function.
|
|
|
|
*/
|
|
|
|
var _getDeviceWidgetHeader = function () {
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var device_header = null;
|
|
|
|
try {
|
|
|
|
device_header = JX.DOM.find(
|
|
|
|
root,
|
|
|
|
'a',
|
|
|
|
'device-widgets-selector');
|
|
|
|
} catch (ex) {
|
|
|
|
// is okay - no deviceWidgetHeader yet... but bail time
|
|
|
|
}
|
|
|
|
return device_header;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Responder to the 'conpherence-did-redraw-thread' event, this bad boy
|
|
|
|
* hides or shows the device widget selector as appropros.
|
|
|
|
*/
|
|
|
|
var _didRedrawThread = function (data) {
|
|
|
|
if (_loadedWidgetsID === null || _loadedWidgetsID != data.threadID) {
|
2013-05-24 19:50:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-05-29 21:46:06 +02:00
|
|
|
var device = JX.Device.getDevice();
|
|
|
|
var device_selector = _getDeviceWidgetHeader();
|
|
|
|
if (device == 'desktop') {
|
|
|
|
JX.DOM.hide(device_selector);
|
|
|
|
} else {
|
|
|
|
JX.DOM.show(device_selector);
|
|
|
|
}
|
|
|
|
if (data.buildDeviceWidgetSelector) {
|
|
|
|
buildDeviceWidgetSelector(data);
|
|
|
|
}
|
|
|
|
toggleWidget(data);
|
2013-05-24 19:50:18 +02:00
|
|
|
};
|
2013-05-29 21:46:06 +02:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
'conpherence-did-redraw-thread',
|
|
|
|
null,
|
|
|
|
function (e) {
|
|
|
|
_didRedrawThread(e.getData());
|
|
|
|
}
|
|
|
|
);
|
2013-05-24 19:50:18 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
/**
|
|
|
|
* Toggling a widget involves showing / hiding the appropriate widget
|
|
|
|
* bodies as well as updating the selectors to have the label on the
|
|
|
|
* newly selected widget.
|
|
|
|
*/
|
|
|
|
var toggleWidget = function (data) {
|
2013-05-24 19:50:18 +02:00
|
|
|
var widgets = config.widgetRegistry;
|
2013-05-29 21:46:06 +02:00
|
|
|
var widget_data = widgets[data.widget];
|
2013-04-16 01:27:41 +02:00
|
|
|
var device = JX.Device.getDevice();
|
|
|
|
var is_desktop = device == 'desktop';
|
2013-05-24 19:50:18 +02:00
|
|
|
|
2013-05-29 21:46:06 +02:00
|
|
|
if (widget_data.deviceOnly && is_desktop) {
|
2013-04-16 01:27:41 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-05-29 21:46:06 +02:00
|
|
|
_selectedWidgetName = widget_data.name;
|
|
|
|
|
|
|
|
var device_header = _getDeviceWidgetHeader();
|
|
|
|
if (device_header) {
|
|
|
|
// this is fragile but adding a sigil to this element is awkward
|
|
|
|
var device_header_spans = JX.DOM.scry(device_header, 'span');
|
|
|
|
var device_header_span = device_header_spans[1];
|
|
|
|
JX.DOM.setContent(
|
|
|
|
device_header_span,
|
|
|
|
widget_data.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't update the non-device selector with device only widget stuff
|
|
|
|
if (!widget_data.deviceOnly) {
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
|
|
|
var widget_pane = JX.DOM.find(root, 'div', 'conpherence-widget-pane');
|
|
|
|
var widget_header = JX.DOM.find(widget_pane, 'a', 'widgets-selector');
|
2013-05-29 23:35:34 +02:00
|
|
|
var adder = JX.DOM.find(widget_pane, 'a', 'conpherence-widget-adder');
|
2015-03-25 19:48:22 +01:00
|
|
|
var threadManager = JX.ConpherenceThreadManager.getInstance();
|
|
|
|
var disabled = !threadManager.getCanEditLoadedThread();
|
2013-05-29 21:46:06 +02:00
|
|
|
JX.DOM.setContent(
|
|
|
|
widget_header,
|
|
|
|
widget_data.name);
|
|
|
|
JX.DOM.appendContent(
|
|
|
|
widget_header,
|
|
|
|
JX.$N('span', { className : 'caret' }));
|
2013-05-29 23:35:34 +02:00
|
|
|
if (widget_data.hasCreate) {
|
|
|
|
JX.DOM.show(adder);
|
2015-03-25 19:48:22 +01:00
|
|
|
JX.DOM.alterClass(
|
|
|
|
adder,
|
|
|
|
'disabled',
|
|
|
|
disabled);
|
2013-05-29 23:35:34 +02:00
|
|
|
} else {
|
|
|
|
JX.DOM.hide(adder);
|
|
|
|
}
|
2013-05-29 21:46:06 +02:00
|
|
|
}
|
2013-04-16 01:27:41 +02:00
|
|
|
|
2013-05-24 19:50:18 +02:00
|
|
|
for (var widget in config.widgetRegistry) {
|
2013-05-29 21:46:06 +02:00
|
|
|
widget_data = widgets[widget];
|
|
|
|
if (widget_data.deviceOnly && is_desktop) {
|
2013-05-24 19:50:18 +02:00
|
|
|
// some one off code for conpherence messages which are device-only
|
|
|
|
// as a widget, but shown always on the desktop
|
|
|
|
if (widget == 'conpherence-message-pane') {
|
2013-01-25 02:23:05 +01:00
|
|
|
JX.$(widget).style.display = 'block';
|
2013-04-16 01:27:41 +02:00
|
|
|
}
|
2013-05-24 19:50:18 +02:00
|
|
|
continue;
|
2013-04-16 01:27:41 +02:00
|
|
|
}
|
|
|
|
if (widget == data.widget) {
|
|
|
|
JX.$(widget).style.display = 'block';
|
2013-05-24 19:50:18 +02:00
|
|
|
// some one off code for conpherence messages - fancier refresh tech
|
2013-04-16 01:27:41 +02:00
|
|
|
if (widget == 'conpherence-message-pane') {
|
|
|
|
JX.Stratcom.invoke('conpherence-redraw-thread', null, {});
|
|
|
|
JX.Stratcom.invoke('conpherence-update-page-data', null, {});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
JX.$(widget).style.display = 'none';
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
}
|
2013-04-16 01:27:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
2013-05-29 21:46:06 +02:00
|
|
|
'conpherence-update-widgets',
|
2013-04-16 01:27:41 +02:00
|
|
|
null,
|
|
|
|
function (e) {
|
2013-05-29 21:46:06 +02:00
|
|
|
var data = e.getData();
|
|
|
|
if (data.buildSelectors) {
|
|
|
|
buildDesktopWidgetSelector(data);
|
|
|
|
buildDeviceWidgetSelector(data);
|
|
|
|
}
|
|
|
|
if (data.toggleWidget) {
|
|
|
|
toggleWidget(data);
|
|
|
|
}
|
|
|
|
});
|
2013-04-16 01:27:41 +02:00
|
|
|
|
2013-05-29 23:35:34 +02:00
|
|
|
/**
|
|
|
|
* Generified adding new stuff to widgets technology!
|
|
|
|
*/
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
['click'],
|
|
|
|
'conpherence-widget-adder',
|
|
|
|
function (e) {
|
|
|
|
e.kill();
|
2013-05-30 02:21:07 +02:00
|
|
|
|
2013-05-29 23:35:34 +02:00
|
|
|
var widgets = config.widgetRegistry;
|
2013-05-30 02:21:07 +02:00
|
|
|
// the widget key might be in node data, but otherwise use the
|
|
|
|
// selected widget
|
|
|
|
var event_data = e.getNodeData('conpherence-widget-adder');
|
|
|
|
var widget_key = _selectedWidgetName;
|
|
|
|
if (event_data.widget) {
|
|
|
|
widget_key = widgets[event_data.widget].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
var widget_to_update = null;
|
|
|
|
var create_data = null;
|
2013-05-29 23:35:34 +02:00
|
|
|
for (var widget in widgets) {
|
2013-05-30 02:21:07 +02:00
|
|
|
if (widgets[widget].name == widget_key) {
|
|
|
|
create_data = widgets[widget].createData;
|
|
|
|
widget_to_update = widget;
|
2013-05-29 23:35:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-05-30 02:21:07 +02:00
|
|
|
// this should be impossible, but hey
|
|
|
|
if (!widget_to_update) {
|
|
|
|
return;
|
2013-04-10 20:37:04 +02:00
|
|
|
}
|
2013-05-30 02:21:07 +02:00
|
|
|
var href = config.widgetBaseUpdateURI + _loadedWidgetsID + '/';
|
|
|
|
if (create_data.customHref) {
|
|
|
|
href = create_data.customHref;
|
|
|
|
}
|
|
|
|
|
2015-03-10 20:20:29 +01:00
|
|
|
var threadManager = JX.ConpherenceThreadManager.getInstance();
|
|
|
|
var latest_transaction_id = threadManager.getLatestTransactionID();
|
2013-05-30 02:21:07 +02:00
|
|
|
var data = {
|
2015-03-10 20:20:29 +01:00
|
|
|
latest_transaction_id : latest_transaction_id,
|
2013-05-30 02:21:07 +02:00
|
|
|
action : create_data.action
|
|
|
|
};
|
2013-04-08 20:13:35 +02:00
|
|
|
|
2015-03-10 20:20:29 +01:00
|
|
|
var workflow = new JX.Workflow(href, data)
|
2013-05-30 02:21:07 +02:00
|
|
|
.setHandler(function (r) {
|
2015-03-10 20:20:29 +01:00
|
|
|
var threadManager = JX.ConpherenceThreadManager.getInstance();
|
|
|
|
threadManager.setLatestTransactionID(r.latest_transaction_id);
|
|
|
|
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
|
2013-05-30 02:21:07 +02:00
|
|
|
if (create_data.refreshFromResponse) {
|
|
|
|
var messages = null;
|
|
|
|
try {
|
|
|
|
messages = JX.DOM.find(root, 'div', 'conpherence-messages');
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
if (messages) {
|
|
|
|
JX.DOM.appendContent(messages, JX.$H(r.transactions));
|
2015-04-13 20:49:30 +02:00
|
|
|
JX.Stratcom.invoke('conpherence-redraw-thread', null, {});
|
2013-05-30 02:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (r.people_widget) {
|
|
|
|
try {
|
|
|
|
var people_root = JX.DOM.find(root, 'div', 'widgets-people');
|
|
|
|
// update the people widget
|
|
|
|
JX.DOM.setContent(
|
|
|
|
people_root,
|
|
|
|
JX.$H(r.people_widget));
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise let's redraw the widget somewhat lazily
|
|
|
|
} else {
|
|
|
|
JX.Stratcom.invoke(
|
|
|
|
'conpherence-reload-widget',
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
threadID : _loadedWidgetsID,
|
|
|
|
widget : widget_to_update
|
|
|
|
});
|
|
|
|
}
|
2015-03-10 20:20:29 +01:00
|
|
|
});
|
2015-06-25 22:14:20 +02:00
|
|
|
|
2015-03-10 20:20:29 +01:00
|
|
|
threadManager.syncWorkflow(workflow, 'submit');
|
2013-04-02 18:32:40 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2013-04-08 20:13:35 +02:00
|
|
|
JX.Stratcom.listen(
|
2013-04-16 01:27:41 +02:00
|
|
|
['touchstart', 'mousedown'],
|
2013-04-02 18:32:40 +02:00
|
|
|
'remove-person',
|
|
|
|
function (e) {
|
2013-05-30 02:21:07 +02:00
|
|
|
var href = config.widgetBaseUpdateURI + _loadedWidgetsID + '/';
|
2013-04-02 18:32:40 +02:00
|
|
|
var data = e.getNodeData('remove-person');
|
2015-06-25 22:14:20 +02:00
|
|
|
|
|
|
|
// While the user is removing themselves, disable the notification
|
|
|
|
// update behavior. If we don't do this, the user can get an error
|
|
|
|
// when they remove themselves about permissions as the notification
|
|
|
|
// code tries to load what jist happened.
|
|
|
|
var threadManager = JX.ConpherenceThreadManager.getInstance();
|
|
|
|
var loadedPhid = threadManager.getLoadedThreadPHID();
|
|
|
|
threadManager.setLoadedThreadPHID(null);
|
|
|
|
|
2013-05-30 02:21:07 +02:00
|
|
|
new JX.Workflow(href, data)
|
2015-06-25 22:14:20 +02:00
|
|
|
.setCloseHandler(function() {
|
|
|
|
threadManager.setLoadedThreadPHID(loadedPhid);
|
|
|
|
})
|
|
|
|
// we re-direct to conpherence home so the thread manager will
|
|
|
|
// fix itself there
|
|
|
|
.setHandler(function(r) {
|
|
|
|
JX.$U(r.href).go();
|
|
|
|
})
|
|
|
|
.start();
|
2013-04-02 18:32:40 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
/* settings widget */
|
2013-03-26 21:30:35 +01:00
|
|
|
var onsubmitSettings = function (e) {
|
|
|
|
e.kill();
|
2013-04-08 20:13:35 +02:00
|
|
|
var form = e.getNode('tag:form');
|
2013-03-26 21:30:35 +01:00
|
|
|
var button = JX.DOM.find(form, 'button');
|
|
|
|
JX.Workflow.newFromForm(form)
|
|
|
|
.setHandler(JX.bind(this, function (r) {
|
|
|
|
new JX.Notification()
|
|
|
|
.setDuration(6000)
|
|
|
|
.setContent(r)
|
|
|
|
.show();
|
|
|
|
button.disabled = '';
|
|
|
|
JX.DOM.alterClass(button, 'disabled', false);
|
|
|
|
}))
|
|
|
|
.start();
|
|
|
|
};
|
|
|
|
|
2013-04-08 20:13:35 +02:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
['submit', 'didSyntheticSubmit'],
|
2013-03-26 21:30:35 +01:00
|
|
|
'notifications-update',
|
|
|
|
onsubmitSettings
|
|
|
|
);
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
});
|