Selaa lähdekoodia

Customer portal : Displays a message when viewing an object with no attachments in read only

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4173 a333f486-631f-4898-b8df-5754b55c2be0
glajarige 9 vuotta sitten
vanhempi
commit
c57b05ea06

+ 6 - 0
datamodels/2.x/itop-portal-base/portal/src/forms/objectformmanager.class.inc.php

@@ -569,6 +569,12 @@ class ObjectFormManager extends FormManager
 					->SetTransactionId($oForm->GetTransactionId())
 					->SetAllowDelete($this->oApp['combodo.portal.instance.conf']['properties']['attachments']['allow_delete'])
 					->SetObject($this->oObject);
+
+				if ($this->sMode === static::ENUM_MODE_VIEW)
+				{
+					$oField->SetReadOnly(true);
+				}
+
 				$oForm->AddField($oField);
 			}
 		}

+ 24 - 11
sources/renderer/bootstrap/fieldrenderer/bsfileuploadfieldrenderer.class.inc.php

@@ -68,8 +68,12 @@ class BsFileUploadFieldRenderer extends FieldRenderer
 		$oOutput->AddHtml('<div class="attachments_container row">');
 		$this->PrepareExistingFiles($oOutput);
 		$oOutput->Addhtml('</div>');
+		// Removing upload input if in read only
 		// TODO : Add max upload size when itop attachment has been refactored
-		$oOutput->AddHtml('<div class="upload_container row">' . Dict::S('Attachments:AddAttachment') . '<input type="file" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" /><span class="loader glyphicon glyphicon-refresh"></span></div>');
+		if (!$this->oField->GetReadOnly())
+		{
+			$oOutput->AddHtml('<div class="upload_container row">' . Dict::S('Attachments:AddAttachment') . '<input type="file" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" /><span class="loader glyphicon glyphicon-refresh"></span></div>');
+		}
 		// Ending files container
 		$oOutput->AddHtml('</div>');
 		// Ending field container
@@ -226,16 +230,24 @@ EOF
 
 		$oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE item_class = :class AND item_id = :item_id");
 		$oSet = new DBObjectSet($oSearch, array(), array('class' => $sObjectClass, 'item_id' => $this->oField->GetObject()->GetKey()));
-		while ($oAttachment = $oSet->Fetch())
+
+		// If in read only and no attachments, we display a short message
+		if ($this->oField->GetReadOnly() && ($oSet->Count() === 0))
+		{
+			$oOutput->AddHtml(Dict::S('Attachments:NoAttachment'));
+		}
+		else
 		{
-			$iAttId = $oAttachment->GetKey();
-			$oDoc = $oAttachment->Get('contents');
-			$sFileName = htmlentities($oDoc->GetFileName(), ENT_QUOTES, 'UTF-8');
-			$sIcon = utils::GetAbsoluteUrlAppRoot() . 'env-' . utils::GetCurrentEnvironment() . '/itop-attachments/icons/image.png';
-			$sPreview = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
-			$sDownloadLink = str_replace('-sAttachmentId-', $iAttId, $this->oField->GetDownloadEndpoint());
-
-			$oOutput->Addhtml(
+			while ($oAttachment = $oSet->Fetch())
+			{
+				$iAttId = $oAttachment->GetKey();
+				$oDoc = $oAttachment->Get('contents');
+				$sFileName = htmlentities($oDoc->GetFileName(), ENT_QUOTES, 'UTF-8');
+				$sIcon = utils::GetAbsoluteUrlAppRoot() . 'env-' . utils::GetCurrentEnvironment() . '/itop-attachments/icons/image.png';
+				$sPreview = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
+				$sDownloadLink = str_replace('-sAttachmentId-', $iAttId, $this->oField->GetDownloadEndpoint());
+
+				$oOutput->Addhtml(
 <<<EOF
 				<div class="attachment col-xs-6 col-sm-3 col-md-2" id="display_attachment_{$iAttId}">
 					<a data-preview="{$sPreview}" href="{$sDownloadLink}" title="{$sFileName}">
@@ -246,7 +258,8 @@ EOF
 					<input id="btn_remove_{$iAttId}" type="button" class="btn btn-xs btn-danger hidden" value="{$sDeleteBtn}"/>
 				</div>
 EOF
-			);
+				);
+			}
 		}
 	}