diff --git a/application/forms.class.inc.php b/application/forms.class.inc.php index 74965a92f..2e35035e9 100644 --- a/application/forms.class.inc.php +++ b/application/forms.class.inc.php @@ -37,6 +37,7 @@ class DesignerForm protected $sSubmitTo; protected $bReadOnly; protected $sSelectorClass; + protected $bDisplayed; public function __construct() { @@ -51,6 +52,7 @@ class DesignerForm $this->bReadOnly = false; $this->sSelectorClass = ''; $this->StartFieldSet($this->sCurrentFieldSet); + $this->bDisplayed = true; } public function AddField(DesignerFormField $oField) @@ -365,7 +367,23 @@ EOF return $this->oParentForm; } - + public function SetDisplayed($bDisplayed) + { + $this->bDisplayed = $bDisplayed; + } + + public function IsDisplayed() + { + if ($this->oParentForm == null) + { + return $this->bDisplayed; + } + else + { + return ($this->bDisplayed && $this->oParentForm->IsDisplayed()); + } + } + public function AddScript($sScript) { $this->sScript .= $sScript; @@ -513,6 +531,7 @@ class DesignerFormField protected $bReadOnly; protected $bAutoApply; protected $aCSSClasses; + protected $bDisplayed; public function __construct($sCode, $sLabel, $defaultValue) { @@ -523,6 +542,7 @@ class DesignerFormField $this->bReadOnly = false; $this->bAutoApply = false; $this->aCSSClasses = array(); + $this->bDisplayed = true; } public function GetCode() @@ -561,6 +581,16 @@ class DesignerFormField return $this->bAutoApply; } + public function SetDisplayed($bDisplayed) + { + $this->bDisplayed = $bDisplayed; + } + + public function IsDisplayed() + { + return $this->bDisplayed; + } + public function Render(WebPage $oP, $sFormId, $sRenderMode='dialog') { $sId = $this->oForm->GetFieldId($this->sCode); @@ -670,20 +700,25 @@ class DesignerTextField extends DesignerFormField { $sId = $this->oForm->GetFieldId($this->sCode); $sName = $this->oForm->GetFieldName($this->sCode); - $sPattern = addslashes($this->sValidationPattern); - if (is_array($this->aForbiddenValues)) + if ($this->IsReadOnly()) { - $sForbiddenValues = json_encode($this->aForbiddenValues); - $sExplainForbiddenValues = addslashes($this->sExplainForbiddenValues); + $sHtmlValue = "".htmlentities($this->defaultValue, ENT_QUOTES, 'UTF-8')."defaultValue, ENT_QUOTES, 'UTF-8')."\"/>"; } else { - $sForbiddenValues = 'null'; - $sExplainForbiddenValues = 'null'; - } - $sMandatory = $this->bMandatory ? 'true' : 'false'; - $sReadOnly = $this->IsReadOnly() ? 'readonly' : ''; - $oP->add_ready_script( + $sPattern = addslashes($this->sValidationPattern); + if (is_array($this->aForbiddenValues)) + { + $sForbiddenValues = json_encode($this->aForbiddenValues); + $sExplainForbiddenValues = addslashes($this->sExplainForbiddenValues); + } + else + { + $sForbiddenValues = 'null'; + $sExplainForbiddenValues = 'null'; + } + $sMandatory = $this->bMandatory ? 'true' : 'false'; + $oP->add_ready_script( <<aCSSClasses) > 0) - { - $sCSSClasses = 'class="'.implode(' ', $this->aCSSClasses).'"'; + ); + $sCSSClasses = ''; + if (count($this->aCSSClasses) > 0) + { + $sCSSClasses = 'class="'.implode(' ', $this->aCSSClasses).'"'; + } + $sHtmlValue = "defaultValue, ENT_QUOTES, 'UTF-8')."\">"; } - return array('label' => $this->sLabel, 'value' => "defaultValue, ENT_QUOTES, 'UTF-8')."\">"); + return array('label' => $this->sLabel, 'value' => $sHtmlValue); } public function ReadParam(&$aValues) @@ -798,39 +835,67 @@ class DesignerComboField extends DesignerFormField { $sCSSClasses = 'class="'.implode(' ', $this->aCSSClasses).'"'; } - if ($this->bMultipleSelection) + if ($this->IsReadOnly()) { - $sHtml = ""; + } + } + else + { + if ($sKey == $this->defaultValue) + { + $aSelected[] = $sDisplayValue; + $aHiddenValues[] = ""; + } + } + } + $sHtml = "".htmlentities(implode(', ', $aSelected), ENT_QUOTES, 'UTF-8').implode($aHiddenValues).""; } else - { - $sHtml = ""; } else { - $sSelected = ($sKey == $this->defaultValue) ? 'selected' : ''; + $sHtml = ""; - if ($this->bOtherChoices) - { - $sHtml .= '
 '; - } - $oP->add_ready_script( + foreach($this->aAllowedValues as $sKey => $sDisplayValue) + { + if ($this->bMultipleSelection) + { + $sSelected = in_array($sKey, $this->defaultValue) ? 'selected' : ''; + } + else + { + $sSelected = ($sKey == $this->defaultValue) ? 'selected' : ''; + } + // Quick and dirty: display the menu parents as a tree + $sHtmlValue = str_replace(' ', ' ', htmlentities($sDisplayValue, ENT_QUOTES, 'UTF-8')); + $sHtml .= ""; + } + $sHtml .= ""; + if ($this->bOtherChoices) + { + $sHtml .= '
 '; + } + $oP->add_ready_script( << $this->sLabel, 'value' => $sHtml); } @@ -857,14 +922,21 @@ class DesignerBooleanField extends DesignerFormField $sId = $this->oForm->GetFieldId($this->sCode); $sName = $this->oForm->GetFieldName($this->sCode); $sChecked = $this->defaultValue ? 'checked' : ''; - $sReadOnly = $this->IsReadOnly() ? 'disabled' : ''; // readonly does not work as expected on checkboxes: - // readonly prevents the user from changing the input's value not its state (checked/unchecked) - $sCSSClasses = ''; - if (count($this->aCSSClasses) > 0) + if ($this->IsReadOnly()) { - $sCSSClasses = 'class="'.implode(' ', $this->aCSSClasses).'"'; + $sLabel = $this->defaultValue ? Dict::S('UI:UserManagement:ActionAllowed:Yes') : Dict::S('UI:UserManagement:ActionAllowed:No'); //TODO use our own yes/no translations + $sHtmlValue = "".htmlentities($sLabel)."defaultValue, ENT_QUOTES, 'UTF-8')."\"/>"; } - return array('label' => $this->sLabel, 'value' => ""); + else + { + $sCSSClasses = ''; + if (count($this->aCSSClasses) > 0) + { + $sCSSClasses = 'class="'.implode(' ', $this->aCSSClasses).'"'; + } + $sHtmlValue = ""; + } + return array('label' => $this->sLabel, 'value' => $sHtmlValue); } public function ReadParam(&$aValues) @@ -1055,7 +1127,8 @@ class DesignerSortableField extends DesignerFormField $bOpen = false; $sId = $this->oForm->GetFieldId($this->sCode); $sName = $this->oForm->GetFieldName($this->sCode); - $aResult = array('label' => $this->sLabel, 'value' => "defaultValue, ENT_QUOTES, 'UTF-8')."\">"); + $sReadOnly = $this->IsReadOnly() ? 'readonly="readonly"' : ''; + $aResult = array('label' => $this->sLabel, 'value' => "defaultValue, ENT_QUOTES, 'UTF-8')."\">"); $sJSFields = json_encode(array_keys($this->aAllowedValues)); @@ -1100,15 +1173,39 @@ class DesignerFormSelectorField extends DesignerFormField { $sCSSClasses = 'class="'.implode(' ', $this->aCSSClasses).'"'; } - $sHtml = ""; + + if ($this->IsReadOnly()) + { + $aSelected = array(); + $aHiddenValues = array(); + $sDisplayValue = ''; + $sHiddenValue = ''; + foreach($this->aSubForms as $sKey => $aFormData) + { + if ($sKey == $this->defaultValue) + { + $sDisplayValue = htmlentities($aFormData['label'], ENT_QUOTES, 'UTF-8'); + $sHiddenValue = ""; + break; + } + } + $sHtml = "".$sDisplayValue.$sHiddenValue.""; + } + else + { + + + $sHtml = ""; + } + if ($sRenderMode == 'property') { $sHtml .= ''; @@ -1117,7 +1214,7 @@ class DesignerFormSelectorField extends DesignerFormField foreach($this->aSubForms as $sKey => $aFormData) { $sId = $this->oForm->GetFieldId($this->sCode); - $sStyle = ($sKey == $this->defaultValue) ? '' : 'style="display:none"'; + $sStyle = (($sKey == $this->defaultValue) && $this->oForm->IsDisplayed()) ? '' : 'style="display:none"'; $oSubForm = $aFormData['form']; $oSubForm->SetParentForm($this->oForm); $oSubForm->CopySubmitParams($this->oForm); @@ -1126,6 +1223,7 @@ class DesignerFormSelectorField extends DesignerFormField if ($sRenderMode == 'property') { + $oSubForm->SetDisplayed($sKey == $this->defaultValue); $sHtml .= ""; $sHtml .= $oSubForm->RenderAsPropertySheet($oP, true); $oParentForm = $this->oForm->GetParentForm();