瀏覽代碼

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

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4686 a333f486-631f-4898-b8df-5754b55c2be0
glajarige 8 年之前
父節點
當前提交
d694f2b506

+ 19 - 0
core/attributedef.class.inc.php

@@ -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;
+    }
 }
 
 /**

+ 1 - 0
sources/autoload.php

@@ -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';

+ 67 - 0
sources/form/field/urlfield.class.inc.php

@@ -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>";
+    }
+}

+ 2 - 1
sources/renderer/bootstrap/bsformrenderer.class.inc.php

@@ -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');

+ 8 - 4
sources/renderer/bootstrap/fieldrenderer/bssimplefieldrenderer.class.inc.php

@@ -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':