diff --git a/include/ajax.forms.php b/include/ajax.forms.php index f99870a9770d436cc36c028c068a5d25ba9061d9..520e8584a80b6107d4b63af9f7bd5b309694ac54 100644 --- a/include/ajax.forms.php +++ b/include/ajax.forms.php @@ -128,6 +128,20 @@ class DynamicFormsAjaxAPI extends AjaxController { include(STAFFINC_DIR . 'templates/list-items.tmpl.php'); } + function previewListItem($list_id, $item_id) { + + $list = DynamicList::lookup($list_id); + if (!$list) + Http::response(404, 'No such list item'); + + $list = CustomListHandler::forList($list); + if (!($item = $list->getItem( (int) $item_id))) + Http::response(404, 'No such list item'); + + $form = $list->getListItemBasicForm($item->ht, $item); + include(STAFFINC_DIR . 'templates/list-item-preview.tmpl.php'); + } + function saveListItem($list_id, $item_id) { global $thisstaff; diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 6131a294b747e7328cfe3a1dcfd88cb7ae8a7673..624294c2d24a5108ccae9e4aefbed8033d93e395 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -1446,6 +1446,28 @@ class SelectionField extends FormField { return parent::getWidget($widgetClass); } + function display($value) { + global $thisstaff; + + if (!is_array($value) + || !$thisstaff // Only agents can preview for now + || !($list=$this->getList())) + return parent::display($value); + + $display = array(); + foreach ($value as $k => $v) { + if (is_numeric($k) + && ($i=$list->getItem((int) $k)) + && $i->hasProperties()) + $display[] = $i->display(); + else // Perhaps deleted entry + $display[] = $v; + } + + return implode(',', $display); + + } + function parse($value) { if (!($list=$this->getList())) diff --git a/include/class.list.php b/include/class.list.php index 84322f7006435453f857ee5ca82dd984b4555eff..d578b73c2d520d4c3d76d2928f481fc27731b63c 100644 --- a/include/class.list.php +++ b/include/class.list.php @@ -70,6 +70,7 @@ interface CustomListItem { function getConfiguration(); + function hasProperties(); function isEnabled(); function isDeletable(); function isEnableable(); @@ -664,6 +665,10 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { $this->clearStatus(self::ENABLED); } + function hasProperties() { + return ($this->getForm() && $this->getForm()->getFields()); + } + function getId() { return $this->get('id'); } @@ -733,6 +738,10 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { return $this->getConfigurationForm(); } + function getFields() { + return $this->getForm()->getFields(); + } + function getVar($name) { $config = $this->getConfiguration(); $name = mb_strtolower($name); @@ -768,6 +777,15 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { return $this->toString(); } + function display() { + return sprintf('<a class="preview" href="#" + data-preview="#list/%d/items/%d/preview">%s</a>', + $this->getListId(), + $this->getId(), + $this->getValue() + ); + } + function update($vars, &$errors=array()) { if (!$vars['value']) { @@ -1102,7 +1120,7 @@ implements CustomListItem, TemplateVariable { return $this->set($field, $this->get($field) | $flag); } - protected function hasProperties() { + function hasProperties() { return ($this->get('properties')); } diff --git a/include/staff/templates/list-item-preview.tmpl.php b/include/staff/templates/list-item-preview.tmpl.php new file mode 100644 index 0000000000000000000000000000000000000000..db9b87f8c2d1b7a0857f83356900b87d71eefe49 --- /dev/null +++ b/include/staff/templates/list-item-preview.tmpl.php @@ -0,0 +1,26 @@ +<?php +$name = $item->getValue(); +if ($abbrev=$item->getAbbrev()) + $name = sprintf('%s (%s)', $name, $abbrev); + +?> +<h2><?php echo Format::htmlchars($name); ?></h2> +<hr/> + +<?php +if ($item->hasProperties()) { ?> +<div> + <table class="custom-info" width="100%"> + <?php + foreach ($item->getFields() as $f) { + ?> + <tr><td style="width:30%;"><?php echo + Format::htmlchars($f->get('label')); ?>:</td> + <td><?php echo $f->display($f->value); ?></td> + </tr> + <?php } + ?> + </table> +</div> +<?php +} ?> diff --git a/include/staff/templates/list-item-row.tmpl.php b/include/staff/templates/list-item-row.tmpl.php index 574f28e97d8cc2ca9b4e1c00c96e1b293f1aee41..b54fee23f2f4aec32524e5ed98c3e61b12eb1c3a 100644 --- a/include/staff/templates/list-item-row.tmpl.php +++ b/include/staff/templates/list-item-row.tmpl.php @@ -7,12 +7,17 @@ <input type="checkbox" value="<?php echo $id; ?>" class="mass nowarn"/> </td> <td> - <a class="field-config" + <a class="field-config preview" style="overflow:inherit" href="#list/<?php echo $list->getId(); ?>/item/<?php echo $id ?>/update" id="item-<?php echo $id; ?>" + data-preview="<?php echo + sprintf('#/list/%d/items/%d/preview', + $item->getListId(), + $item->getId()); + ?>" ><?php echo sprintf('<i class="icon-edit" %s></i> ', ($prop_fields && !$item->getConfiguration()) diff --git a/scp/ajax.php b/scp/ajax.php index f01cf70b4bb00f0b4b4a6f17bab1c0d5d92e5a2c..de27157dc74093cf638db8a5a3e0550384e00857 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -71,6 +71,7 @@ $dispatcher = patterns('', url_get('^(?P<list>\w+)/items/search$', 'searchListItems'), url_get('^(?P<list>\w+)/item/(?P<id>\d+)/update$', 'getListItem'), url_post('^(?P<list>\w+)/item/(?P<id>\d+)/update$', 'saveListItem'), + url_get('^(?P<list>\w+)/items/(?P<id>\d+)/preview$', 'previewListItem'), url('^(?P<list>\w+)/item/add$', 'addListItem'), url('^(?P<list>\w+)/import$', 'importListItems'), url('^(?P<list>\w+)/manage$', 'massManageListItems'),