diff --git a/core/ormdocument.class.inc.php b/core/ormdocument.class.inc.php index 102a7f524..94625b175 100644 --- a/core/ormdocument.class.inc.php +++ b/core/ormdocument.class.inc.php @@ -117,5 +117,21 @@ class ormDocument { return "".$this->GetFileName()."\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; + } } ?> diff --git a/datamodels/2.x/itop-attachments/ajax.attachment.php b/datamodels/2.x/itop-attachments/ajax.attachment.php index fcd76ea98..cbbaf2495 100755 --- a/datamodels/2.x/itop-attachments/ajax.attachment.php +++ b/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) { diff --git a/datamodels/2.x/itop-attachments/en .dict.itop-attachments.php b/datamodels/2.x/itop-attachments/en .dict.itop-attachments.php index daf793080..ab3ebbd96 100755 --- a/datamodels/2.x/itop-attachments/en .dict.itop-attachments.php +++ b/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.', )); ?> diff --git a/datamodels/2.x/itop-attachments/fr.dict.itop-attachments.php b/datamodels/2.x/itop-attachments/fr.dict.itop-attachments.php index ba4c91d57..71c50cdb2 100755 --- a/datamodels/2.x/itop-attachments/fr.dict.itop-attachments.php +++ b/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.', )); ?> \ No newline at end of file diff --git a/datamodels/2.x/itop-attachments/main.attachments.php b/datamodels/2.x/itop-attachments/main.attachments.php index 4c833568f..964865270 100755 --- a/datamodels/2.x/itop-attachments/main.attachments.php +++ b/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('

'+data.msg+'

'); + $('#attachments').append('

'+data.msg+'

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

'.$sFileName.'

  
'); + $oPage->add('

'.$sFileName.'

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

'.$sFileName.'

  
'); + $sPreview = $oDoc->IsPreviewAvailable() ? 'true' : 'false'; + $oPage->add('

'.$sFileName.'

  
'); $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('

'.$sFileName.'

  
'); + $oPage->add('

'.$sFileName.'

  
'); } } } + $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('');} else { return '$sPreviewNotAvailable'; }}});"); } - protected static function UpdateAttachments($oObject, $oChange = null) { self::$m_bIsModified = false;