N°829 Portal: AttributeUrl was not clickable in the new portal

SVN:trunk[4686]
This commit is contained in:
Guillaume Lajarige
2017-04-19 15:36:00 +00:00
parent 9c5b3818eb
commit 2e8c629195
5 changed files with 97 additions and 5 deletions

View File

@@ -4870,6 +4870,25 @@ class AttributeURL extends AttributeString
{
return $this->GetOptional('validation_pattern', '^'.utils::GetConfig()->Get('url_validation_pattern').'$');
}
static public function GetFormFieldClass()
{
return '\\Combodo\\iTop\\Form\\Field\\UrlField';
}
public function MakeFormField(DBObject $oObject, $oFormField = null)
{
if ($oFormField === null)
{
$sFormFieldClass = static::GetFormFieldClass();
$oFormField = new $sFormFieldClass($this->GetCode());
}
parent::MakeFormField($oObject, $oFormField);
$oFormField->SetTarget($this->Get('target'));
return $oFormField;
}
}
/**

View File

@@ -30,6 +30,7 @@ require_once APPROOT . 'sources/form/field/textfield.class.inc.php';
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/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,67 @@
<?php
// Copyright (C) 2010-2016 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 UrlField
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
*/
class UrlField extends StringField
{
const DEFAULT_TARGET = '_blank';
protected $sTarget;
/**
* Default constructor
*
* @param string $sId
* @param Closure $onFinalizeCallback (Used in the $oForm->AddField($sId, ..., function() use ($oManager, $oForm, '...') { ... } ); )
*/
public function __construct($sId, Closure $onFinalizeCallback = null)
{
parent::__construct($sId, $onFinalizeCallback);
$this->sTarget = static::DEFAULT_TARGET;
}
public function SetTarget($sTarget)
{
$this->sTarget = $sTarget;
return $this;
}
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 target=\"$this->sTarget\" href=\"$this->currentValue\">$sLabel</a>";
}
}

View File

@@ -43,7 +43,8 @@ class BsFormRenderer extends FormRenderer
$this->AddSupportedField('HiddenField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('LabelField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('PasswordField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('StringField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('StringField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('UrlField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('TextAreaField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('CaseLogField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('SelectField', 'BsSimpleFieldRenderer');

View File

@@ -84,6 +84,7 @@ EOF
break;
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
$oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
if ($this->oField->GetLabel() !== '')
{
@@ -210,7 +211,8 @@ EOF
$oOutput->AddHtml('</div>');
break;
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
$oOutput->AddHtml('<div class="form-group">');
// Showing label / value only if read-only but not hidden
@@ -221,7 +223,7 @@ EOF
$oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
}
if($sFieldClass === 'Combodo\\iTop\\Form\\Field\\TextAreaField')
if($sFieldClass === 'Combodo\\iTop\\Form\\Field\\UrlField' || $sFieldClass === 'Combodo\\iTop\\Form\\Field\\TextAreaField')
{
$bEncodeHtmlEntities = false;
$sDisplayValue = $this->oField->GetDisplayValue();
@@ -324,7 +326,8 @@ EOF
switch ($sFieldClass)
{
case 'Combodo\\iTop\\Form\\Field\\PasswordField':
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
case 'Combodo\\iTop\\Form\\Field\\CaseLogField':
case 'Combodo\\iTop\\Form\\Field\\SelectField':
@@ -396,7 +399,8 @@ EOF
switch ($sFieldClass)
{
case 'Combodo\\iTop\\Form\\Field\\PasswordField':
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\SelectField':
case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
case 'Combodo\\iTop\\Form\\Field\\HiddenField':