Browse Source

Portal: AttributeImage can now be displayed in forms

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4722 a333f486-631f-4898-b8df-5754b55c2be0
glajarige 8 years ago
parent
commit
639e1295e5

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

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

+ 1 - 0
sources/autoload.php

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

+ 53 - 0
sources/form/field/imagefield.class.inc.php

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

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

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

+ 12 - 2
sources/renderer/bootstrap/fieldrenderer/bssimplefieldrenderer.class.inc.php

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