N°1405 Add support of AttributePhoneNumber which allows launch of phone application on click.

SVN:trunk[5698]
This commit is contained in:
Guillaume Lajarige
2018-04-19 15:56:11 +00:00
parent 512f368cbf
commit 18bd0ae096
15 changed files with 199 additions and 67 deletions

View File

@@ -3430,7 +3430,10 @@ class AttributeEmailAddress extends AttributeString
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
{
if (empty($sValue)) return '';
return '<a class="mailto" href="mailto:'.$sValue.'">'.parent::GetAsHTML($sValue).'</a>';
$sUrlDecorationClass = utils::GetConfig()->Get('email_decoration_class');
return '<a class="mailto" href="mailto:'.$sValue.'"><span class="text_decoration '.$sUrlDecorationClass.'"></span>'.parent::GetAsHTML($sValue).'</a>';
}
}
@@ -3454,6 +3457,35 @@ class AttributeIPAddress extends AttributeString
}
}
/**
* Specialization of a string: phone number
*
* @package iTopORM
*/
class AttributePhoneNumber extends AttributeString
{
public function GetValidationPattern()
{
return $this->GetOptional('validation_pattern', '^'.utils::GetConfig()->Get('phone_number_validation_pattern').'$');
}
static public function GetFormFieldClass()
{
return '\\Combodo\\iTop\\Form\\Field\\PhoneField';
}
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
{
if (empty($sValue)) return '';
$sUrlDecorationClass = utils::GetConfig()->Get('phone_number_decoration_class');
$sUrlPattern = utils::GetConfig()->Get('phone_number_url_pattern');
$sUrl = sprintf($sUrlPattern, $sValue);
return '<a class="tel" href="'.$sUrl.'"><span class="text_decoration '.$sUrlDecorationClass.'"></span>'.parent::GetAsHTML($sValue).'</a>';
}
}
/**
* Specialization of a string: OQL expression
*

View File

@@ -764,14 +764,46 @@ class Config
'source_of_value' => '',
'show_in_conf_sample' => true,
),
'email_validation_pattern' => array(
'type' => 'string',
'description' => 'Regular expression to validate/detect the format of an eMail address',
'default' => "[a-zA-Z0-9._&'-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,}",
'value' => '',
'source_of_value' => '',
'show_in_conf_sample' => true,
),
'email_validation_pattern' => array(
'type' => 'string',
'description' => 'Regular expression to validate/detect the format of an eMail address',
'default' => "[a-zA-Z0-9._&'-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,}",
'value' => '',
'source_of_value' => '',
'show_in_conf_sample' => true,
),
'email_decoration_class' => array(
'type' => 'string',
'description' => 'CSS class(es) to use as decoration for the HTML rendering of the attribute. eg. "fa fa-envelope" will put a mail icon.',
'default' => 'fa fa-envelope',
'value' => '',
'source_of_value' => '',
'show_in_conf_sample' => false,
),
'phone_number_validation_pattern' => array(
'type' => 'string',
'description' => 'Regular expression to validate/detect the format of a phone number',
'default' => "[0-9.\-\ \+\(\)]+",
'value' => '',
'source_of_value' => '',
'show_in_conf_sample' => false,
),
'phone_number_url_pattern' => array(
'type' => 'string',
'description' => 'Format for phone number url, use %1$s as a placeholder for the value. eg. "tel:%1$s" for regular phone applications or "callto:%1$s" for Skype. Default is "tel:%1$s".',
'default' => 'tel:%1$s',
'value' => '',
'source_of_value' => '',
'show_in_conf_sample' => false,
),
'phone_number_decoration_class' => array(
'type' => 'string',
'description' => 'CSS class(es) to use as decoration for the HTML rendering of the attribute. eg. "fa fa-phone" will put a phone icon.',
'default' => 'fa fa-phone',
'value' => '',
'source_of_value' => '',
'show_in_conf_sample' => false,
),
'log_kpi_duration' => array(
'type' => 'integer',
'description' => 'Level of logging for troubleshooting performance issues (1 to enable, 2 +blame callers)',

View File

@@ -301,17 +301,15 @@ td a.no-arrow:hover {
padding-left: 0px;
background: inherit;
}
td a.mailto, td a.mailto:visited {
text-decoration: none;
color: #000;
padding-left: 20px;
background: url(../images/mail.png?v=v2.5.0) no-repeat left;
td a:hover .text_decoration, td a:visited:hover .text_decoration {
color: #d56e14;
}
td a.mailto:hover {
text-decoration: underline;
td a .text_decoration, td a:visited .text_decoration {
vertical-align: baseline;
text-decoration: none;
color: #ea7d1e;
padding-left: 20px;
background: url(../images/mail.png?v=v2.5.0) no-repeat left;
margin-right: 8px;
transition: color 0.2s ease-in-out;
}
a.small_action {
font-family: Tahoma, Verdana, Arial, Helvetica;

View File

@@ -357,17 +357,21 @@ td a.no-arrow:hover {
padding-left:0px;
background: inherit;
}
td a.mailto, td a.mailto:visited {
text-decoration:none;
color:#000000;
padding-left:20px;
background: url(../images/mail.png?v=#{$version}) no-repeat left;
}
td a.mailto:hover {
text-decoration:underline;
color:$highlight-color;
padding-left:20px;
background: url(../images/mail.png?v=#{$version}) no-repeat left;
td a,
td a:visited{
&:hover{
.text_decoration{
color: darken($highlight-color, 6%);
}
}
.text_decoration{
vertical-align: baseline;
text-decoration: none;
color: $highlight-color;
margin-right: 8px;
transition: color 0.2s ease-in-out;
}
}
a.small_action {

View File

@@ -934,6 +934,10 @@ table .group-actions {
color: #ea7d1e;
font-size: 0.9em;
}
.form_field .form_field_decoration {
vertical-align: baseline;
margin-right: 8px;
}
/* ExternalKey */
.selectobject .input-group-addon {
cursor: pointer;

View File

@@ -1016,6 +1016,10 @@ table .group-actions .item-action-wrapper .panel-body > p:last-child{
color: $brand-primary;
font-size: 0.9em;
}
.form_field .form_field_decoration{
vertical-align: baseline;
margin-right: 8px;
}
/* ExternalKey */
.selectobject .input-group-addon{
cursor: pointer;

View File

@@ -33,6 +33,7 @@ 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/phonefield.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

@@ -1,6 +1,6 @@
<?php
// Copyright (C) 2010-2017 Combodo SARL
// Copyright (C) 2010-2018 Combodo SARL
//
// This file is part of iTop.
//
@@ -19,8 +19,8 @@
namespace Combodo\iTop\Form\Field;
use \Str;
use \Combodo\iTop\Form\Field\StringField;
use Str;
use utils;
/**
* Description of EmailField
@@ -38,6 +38,8 @@ class EmailField extends StringField
$sLabel = substr($sLabel, 0, 100).'.....'.substr($sLabel, -20);
}
return "<a class=\"mailto\" href=\"mailto:$this->currentValue\">$sLabel</a>";
$sUrlDecorationClass = utils::GetConfig()->Get('email_decoration_class');
return "<a class=\"mailto\" href=\"mailto:$this->currentValue\"><span class=\"form_field_decoration $sUrlDecorationClass\"></span>$sLabel</a>";
}
}

View File

@@ -0,0 +1,45 @@
<?php
// Copyright (C) 2010-2018 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 utils;
/**
* Description of PhoneField
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
*/
class PhoneField 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);
}
$sUrlDecorationClass = utils::GetConfig()->Get('phone_number_decoration_class');
return "<a class=\"tel\" href=\"tel:$this->currentValue\"><span class=\"form_field_decoration $sUrlDecorationClass\"></span>$sLabel</a>";
}
}

