From b954fee2b5ae0de127a6470dca5e100184858fff Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Wed, 9 Jul 2014 18:31:54 +0000 Subject: [PATCH] Support complex lookup on list items --- include/ajax.forms.php | 4 ++-- include/class.dynamic_forms.php | 2 +- include/class.forms.php | 4 ++-- include/class.list.php | 22 ++++++++++++++++------ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/ajax.forms.php b/include/ajax.forms.php index 57959fe72..bd71f3924 100644 --- a/include/ajax.forms.php +++ b/include/ajax.forms.php @@ -65,7 +65,7 @@ class DynamicFormsAjaxAPI extends AjaxController { else $list = BuiltInCustomList::lookup($list_id); - if (!($item = $list->getItem($item_id))) + if (!($item = $list->getItem( (int) $item_id))) Http::response(404, 'No such list item'); include(STAFFINC_DIR . 'templates/list-item-properties.tmpl.php'); @@ -78,7 +78,7 @@ class DynamicFormsAjaxAPI extends AjaxController { else $list = BuiltInCustomList::lookup($list_id); - if (!($item = $list->getItem($item_id))) + if (!($item = $list->getItem( (int) $item_id))) Http::response(404, 'No such list item'); if (!$item->setConfiguration()) diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 9c49000d0..2d685db89 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -426,7 +426,7 @@ class DynamicFormField extends VerySimpleModel { function setConfiguration(&$errors=array()) { $config = array(); foreach ($this->getConfigurationForm() as $name=>$field) { - $config[$name] = $field->getClean(); + $config[$name] = $field->to_php($field->getClean()); $errors = array_merge($errors, $field->errors()); } if (count($errors) === 0) diff --git a/include/class.forms.php b/include/class.forms.php index 8e58ca494..c5cb405a6 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -256,7 +256,7 @@ class FormField { * useful error message indicating what is wrong with the input. */ function parse($value) { - return trim($value); + return is_string($value) ? trim($value) : $value; } /** @@ -1110,7 +1110,7 @@ class PhoneNumberWidget extends Widget { class ChoicesWidget extends Widget { function render($mode=false) { - if ($mode && $mode =='view') { + if ($mode && $mode == 'view') { if (!($val = (string) $this->field)) $val = '<span class="faded">None</span>'; diff --git a/include/class.list.php b/include/class.list.php index 293165bbd..d6080304a 100644 --- a/include/class.list.php +++ b/include/class.list.php @@ -275,10 +275,15 @@ class DynamicList extends VerySimpleModel implements CustomList { - function getItem($id) { - return DynamicListItem::lookup(array( - 'id' => $id, - 'list_id' => $this->getId())); + function getItem($val) { + + $criteria = array('list_id' => $this->getId()); + if (is_int($val)) + $criteria['id'] = $val; + else + $criteria['value'] = $val; + + return DynamicListItem::lookup($criteria); } function addItem($vars, &$errors) { @@ -640,11 +645,16 @@ class TicketStatusList extends BuiltInCustomList { return $this->_items; } - function getItem($id) { - return TicketStatus::lookup($id); + function getItem($val) { + + if (!is_int($val)) + $val = array('name' => $val); + + return TicketStatus::lookup($val); } function addItem($vars, &$errors) { + $item = TicketStatus::create(array( 'flags' => 0, //Disable until configured. 'sort' => $vars['sort'], -- GitLab