Skip to content
Snippets Groups Projects
Commit db27d783 authored by Jared Hancock's avatar Jared Hancock Committed by Peter Rotich
Browse files

forms: Support grouped choice field selections

parent 77204ee9
Branches
Tags
No related merge requests found
...@@ -1706,10 +1706,17 @@ class AssigneeField extends ChoiceField { ...@@ -1706,10 +1706,17 @@ class AssigneeField extends ChoiceField {
function getChoices() { function getChoices() {
global $cfg; global $cfg;
$choices = array(); $choices = array(__('Agents') => new ArrayObject(), __('Teams') => new ArrayObject());
$A = current($choices);
if (($agents = Staff::getAvailableStaffMembers())) if (($agents = Staff::getAvailableStaffMembers()))
foreach ($agents as $id => $name) foreach ($agents as $id => $name)
$choices[$id] = $name; $A['s'.$id] = $name;
next($choices);
$T = current($choices);
if (($teams = Team::getTeams()))
foreach ($teams as $id => $name)
$T['t'.$id] = $name;
return $choices; return $choices;
} }
...@@ -2573,14 +2580,9 @@ class ChoicesWidget extends Widget { ...@@ -2573,14 +2580,9 @@ class ChoicesWidget extends Widget {
<?php if (!$have_def && !$config['multiselect']) { ?> <?php if (!$have_def && !$config['multiselect']) { ?>
<option value="<?php echo $def_key; ?>">&mdash; <?php <option value="<?php echo $def_key; ?>">&mdash; <?php
echo $def_val; ?> &mdash;</option> echo $def_val; ?> &mdash;</option>
<?php } <?php
foreach ($choices as $key => $name) { }
if (!$have_def && $key == $def_key) $this->emitChoices($choices); ?>
continue; ?>
<option value="<?php echo $key; ?>" <?php
if (isset($values[$key])) echo 'selected="selected"';
?>><?php echo $name; ?></option>
<?php } ?>
</select> </select>
<?php <?php
if ($config['multiselect']) { if ($config['multiselect']) {
...@@ -2595,6 +2597,35 @@ class ChoicesWidget extends Widget { ...@@ -2595,6 +2597,35 @@ class ChoicesWidget extends Widget {
} }
} }
function emitChoices($choices) {
reset($choices);
if (is_array(current($choices)) || current($choices) instanceof Traversable)
return $this->emitComplexChoices($choices);
foreach ($choices as $key => $name) {
if (!$have_def && $key == $def_key)
continue; ?>
<option value="<?php echo $key; ?>" <?php
if (isset($values[$key])) echo 'selected="selected"';
?>><?php echo $name; ?></option>
<?php
}
}
function emitComplexChoices($choices) {
foreach ($choices as $label => $group) { ?>
<optgroup label="<?php echo $label; ?>"><?php
foreach ($group as $key => $name) {
if (!$have_def && $key == $def_key)
continue; ?>
<option value="<?php echo $key; ?>" <?php
if (isset($values[$key])) echo 'selected="selected"';
?>><?php echo $name; ?></option>
<?php } ?>
</optgroup><?php
}
}
function getValue() { function getValue() {
if (!($value = parent::getValue())) if (!($value = parent::getValue()))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment