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/policy/behavior-policy-control.js
epriestley 5af031ec9b Make the policy control a JS dropdown with icons
Summary: Ref T603. After thinking about this for a bit I can't really come up with anything better than what Facebook does, so I'm going to implement something similar for choosing custom policies. To start with, swap this over to a JS-driven dropdown.

Test Plan: See screenshot.

Reviewers: chad, btrahan

Reviewed By: btrahan

CC: chad, aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7285
2013-10-12 17:08:11 -07:00

50 lines
1.3 KiB
JavaScript

/**
* @provides javelin-behavior-policy-control
* @requires javelin-behavior
* javelin-dom
* javelin-util
* phabricator-dropdown-menu
* phabricator-menu-item
* @javelin
*/
JX.behavior('policy-control', function(config) {
var control = JX.$(config.controlID);
var input = JX.$(config.inputID);
var menu = new JX.PhabricatorDropdownMenu(control)
.setWidth(260);
menu.toggleAlignDropdownRight(false);
menu.listen('open', function() {
menu.clear();
for (var ii = 0; ii < config.groups.length; ii++) {
var group = config.groups[ii];
var header = new JX.PhabricatorMenuItem(config.labels[group]);
header.setDisabled(true);
menu.addItem(header);
for (var jj = 0; jj < config.order[group].length; jj++) {
var phid = config.order[group][jj];
var option = config.options[phid];
var render = [JX.$H(config.icons[option.icon]), option.name];
var item = new JX.PhabricatorMenuItem(
render,
JX.bind(null, function(phid, render) {
JX.DOM.setContent(
JX.DOM.find(control, 'span', 'policy-label'),
render);
input.value = phid;
}, phid, render));
menu.addItem(item);
}
}
});
});