From 6d2d0ff7010139ce754adcdb09613eb093a056a7 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Tue, 23 Dec 2014 15:23:12 +0000 Subject: [PATCH] - Read-only "long text" fields no longer appear as editable - Combo and FormSelector fields are now sorted by default (but sorting can be disabled if needed) SVN:trunk[3483] --- application/forms.class.inc.php | 67 +++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/application/forms.class.inc.php b/application/forms.class.inc.php index 60ed36117..1f30e4d93 100644 --- a/application/forms.class.inc.php +++ b/application/forms.class.inc.php @@ -972,8 +972,14 @@ class DesignerLongTextField extends DesignerTextField $sExplainForbiddenValues = 'null'; } $sMandatory = $this->bMandatory ? 'true' : 'false'; - $sReadOnly = $this->IsReadOnly() ? 'readonly' : ''; - $oP->add_ready_script( + $sCSSClasses = ''; + if (count($this->aCSSClasses) > 0) + { + $sCSSClasses = 'class="'.implode(' ', $this->aCSSClasses).'"'; + } + if (!$this->IsReadOnly()) + { + $oP->add_ready_script( <<aCSSClasses) > 0) - { - $sCSSClasses = 'class="'.implode(' ', $this->aCSSClasses).'"'; + ); + $sValue = ""; } - return array('label' => $this->sLabel, 'value' => ""); + else + { + $sValue = "
".htmlentities($this->defaultValue, ENT_QUOTES, 'UTF-8')."
"; + } + return array('label' => $this->sLabel, 'value' => $sValue); } } @@ -1065,6 +1072,7 @@ class DesignerComboField extends DesignerFormField protected $bMultipleSelection; protected $bOtherChoices; protected $sNullLabel; + protected $bSorted; public function __construct($sCode, $sLabel = '', $defaultValue = '') { @@ -1075,6 +1083,7 @@ class DesignerComboField extends DesignerFormField $this->sNullLabel = Dict::S('UI:SelectOne'); $this->bAutoApply = true; + $this->bSorted = true; // Sorted by default } public function SetAllowedValues($aAllowedValues) @@ -1100,6 +1109,16 @@ class DesignerComboField extends DesignerFormField $this->sNullLabel = $sLabel; } + public function IsSorted() + { + return $this->bSorted; + } + + public function SetSorted($bSorted) + { + $this->bSorted = $bSorted; + } + public function Render(WebPage $oP, $sFormId, $sRenderMode='dialog') { $sId = $this->oForm->GetFieldId($this->sCode); @@ -1107,6 +1126,10 @@ class DesignerComboField extends DesignerFormField $sChecked = $this->defaultValue ? 'checked' : ''; $sMandatory = $this->bMandatory ? 'true' : 'false'; $sReadOnly = $this->IsReadOnly() ? 'disabled="disabled"' : ''; + if ($this->IsSorted()) + { + asort($this->aAllowedValues); + } $sCSSClasses = ''; if (count($this->aCSSClasses) > 0) { @@ -1428,13 +1451,37 @@ class DesignerFormSelectorField extends DesignerFormField { protected $aSubForms; protected $defaultRealValue; // What's stored as default value is actually the index + protected $bSorted; + public function __construct($sCode, $sLabel = '', $defaultValue = '') { parent::__construct($sCode, $sLabel, 0); $this->defaultRealValue = $defaultValue; $this->aSubForms = array(); + $this->bSorted = true; + } + + public function IsSorted() + { + return $this->bSorted; } + public function SetSorted($bSorted) + { + $this->bSorted = $bSorted; + } + + /** + * Callback for sorting an array of $aFormData based ont he labels of the subforms + * @param unknown $aItem1 + * @param unknown $aItem2 + * @return number + */ + static function SortOnFormLabel($aItem1, $aItem2) + { + return strcasecmp($aItem1['label'], $aItem2['label']); + } + public function GetWidgetClass() { return 'selector_property_field'; @@ -1465,6 +1512,10 @@ class DesignerFormSelectorField extends DesignerFormField $sCSSClasses = 'class="'.implode(' ', $this->aCSSClasses).'"'; } + if ($this->IsSorted()) + { + uasort($this->aSubForms, array(get_class($this), 'SortOnFormLabel')); + } if ($this->IsReadOnly()) {