From 9c6b2a202a367d1a7e2fea8c1b8c852420871a62 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Mon, 7 Jul 2014 13:42:55 +0000 Subject: [PATCH] Add ability to render choice field in view mode. --- include/class.forms.php | 21 +++++++++++----- include/class.user.php | 4 ++++ .../templates/list-item-properties.tmpl.php | 24 +++++++++++-------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/include/class.forms.php b/include/class.forms.php index 877a6a086..8e58ca494 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -1016,7 +1016,7 @@ class Widget { class TextboxWidget extends Widget { static $input_type = 'text'; - function render() { + function render($mode=false) { $config = $this->field->getConfiguration(); if (isset($config['size'])) $size = "size=\"{$config['size']}\""; @@ -1056,7 +1056,7 @@ class PasswordWidget extends TextboxWidget { } class TextareaWidget extends Widget { - function render() { + function render($mode=false) { $config = $this->field->getConfiguration(); $class = $cols = $rows = $maxlength = ""; if (isset($config['rows'])) @@ -1080,7 +1080,7 @@ class TextareaWidget extends Widget { } class PhoneNumberWidget extends Widget { - function render() { + function render($mode=false) { $config = $this->field->getConfiguration(); list($phone, $ext) = explode("X", $this->value); ?> @@ -1109,6 +1109,15 @@ class PhoneNumberWidget extends Widget { class ChoicesWidget extends Widget { function render($mode=false) { + + if ($mode && $mode =='view') { + if (!($val = (string) $this->field)) + $val = '<span class="faded">None</span>'; + + echo $val; + return; + } + $config = $this->field->getConfiguration(); // Determine the value for the default (the one listed if nothing is // selected) @@ -1178,7 +1187,7 @@ class CheckboxWidget extends Widget { $this->name = '_field-checkboxes'; } - function render() { + function render($mode=false) { $config = $this->field->getConfiguration(); if (!isset($this->value)) $this->value = $this->field->get('default'); @@ -1202,7 +1211,7 @@ class CheckboxWidget extends Widget { } class DatetimePickerWidget extends Widget { - function render() { + function render($mode=false) { global $cfg; $config = $this->field->getConfiguration(); @@ -1272,7 +1281,7 @@ class DatetimePickerWidget extends Widget { } class SectionBreakWidget extends Widget { - function render() { + function render($mode=false) { ?><div class="form-header section-break"><h3><?php echo Format::htmlchars($this->field->get('label')); ?></h3><em><?php echo Format::htmlchars($this->field->get('hint')); diff --git a/include/class.user.php b/include/class.user.php index b137d49ee..9129b1e2e 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -254,6 +254,10 @@ class User extends UserModel { return JsonDataEncoder::encode($info); } + function __toString() { + return $this->asVar(); + } + function asVar() { return (string) $this->getName(); } diff --git a/include/staff/templates/list-item-properties.tmpl.php b/include/staff/templates/list-item-properties.tmpl.php index ef7158d03..6c6f09656 100644 --- a/include/staff/templates/list-item-properties.tmpl.php +++ b/include/staff/templates/list-item-properties.tmpl.php @@ -33,16 +33,20 @@ </td><td> <span style="display:inline-block;width:100%"> <?php - $f->render(); - if ($f->get('required')) { ?> - <font class="error">*</font> - <?php - } - if ($f->get('hint')) { ?> - <br /><em style="color:gray;display:inline-block"><?php - echo Format::htmlchars($f->get('hint')); ?></em> - <?php - } + if ($item->isInternal() && $f->isConfigurable()) + $f->render('view'); + else { + $f->render(); + if ($f->get('required')) { ?> + <font class="error">*</font> + <?php + } + if ($f->get('hint')) { ?> + <br /><em style="color:gray;display:inline-block"><?php + echo Format::htmlchars($f->get('hint')); ?></em> + <?php + } + } ?> </span> <?php -- GitLab