1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00
phorge-phorge/webroot/rsrc/js/application/policy/behavior-policy-control.js
epriestley 130a15b51b Highlight the currently selected policy in the policy dropdown control thing
Summary: Ref T603. Make this a little easier to use by highlighting the current value.

Test Plan: See screenshot.

Reviewers: chad, btrahan

Reviewed By: chad

CC: chad, aran

Maniphest Tasks: T603

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

56 lines
1.4 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 value = config.value;
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;
value = phid;
}, phid, render));
if (phid == value) {
item.setSelected(true);
}
menu.addItem(item);
}
}
});
});