From cb418a6f491cd1175c9a7e0ef37736e17a9c1d08 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 17 Feb 2015 17:07:39 -0600 Subject: [PATCH] filter: Allow filtering by list item abbreviation --- include/class.dynamic_forms.php | 26 +++++++++++++++++++------- include/class.list.php | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 4a85ffabf..364d29dfa 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -1155,10 +1155,17 @@ class SelectionField extends FormField { return $this->getList()->getForm(); } function getSubFields() { + $fields = new ListObject(array( + new TextboxField(array( + // XXX: i18n: Change to a better word when the UI changes + 'label' => '['.__('Abbrev').']', + 'id' => 'abb', + )) + )); $form = $this->getList()->getForm(); - if ($form) - return $form->getFields(); - return array(); + if ($form && ($F = $form->getFields())) + $fields->extend($F); + return $fields; } function toString($items) { @@ -1307,9 +1314,9 @@ class TypeaheadSelectionWidget extends ChoicesWidget { foreach ($this->field->getList()->getItems() as $i) $source[] = array( 'value' => $i->getValue(), 'id' => $i->getId(), - 'info' => sprintf('%s %s', + 'info' => sprintf('%s%s', $i->getValue(), - (($extra= $i->getAbbrev()) ? "-- $extra" : '')), + (($extra= $i->getAbbrev()) ? " — $extra" : '')), ); ?> <span style="display:inline-block"> @@ -1330,6 +1337,7 @@ class TypeaheadSelectionWidget extends ChoicesWidget { $('input#<?php echo $this->name; ?>_id') .attr('name', '<?php echo $this->name; ?>[' + item['id'] + ']') .val(item['value']); + return false; } }); }); @@ -1348,8 +1356,12 @@ class TypeaheadSelectionWidget extends ChoicesWidget { function getEnteredValue() { // Used to verify typeahead fields $data = $this->field->getSource(); - if (isset($data[$this->name.'_name'])) - return trim($data[$this->name.'_name']); + if (isset($data[$this->name.'_name'])) { + // Drop the extra part, if any + $v = $data[$this->name.'_name']; + $v = substr($v, 0, strrpos($v, ' — ')); + return trim($v); + } return parent::getValue(); } } diff --git a/include/class.list.php b/include/class.list.php index 08451a298..a54277533 100644 --- a/include/class.list.php +++ b/include/class.list.php @@ -592,6 +592,7 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { foreach ($this->getConfigurationForm()->getFields() as $F) { $data['.'.$F->get('id')] = $F->toString($F->value); } + $data['.abb'] = (string) $this->get('extra'); return $data; } -- GitLab