Skip to content
Snippets Groups Projects
Commit b954fee2 authored by Peter Rotich's avatar Peter Rotich
Browse files

Support complex lookup on list items

parent 9c6b2a20
No related branches found
No related tags found
No related merge requests found
......@@ -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())
......
......@@ -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)
......
......@@ -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>';
......
......@@ -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'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment