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 bde36701dec0f1de84e6b3cf33ae9b6631a967b2..7bb040814714eeaa7b6f4400ef84d3e98391cccf 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -1448,6 +1448,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..69106502be674220c0f2c36c2293932554245471 100644 --- a/include/class.list.php +++ b/include/class.list.php @@ -68,8 +68,12 @@ interface CustomListItem { function getAbbrev(); function getSortOrder(); + function getList(); + function getListId(); + function getConfiguration(); + function hasProperties(); function isEnabled(); function isDeletable(); function isEnableable(); @@ -664,10 +668,18 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { $this->clearStatus(self::ENABLED); } + function hasProperties() { + return ($this->getForm() && $this->getForm()->getFields()); + } + function getId() { return $this->get('id'); } + function getList() { + return $this->list; + } + function getListId() { return $this->get('list_id'); } @@ -733,6 +745,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 +784,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 +1127,7 @@ implements CustomListItem, TemplateVariable { return $this->set($field, $this->get($field) | $flag); } - protected function hasProperties() { + function hasProperties() { return ($this->get('properties')); } @@ -1254,6 +1279,11 @@ implements CustomListItem, TemplateVariable { return $this->_list; } + function getListId() { + if (($list = $this->getList())) + return $list->getId(); + } + function getConfigurationForm($source=null) { if (!$this->_form) { $config = $this->getConfiguration(); @@ -1283,6 +1313,10 @@ implements CustomListItem, TemplateVariable { return $this->_form; } + function getFields() { + return $this->getConfigurationForm()->getFields(); + } + function getConfiguration() { if (!$this->_settings) { @@ -1367,6 +1401,15 @@ implements CustomListItem, TemplateVariable { return count($errors) === 0; } + function display() { + return sprintf('<a class="preview" href="#" + data-preview="#list/%d/items/%d/preview">%s</a>', + $this->getListId(), + $this->getId(), + $this->getLocalName() + ); + } + function update($vars, &$errors) { $fields = array('name', 'sort'); foreach($fields as $k) { 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..3ffcd1998faf69ef71af61c492f049c93d57ece3 --- /dev/null +++ b/include/staff/templates/list-item-preview.tmpl.php @@ -0,0 +1,27 @@ +<?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) { + if (!$f->isVisible()) continue; + ?> + <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/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index 62ac75e116a99c49ec2f3dfac78039584765331f..0ebf5cbf2e134d6d557556c053b848da35e516c6 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -239,7 +239,7 @@ if($ticket->isOverdue()) <table border="0" cellspacing="" cellpadding="4" width="100%"> <tr> <th width="100"><?php echo __('Status');?>:</th> - <td><?php echo ($S = $ticket->getStatus()) ? $S->getLocalName() : ''; ?></td> + <td><?php echo ($S = $ticket->getStatus()) ? $S->display() : ''; ?></td> </tr> <tr> <th><?php echo __('Priority');?>:</th> 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'),