Browse Source

#782: preview (as a tooltip) for image attachments.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2877 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 11 years ago
parent
commit
543cdd5e69

+ 16 - 0
core/ormdocument.class.inc.php

@@ -117,5 +117,21 @@ class ormDocument
 	{
 		return "<a href=\"".utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=download_document&class=$sClass&id=$Id&field=$sAttCode\">".$this->GetFileName()."</a>\n";
 	}
+	
+	
+	public function IsPreviewAvailable()
+	{
+		$bRet = false;
+		switch($this->GetMimeType())
+		{
+			case 'image/png':
+			case 'image/jpg':
+			case 'image/jpeg':
+			case 'image/gif':
+			$bRet = true;
+			break;
+		}
+		return $bRet;
+	}
 }
 ?>

+ 2 - 0
datamodels/2.x/itop-attachments/ajax.attachment.php

@@ -48,6 +48,7 @@ try
 		$aResult = array(
 			'error' => '',
 			'att_id' => 0,
+			'preview' => 'false',
 			'msg' => ''
 		);
 		$sObjClass = stripslashes(utils::ReadParam('obj_class', '', false, 'class'));
@@ -76,6 +77,7 @@ try
 				$aResult['msg'] = $oDoc->GetFileName();
 				$aResult['icon'] = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($oDoc->GetFileName());
 				$aResult['att_id'] = $iAttId;
+				$aResult['preview'] = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
 			}
 			catch (FileUploadException $e)
 			{

+ 1 - 0
datamodels/2.x/itop-attachments/en .dict.itop-attachments.php

@@ -37,5 +37,6 @@ Dict::Add('EN US', 'English', 'English', array(
 	'Attachment:Max_Mo' => '(Maximum file size: %1$s Mo)',
 	'Attachment:Max_Ko' => '(Maximum file size: %1$s Ko)',
 	'Attachments:NoAttachment' => 'No attachment. ',
+	'Attachments:PreviewNotAvailable' => 'Preview not available for this type of attachment.',
 ));
 ?>

+ 2 - 1
datamodels/2.x/itop-attachments/fr.dict.itop-attachments.php

@@ -35,6 +35,7 @@ Dict::Add('FR FR', 'French', 'Français', array(
 	'Attachment:Max_Go' => '(Taille de fichier max.: %1$s Gb)',
 	'Attachment:Max_Mo' => '(Taille de fichier max.: %1$s Mb)',
 	'Attachment:Max_Ko' => '(Taille de fichier max.: %1$s Kb)',
-	'Attachments:NoAttachment' => 'Aucune pièce jointe.',	
+	'Attachments:NoAttachment' => 'Aucune pièce jointe.',
+	'Attachments:PreviewNotAvailable' => 'Pas d\'aperçu pour ce type de pièce jointe.',
 ));
 ?>

+ 9 - 5
datamodels/2.x/itop-attachments/main.attachments.php

@@ -283,7 +283,7 @@ EOF
 						else
 						{
 							var sDownloadLink = GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?operation=download_document&class=Attachment&id='+data.att_id+'&field=contents';
-							$('#attachments').append('<div class="attachment" id="display_attachment_'+data.att_id+'"><a href="'+sDownloadLink+'"><img src="'+data.icon+'"><br/>'+data.msg+'<input id="attachment_'+data.att_id+'" type="hidden" name="attachments[]" value="'+data.att_id+'"/></a><br/><input type="button" class="btn_hidden" value="{$sDeleteBtn}" onClick="RemoveNewAttachment('+data.att_id+');"/></div>');
+							$('#attachments').append('<div class="attachment" id="display_attachment_'+data.att_id+'"><a data-preview="'+data.preview+'" href="'+sDownloadLink+'"><img src="'+data.icon+'"><br/>'+data.msg+'<input id="attachment_'+data.att_id+'" type="hidden" name="attachments[]" value="'+data.att_id+'"/></a><br/><input type="button" class="btn_hidden" value="{$sDeleteBtn}" onClick="RemoveNewAttachment('+data.att_id+');"/></div>');
 							if($sIsDeleteEnabled)
 							{
 								$('#display_attachment_'+data.att_id).hover( function() { $(this).children(':button').toggleClass('btn_hidden'); } );
@@ -313,8 +313,9 @@ EOF
 				$oDoc = $oAttachment->Get('contents');
 				$sFileName = $oDoc->GetFileName();
 				$sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName);
+				$sPreview = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
 				$sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents';
-				$oPage->add('<div class="attachment" id="attachment_'.$iAttId.'"><a href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/>&nbsp;<input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="$(\'#attachment_'.$iAttId.'\').remove();"/>&nbsp;</div>');
+				$oPage->add('<div class="attachment" id="attachment_'.$iAttId.'"><a data-preview="'.$sPreview.'" href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/>&nbsp;<input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="$(\'#attachment_'.$iAttId.'\').remove();"/>&nbsp;</div>');
 			}
 			
 			// Suggested attachments are listed here but treated as temporary
@@ -341,7 +342,8 @@ EOF
 						$sFileName = $oDoc->GetFileName();
 						$sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName);
 						$sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents';
-						$oPage->add('<div class="attachment" id="display_attachment_'.$iAttId.'"><a href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/>&nbsp;<input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="RemoveNewAttachment('.$iAttId.');"/>&nbsp;</div>');
+						$sPreview = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
+						$oPage->add('<div class="attachment" id="display_attachment_'.$iAttId.'"><a data-preview="'.$sPreview.'" href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/>&nbsp;<input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="RemoveNewAttachment('.$iAttId.');"/>&nbsp;</div>');
 						$oPage->add_ready_script("$('#attachment_plugin').trigger('add_attachment', [$iAttId, '".addslashes($sFileName)."']);");
 					}
 				}
@@ -374,14 +376,16 @@ EOF
 					$oDoc = $oAttachment->Get('contents');
 					$sFileName = $oDoc->GetFileName();
 					$sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName);
+					$sPreview = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
 					$sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents';
-					$oPage->add('<div class="attachment" id="attachment_'.$iAttId.'"><a href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'</a><input type="hidden" name="attachments[]" value="'.$iAttId.'"/><br/>&nbsp;&nbsp;</div>');
+					$oPage->add('<div class="attachment" id="attachment_'.$iAttId.'"><a data-preview="'.$sPreview.'" href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'</a><input type="hidden" name="attachments[]" value="'.$iAttId.'"/><br/>&nbsp;&nbsp;</div>');
 				}
 			}
 		}
+		$sPreviewNotAvailable = Dict::S('Attachments:PreviewNotAvailable');
+		$oPage->add_ready_script("$(document).tooltip({ items: '.attachment a',  position: { my: 'left top', at: 'right top', using: function( position, feedback ) { $( this ).css( position ); }}, content: function() { if ($(this).attr('data-preview') == 'true') { return('<img style=\"max-width:290px\" src=\"'+$(this).attr('href')+'\"></img>');} else { return '$sPreviewNotAvailable'; }}});");
 	}
 
-
 	protected static function UpdateAttachments($oObject, $oChange = null)
 	{
 		self::$m_bIsModified = false;