1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 17:02:41 +01:00
phorge-phorge/webroot/rsrc/js/application/conpherence/behavior-widget-pane.js
Bob Trahan 27ad838939 Conpherence - make widget selector be a fun JS-based menu
Summary: Ref T3155. Also re-adds the ability to update Conpherence titles by letting user click the title and fill out a little dialogue. Also fixes a bunch of random bugs and what have you. I tried to make the javascript less mysterious by trying to code what's actually happening more explicitly. Still a work in progress all over the place but a good stopping point for feedback.

Test Plan: played around with Conpherence. In particular, went to /conpherence/ and re-sized and went to /conpherence/X/ and re-sized. Also loaded up my no conpherneces user.

Reviewers: epriestley

Reviewed By: epriestley

CC: chad, aran, Korvin

Maniphest Tasks: T3155

Differential Revision: https://secure.phabricator.com/D6022
2013-05-24 10:50:18 -07:00

195 lines
5.6 KiB
JavaScript

/**
* @requires javelin-behavior
* javelin-dom
* javelin-stratcom
* javelin-workflow
* javelin-util
* phabricator-notification
* javelin-behavior-device
* phabricator-dropdown-menu
* phabricator-menu-item
* @provides javelin-behavior-conpherence-widget-pane
*/
JX.behavior('conpherence-widget-pane', function(config) {
var build_widget_selector = function (data) {
var widgets = config.widgetRegistry;
var root = JX.DOM.find(document, 'div', 'conpherence-layout');
var widgetPane = JX.DOM.find(root, 'div', 'conpherence-widget-pane');
var widgetHeader = JX.DOM.find(widgetPane, 'a', 'widgets-selector');
var mobileWidgetHeader = null;
try {
mobileWidgetHeader = JX.DOM.find(
root,
'a',
'device-widgets-selector');
} catch (ex) {
// is okay - no mobileWidgetHeader yet...
}
var widgetData = widgets[data.widget];
JX.DOM.setContent(
widgetHeader,
widgetData.name);
JX.DOM.appendContent(
widgetHeader,
JX.$N('span', { className : 'caret' }));
if (mobileWidgetHeader) {
// this is fragile but adding a sigil to this element is awkward
var mobileWidgetHeaderSpans = JX.DOM.scry(mobileWidgetHeader, 'span');
var mobileWidgetHeaderSpan = mobileWidgetHeaderSpans[1];
JX.DOM.setContent(
mobileWidgetHeaderSpan,
widgetData.name);
}
var menu = new JX.PhabricatorDropdownMenu(widgetHeader);
menu.toggleAlignDropdownRight(false);
var deviceMenu = null;
if (mobileWidgetHeader) {
deviceMenu = new JX.PhabricatorDropdownMenu(mobileWidgetHeader);
}
for (var widget in widgets) {
widgetData = widgets[widget];
if (mobileWidgetHeader) {
deviceMenu.addItem(new JX.PhabricatorMenuItem(
widgetData.name,
JX.bind(null, build_widget_selector, { widget : widget }),
'#'
).setDisabled(widget == data.widget));
}
if (widgetData.deviceOnly) {
continue;
}
menu.addItem(new JX.PhabricatorMenuItem(
widgetData.name,
JX.bind(null, build_widget_selector, { widget : widget }),
'#'
).setDisabled(widget == data.widget));
}
if (data.no_toggle) {
return;
}
toggle_widget(data);
};
var toggle_widget = function (data) {
var widgets = config.widgetRegistry;
var widgetData = widgets[data.widget];
var device = JX.Device.getDevice();
var is_desktop = device == 'desktop';
if (widgetData.deviceOnly && is_desktop) {
return;
}
for (var widget in config.widgetRegistry) {
widgetData = widgets[widget];
if (widgetData.deviceOnly && is_desktop) {
// 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') {
JX.$(widget).style.display = 'block';
JX.Stratcom.invoke('conpherence-redraw-thread', null, {});
}
continue;
}
if (widget == data.widget) {
JX.$(widget).style.display = 'block';
// some one off code for conpherence messages - fancier refresh tech
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';
}
}
};
JX.Stratcom.listen(
'conpherence-toggle-widget',
null,
function (e) {
build_widget_selector(e.getData());
}
);
/* people widget */
JX.Stratcom.listen(
['submit', 'didSyntheticSubmit'],
'add-person',
function (e) {
e.kill();
var root = e.getNode('conpherence-layout');
var form = e.getNode('tag:form');
var data = e.getNodeData('add-person');
var peopleRoot = e.getNode('widgets-people');
var messages = null;
try {
messages = JX.DOM.find(root, 'div', 'conpherence-messages');
} catch (ex) {
}
var latestTransactionData = JX.Stratcom.getData(
JX.DOM.find(
root,
'input',
'latest-transaction-id'
));
data.latest_transaction_id = latestTransactionData.id;
JX.Workflow.newFromForm(form, data)
.setHandler(JX.bind(this, function (r) {
if (messages) {
JX.DOM.appendContent(messages, JX.$H(r.transactions));
messages.scrollTop = messages.scrollHeight;
}
// update the people widget
JX.DOM.setContent(
peopleRoot,
JX.$H(r.people_widget)
);
}))
.start();
}
);
JX.Stratcom.listen(
['touchstart', 'mousedown'],
'remove-person',
function (e) {
var peopleRoot = e.getNode('widgets-people');
var form = JX.DOM.find(peopleRoot, 'form');
var data = e.getNodeData('remove-person');
// we end up re-directing to conpherence home
JX.Workflow.newFromForm(form, data)
.start();
}
);
/* settings widget */
var onsubmitSettings = function (e) {
e.kill();
var form = e.getNode('tag:form');
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();
};
JX.Stratcom.listen(
['submit', 'didSyntheticSubmit'],
'notifications-update',
onsubmitSettings
);
});