Portal: AttributeImage can now be displayed in forms

SVN:trunk[4722]
This commit is contained in:
Guillaume Lajarige
2017-05-09 12:27:25 +00:00
parent d2d895fdf5
commit 1de6ac1765
5 changed files with 73 additions and 3 deletions

View File

@@ -5465,6 +5465,11 @@ class AttributeImage extends AttributeBlob
}
return '<div class="view-image" style="width: '.$iMaxWidthPx.'px; height: '.$iMaxHeightPx.'px;"><span class="helper-middle"></span>'.$sRet.'</div>';
}
static public function GetFormFieldClass()
{
return '\\Combodo\\iTop\\Form\\Field\\ImageField';
}
}
/**
* A stop watch is an ormStopWatch object, it is stored as several columns in the database

View File

@@ -25,6 +25,7 @@ require_once APPROOT . 'sources/form/formmanager.class.inc.php';
require_once APPROOT . 'sources/form/field/field.class.inc.php';
require_once APPROOT . 'sources/form/field/fileuploadfield.class.inc.php';
require_once APPROOT . 'sources/form/field/blobfield.class.inc.php';
require_once APPROOT . 'sources/form/field/imagefield.class.inc.php';
require_once APPROOT . 'sources/form/field/subformfield.class.inc.php';
require_once APPROOT . 'sources/form/field/textfield.class.inc.php';
require_once APPROOT . 'sources/form/field/hiddenfield.class.inc.php';

View File

@@ -0,0 +1,53 @@
<?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 \utils;
use \Dict;
use \ormDocument;
use \Combodo\iTop\Form\Field\BlobField;
/**
* Description of ImageField
*
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
*/
class ImageField extends BlobField
{
public function GetDisplayValue()
{
if ($this->currentValue->IsEmpty())
{
$sValue = Dict::S('Portal:File:None');
}
else
{
$sFilename = $this->currentValue->GetFileName();
$iSize = utils::BytesToFriendlyFormat(strlen($this->currentValue->GetData()));
$sOpenLink = $this->GetDisplayUrl();
$sDownloadLink = $this->GetDownloadUrl();
$sValue = Dict::Format('Portal:File:DisplayInfo+', $sFilename, $iSize, $sOpenLink, $sDownloadLink);
}
return $sValue;
}
}

View File

@@ -57,7 +57,8 @@ class BsFormRenderer extends FormRenderer
$this->AddSupportedField('DateTimeField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('DurationField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('FileUploadField', 'BsFileUploadFieldRenderer');
$this->AddSupportedField('BlobField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('BlobField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('ImageField', 'BsSimpleFieldRenderer');
}
}

View File

@@ -280,7 +280,8 @@ EOF
$oOutput->AddHtml('</div>');
break;
case 'Combodo\\iTop\\Form\\Field\\BlobField':
case 'Combodo\\iTop\\Form\\Field\\BlobField':
case 'Combodo\\iTop\\Form\\Field\\ImageField':
$oOutput->AddHtml('<div class="form-group">');
// Showing label / value only if read-only but not hidden
if (!$this->oField->GetHidden())
@@ -289,7 +290,16 @@ EOF
{
$oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
}
$oOutput->AddHtml('<div class="form-control-static">')->AddHtml($this->oField->GetDisplayValue(), false)->AddHtml('</div>');
$oOutput->AddHtml('<div class="form-control-static">');
if($sFieldClass === 'Combodo\\iTop\\Form\\Field\\ImageField')
{
$oOutput->AddHtml('<img src="' . $this->oField->GetDisplayUrl() . '" />', false);
}
else
{
$oOutput->AddHtml($this->oField->GetDisplayValue(), false);
}
$oOutput->AddHtml('</div>');
}
$oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('" class="form-control" />');
$oOutput->AddHtml('</div>');