N°2922 - Revert 93a1f027 and add support for LabelField in the ConsoleFormRenderer (was already done in PortalFormRenderer)

This commit is contained in:
Molkobain
2021-04-29 12:02:13 +02:00
parent cbc5bb70d0
commit cfab20519e
3 changed files with 25 additions and 23 deletions

View File

@@ -5,7 +5,9 @@
*/
use Combodo\iTop\Application\UI\Base\Component\FieldBadge\FieldBadgeUIBlockFactory;
use Combodo\iTop\Form\Field\LabelField;
use Combodo\iTop\Form\Field\TextAreaField;
use Combodo\iTop\Form\Form;
use Combodo\iTop\Form\Validator\NotEmptyExtKeyValidator;
use Combodo\iTop\Form\Validator\Validator;
use Combodo\iTop\Renderer\BlockRenderer;
@@ -12622,19 +12624,17 @@ class AttributeCustomFields extends AttributeDefinition
*/
public function GetForm(DBObject $oHostObject, $sFormPrefix = null)
{
try
{
try {
$oValue = $oHostObject->Get($this->GetCode());
$oHandler = $this->GetHandler($oValue->GetValues());
$sFormId = is_null($sFormPrefix) ? 'cf_'.$this->GetCode() : $sFormPrefix.'_cf_'.$this->GetCode();
$oHandler->BuildForm($oHostObject, $sFormId);
$oForm = $oHandler->GetForm();
} catch (Exception $e) {
$oForm = new \Combodo\iTop\Form\Form('');
$oField = new \Combodo\iTop\Form\Field\StringField('');
$oField->SetReadOnly(true);
$oField->SetLabel('Custom field error: ');
$oField->SetCurrentValue($e->getMessage());
}
catch (Exception $e) {
$oForm = new Form('');
$oField = new LabelField('');
$oField->SetLabel('Custom field error: '.$e->getMessage());
$oForm->AddField($oField);
$oForm->Finalize();
}

View File

@@ -29,6 +29,7 @@ class ConsoleFormRenderer extends FormRenderer
{
parent::__construct($oForm);
$this->AddSupportedField('HiddenField', 'ConsoleSimpleFieldRenderer');
$this->AddSupportedField('LabelField', 'ConsoleSimpleFieldRenderer');
$this->AddSupportedField('StringField', 'ConsoleSimpleFieldRenderer');
$this->AddSupportedField('SelectField', 'ConsoleSimpleFieldRenderer');
$this->AddSupportedField('TextAreaField', 'ConsoleSimpleFieldRenderer');

View File

@@ -64,24 +64,27 @@ class ConsoleSimpleFieldRenderer extends FieldRenderer
{
$oOutput->AddHtml('<input type="hidden" id="'.$this->oField->GetGlobalId().'" value="' . htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8') . '"/>');
$oOutput->AddHtml('<span class="form-field-data">'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'</span>');
} else {
$oOutput->AddHtml('<input class="form-field-data datetime-pick" size="15" type="text" placeholder="'.htmlentities($sPlaceHolder, ENT_QUOTES, 'UTF-8').'" id="'.$this->oField->GetGlobalId().'" value="'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES,
'UTF-8').'" size="30"/>');
}
else
{
$oOutput->AddHtml('<input class="form-field-data datetime-pick" size="15" type="text" placeholder="'.htmlentities($sPlaceHolder, ENT_QUOTES, 'UTF-8').'" id="'.$this->oField->GetGlobalId().'" value="'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'" size="30"/>');
}
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
break;
case 'Combodo\\iTop\\Form\\Field\\LabelField':
$oOutput->AddHtml('<td class="form-field-content">');
$oOutput->AddHtml('<span class="form-field-data">'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'</span>');
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
break;
case 'Combodo\\iTop\\Form\\Field\\StringField':
$oOutput->AddHtml('<td class="form-field-content">');
if ($this->oField->GetReadOnly())
{
$oOutput->AddHtml('<input type="hidden" id="'.$this->oField->GetGlobalId().'" value="' . htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8') . '"/>');
if ($this->oField->GetReadOnly()) {
$oOutput->AddHtml('<input type="hidden" id="'.$this->oField->GetGlobalId().'" value="'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'"/>');
$oOutput->AddHtml('<span class="form-field-data">'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'</span>');
}
else
{
} else {
$oOutput->AddHtml('<input class="form-field-data" type="text" id="'.$this->oField->GetGlobalId().'" value="'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'" size="30"/>');
}
$oOutput->AddHtml('<span class="form_validation"></span>');
@@ -92,11 +95,9 @@ class ConsoleSimpleFieldRenderer extends FieldRenderer
$bRichEditor = ($this->oField->GetFormat() === TextAreaField::ENUM_FORMAT_HTML);
$oOutput->AddHtml('<td class="form-field-content">');
if ($this->oField->GetReadOnly())
{
$oOutput->AddHtml('<textarea disabled="disabled" id="' . $this->oField->GetGlobalId() . '" class="form-field-data resizable" rows="8" cols="40">' . $this->oField->GetCurrentValue() . '</textarea>');
}
else
if ($this->oField->GetReadOnly()) {
$oOutput->AddHtml('<textarea disabled="disabled" id="'.$this->oField->GetGlobalId().'" class="form-field-data resizable" rows="8" cols="40">'.$this->oField->GetCurrentValue().'</textarea>');
} else
{
$oOutput->AddHtml('<textarea id="' . $this->oField->GetGlobalId() . '" class="form-field-data resizable" rows="8" cols="40">' . $this->oField->GetCurrentValue() . '</textarea>');
// Some additional stuff if we are displaying it with a rich editor