N°844 Portal: ExternalField support in forms has been improved. For example, email and url links were not displayed as proper HTML.

SVN:trunk[4854]
This commit is contained in:
Guillaume Lajarige
2017-08-08 11:59:53 +00:00
parent 66b6206daf
commit df4cad3ff1
5 changed files with 61 additions and 10 deletions

View File

@@ -3331,6 +3331,11 @@ class AttributeEmailAddress extends AttributeString
return $this->GetOptional('validation_pattern', '^'.utils::GetConfig()->Get('email_validation_pattern').'$');
}
static public function GetFormFieldClass()
{
return '\\Combodo\\iTop\\Form\\Field\\EmailField';
}
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
{
if (empty($sValue)) return '';
@@ -5078,19 +5083,15 @@ class AttributeExternalField extends AttributeDefinition
{
if ($oFormField === null)
{
$sFormFieldClass = static::GetFormFieldClass();
// ExternalField's FormField are actually based on the FormField from the target attribute.
$oRemoteAttDef = $this->GetExtAttDef();
$sFormFieldClass = $oRemoteAttDef::GetFormFieldClass();
$oFormField = new $sFormFieldClass($this->GetCode());
}
parent::MakeFormField($oObject, $oFormField);
// Note : As of today, this attribute is -by nature- only supported in readonly mode, not edition
$sAttCode = $this->GetCode();
$sAttCodeFriendlyname = $sAttCode . '_friendlyname';
if ($this->IsExternalKey(EXTKEY_ABSOLUTE) && MetaModel::IsValidAttCode(get_class($oObject), $sAttCodeFriendlyname))
{
$sAttCode = $sAttCodeFriendlyname;
}
$oFormField->SetCurrentValue(html_entity_decode($oObject->GetAsHTML($sAttCode), ENT_QUOTES, 'UTF-8'));
// Readonly field because we can't update external fields
$oFormField->SetReadOnly(true);
return $oFormField;
}

View File

@@ -32,6 +32,7 @@ require_once APPROOT . 'sources/form/field/hiddenfield.class.inc.php';
require_once APPROOT . 'sources/form/field/labelfield.class.inc.php';
require_once APPROOT . 'sources/form/field/stringfield.class.inc.php';
require_once APPROOT . 'sources/form/field/urlfield.class.inc.php';
require_once APPROOT . 'sources/form/field/emailfield.class.inc.php';
require_once APPROOT . 'sources/form/field/passwordfield.class.inc.php';
require_once APPROOT . 'sources/form/field/datetimefield.class.inc.php';
require_once APPROOT . 'sources/form/field/durationfield.class.inc.php';

View File

@@ -0,0 +1,43 @@
<?php
// Copyright (C) 2010-2017 Combodo SARL
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
namespace Combodo\iTop\Form\Field;
use \Str;
use \Combodo\iTop\Form\Field\StringField;
/**
* Description of EmailField
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
*/
class EmailField extends StringField
{
public function GetDisplayValue()
{
$sLabel = Str::pure2html($this->currentValue);
if (strlen($sLabel) > 128)
{
// Truncate the length to 128 characters, by removing the middle
$sLabel = substr($sLabel, 0, 100).'.....'.substr($sLabel, -20);
}
return "<a class=\"mailto\" href=\"mailto:$this->currentValue\">$sLabel</a>";
}
}

View File

@@ -45,6 +45,7 @@ class BsFormRenderer extends FormRenderer
$this->AddSupportedField('PasswordField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('StringField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('UrlField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('EmailField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('TextAreaField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('CaseLogField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('SelectField', 'BsSimpleFieldRenderer');

View File

@@ -59,6 +59,7 @@ class BsSimpleFieldRenderer extends FieldRenderer
case 'Combodo\\iTop\\Form\\Field\\PasswordField':
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\EmailField':
case 'Combodo\\iTop\\Form\\Field\\SelectField':
case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
// Opening container
@@ -98,6 +99,7 @@ EOF
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\EmailField':
$oOutput->AddHtml('<input type="text" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('" class="form-control" maxlength="255" />');
break;
@@ -226,6 +228,7 @@ EOF
case 'Combodo\\iTop\\Form\\Field\\LabelField':
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\EmailField':
case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
case 'Combodo\\iTop\\Form\\Field\\DurationField':
// Opening container
@@ -243,7 +246,7 @@ EOF
$oOutput->AddHtml('</div>');
// Value
$bEncodeHtmlEntities = ($sFieldClass === 'Combodo\\iTop\\Form\\Field\\UrlField') ? false : true;
$bEncodeHtmlEntities = (in_array($sFieldClass, array('Combodo\\iTop\\Form\\Field\\UrlField', 'Combodo\\iTop\\Form\\Field\\EmailField'))) ? false : true;
$oOutput->AddHtml('<div class="form_field_control">');
$oOutput->AddHtml('<div class="form-control-static">')->AddHtml($this->oField->GetDisplayValue(), $bEncodeHtmlEntities)->AddHtml('</div>');
$oOutput->AddHtml('</div>');
@@ -392,6 +395,7 @@ EOF
case 'Combodo\\iTop\\Form\\Field\\PasswordField':
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\EmailField':
case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
case 'Combodo\\iTop\\Form\\Field\\CaseLogField':
case 'Combodo\\iTop\\Form\\Field\\SelectField':
@@ -465,6 +469,7 @@ EOF
case 'Combodo\\iTop\\Form\\Field\\PasswordField':
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\EmailField':
case 'Combodo\\iTop\\Form\\Field\\SelectField':
case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
case 'Combodo\\iTop\\Form\\Field\\HiddenField':