View File

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

View File

@@ -1,6 +1,6 @@
<?php
// Copyright (C) 2010-2017 Combodo SARL
// Copyright (C) 2010-2018 Combodo SARL
//
// This file is part of iTop.
//
@@ -19,16 +19,16 @@
namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer;
use \utils;
use \Dict;
use \UserRights;
use \InlineImage;
use \DBObjectSet;
use \DBObjectSearch;
use \MetaModel;
use \Combodo\iTop\Renderer\FieldRenderer;
use \Combodo\iTop\Renderer\RenderingOutput;
use \Combodo\iTop\Form\Field\LinkedSetField;
use utils;
use Dict;
use UserRights;
use InlineImage;
use DBObjectSet;
use DBObjectSearch;
use MetaModel;
use Combodo\iTop\Renderer\FieldRenderer;
use Combodo\iTop\Renderer\RenderingOutput;
use Combodo\iTop\Form\Field\LinkedSetField;
/**
* Description of BsFileUploadFieldRenderer
@@ -46,6 +46,7 @@ class BsFileUploadFieldRenderer extends FieldRenderer
public function Render()
{
$oOutput = new RenderingOutput();
$oOutput->AddCssClass('form_field');
$oOutput->AddCssClass('form_field_' . $this->oField->GetDisplayMode());
$sObjectClass = get_class($this->oField->GetObject());

View File

@@ -1,6 +1,6 @@
<?php
// Copyright (C) 2010-2017 Combodo SARL
// Copyright (C) 2010-2018 Combodo SARL
//
// This file is part of iTop.
//
@@ -19,14 +19,14 @@
namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer;
use \Exception;
use \ApplicationContext;
use \IssueLog;
use \Dict;
use \MetaModel;
use \AttributeFriendlyName;
use \Combodo\iTop\Renderer\FieldRenderer;
use \Combodo\iTop\Renderer\RenderingOutput;
use Exception;
use ApplicationContext;
use IssueLog;
use Dict;
use MetaModel;
use AttributeFriendlyName;
use Combodo\iTop\Renderer\FieldRenderer;
use Combodo\iTop\Renderer\RenderingOutput;
/**
* Description of BsLinkedSetFieldRenderer
@@ -43,6 +43,7 @@ class BsLinkedSetFieldRenderer extends FieldRenderer
public function Render()
{
$oOutput = new RenderingOutput();
$oOutput->AddCssClass('form_field');
$oOutput->AddCssClass('form_field_' . $this->oField->GetDisplayMode());
$sFieldMandatoryClass = ($this->oField->GetMandatory()) ? 'form_mandatory' : '';

View File

@@ -1,6 +1,6 @@
<?php
// Copyright (C) 2010-2017 Combodo SARL
// Copyright (C) 2010-2018 Combodo SARL
//
// This file is part of iTop.
//
@@ -45,6 +45,7 @@ class BsSelectObjectFieldRenderer extends FieldRenderer
public function Render()
{
$oOutput = new RenderingOutput();
$oOutput->AddCssClass('form_field');
$oOutput->AddCssClass('form_field_' . $this->oField->GetDisplayMode());
$sFieldValueClass = $this->oField->GetSearch()->GetClass();

View File

@@ -1,6 +1,6 @@
<?php
// Copyright (C) 2010-2017 Combodo SARL
// Copyright (C) 2010-2018 Combodo SARL
//
// This file is part of iTop.
//
@@ -19,15 +19,15 @@
namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer;
use \utils;
use \Dict;
use \UserRights;
use \AttributeDateTime;
use \AttributeText;
use \InlineImage;
use \Combodo\iTop\Renderer\FieldRenderer;
use \Combodo\iTop\Renderer\RenderingOutput;
use \Combodo\iTop\Form\Field\TextAreaField;
use utils;
use Dict;
use UserRights;
use AttributeDateTime;
use AttributeText;
use InlineImage;
use Combodo\iTop\Renderer\FieldRenderer;
use Combodo\iTop\Renderer\RenderingOutput;
use Combodo\iTop\Form\Field\TextAreaField;
/**
* Description of BsSimpleFieldRenderer
@@ -45,6 +45,7 @@ class BsSimpleFieldRenderer extends FieldRenderer
public function Render()
{
$oOutput = new RenderingOutput();
$oOutput->AddCssClass('form_field');
$oOutput->AddCssClass('form_field_' . $this->oField->GetDisplayMode());
$sFieldClass = get_class($this->oField);
@@ -61,6 +62,7 @@ class BsSimpleFieldRenderer extends FieldRenderer
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\EmailField':
case 'Combodo\\iTop\\Form\\Field\\PhoneField':
case 'Combodo\\iTop\\Form\\Field\\SelectField':
case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
// Opening container
@@ -101,6 +103,7 @@ EOF
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\EmailField':
case 'Combodo\\iTop\\Form\\Field\\PhoneField':
$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;
@@ -220,6 +223,7 @@ EOF
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\EmailField':
case 'Combodo\\iTop\\Form\\Field\\PhoneField':
case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
case 'Combodo\\iTop\\Form\\Field\\CaseLogField':
case 'Combodo\\iTop\\Form\\Field\\SelectField':
@@ -291,6 +295,7 @@ EOF
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\EmailField':
case 'Combodo\\iTop\\Form\\Field\\PhoneField':
case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
case 'Combodo\\iTop\\Form\\Field\\DurationField':
// Opening container
@@ -308,7 +313,7 @@ EOF
$oOutput->AddHtml('</div>');
// Value
$bEncodeHtmlEntities = ( in_array($sFieldClass, array('Combodo\\iTop\\Form\\Field\\UrlField', 'Combodo\\iTop\\Form\\Field\\EmailField')) ) ? false : true;
$bEncodeHtmlEntities = ( in_array($sFieldClass, array('Combodo\\iTop\\Form\\Field\\UrlField', 'Combodo\\iTop\\Form\\Field\\EmailField', 'Combodo\\iTop\\Form\\Field\\PhoneField')) ) ? 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>');
@@ -475,6 +480,7 @@ EOF
case 'Combodo\\iTop\\Form\\Field\\StringField':
case 'Combodo\\iTop\\Form\\Field\\UrlField':
case 'Combodo\\iTop\\Form\\Field\\EmailField':
case 'Combodo\\iTop\\Form\\Field\\PhoneField':
case 'Combodo\\iTop\\Form\\Field\\SelectField':
case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
case 'Combodo\\iTop\\Form\\Field\\HiddenField':

View File

@@ -1,5 +1,5 @@
<?php
// Copyright (C) 2016-2017 Combodo SARL
// Copyright (C) 2016-2018 Combodo SARL
//
// This file is part of iTop.
//
@@ -18,7 +18,7 @@
namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer;
use \Dict;
use Dict;
use Combodo\iTop\Renderer\Bootstrap\BsFormRenderer;
use Combodo\iTop\Renderer\FieldRenderer;
use Combodo\iTop\Renderer\RenderingOutput;