diff --git a/css/backoffice/pages/_all.scss b/css/backoffice/pages/_all.scss index 7d44d47e6..6cc563f22 100644 --- a/css/backoffice/pages/_all.scss +++ b/css/backoffice/pages/_all.scss @@ -17,4 +17,5 @@ */ @import "base"; -@import "preferences"; \ No newline at end of file +@import "preferences"; +@import "attachments"; \ No newline at end of file diff --git a/css/backoffice/pages/_attachments.scss b/css/backoffice/pages/_attachments.scss new file mode 100644 index 000000000..06902795e --- /dev/null +++ b/css/backoffice/pages/_attachments.scss @@ -0,0 +1,17 @@ +$ibo-attachment--datatable--icon-preview--max-height: 44px !default; +$ibo-attachment--datatable--icon-preview--max-width: $ibo-attachment--datatable--icon-preview--max-height !default; + +$ibo-attachment--datatable--line-height: $ibo-attachment--datatable--icon-preview--max-height !default; + +$ibo-attachment--datatable--first-column--line-height: 0px !default; + +.ibo-attachment--datatable--icon-preview{ + max-height: $ibo-attachment--datatable--icon-preview--max-height; + max-width: $ibo-attachment--datatable--icon-preview--max-width; +} +.ibo-attachment--datatable tbody tr td { + line-height: $ibo-attachment--datatable--line-height; +} +.ibo-attachment--datatable tbody tr td:nth-child(1){ + line-height: $ibo-attachment--datatable--first-column--line-height; +} \ No newline at end of file diff --git a/datamodels/2.x/itop-attachments/main.itop-attachments.php b/datamodels/2.x/itop-attachments/main.itop-attachments.php index 4162f93dc..423d19c79 100644 --- a/datamodels/2.x/itop-attachments/main.itop-attachments.php +++ b/datamodels/2.x/itop-attachments/main.itop-attachments.php @@ -261,11 +261,7 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt $sTitle = ($iCount > 0) ? Dict::Format('Attachments:TabTitle_Count', $iCount) : Dict::S('Attachments:EmptyTabTitle'); $oPage->SetCurrentTab('Attachments:Tab', $sTitle); } - - $oPage->add('
'); - $oPage->add(''.Dict::S('Attachments:FieldsetTitle').''); - - $oPage->add('
'); + $bIsReadOnlyState = self::IsReadonlyState($oObject, $oObject->GetState(), AttachmentPlugIn::ENUM_GUI_BACKOFFICE); if ($bEditMode && !$bIsReadOnlyState) { @@ -274,10 +270,8 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt else { $oAttachmentsRenderer->RenderViewAttachmentsList(); - } - $oPage->add('
'); - $oPage->add('
'); + } } protected static function UpdateAttachments($oObject, $oChange = null) diff --git a/datamodels/2.x/itop-attachments/renderers.itop-attachments.php b/datamodels/2.x/itop-attachments/renderers.itop-attachments.php index 16c848fbd..a8ceb9ad8 100644 --- a/datamodels/2.x/itop-attachments/renderers.itop-attachments.php +++ b/datamodels/2.x/itop-attachments/renderers.itop-attachments.php @@ -24,6 +24,10 @@ */ +use Combodo\iTop\Application\UI\Base\Component\Button\ButtonUIBlockFactory; +use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableUIBlockFactory; +use Combodo\iTop\Renderer\BlockRenderer; + define('ATTACHMENT_DOWNLOAD_URL', 'pages/ajax.document.php?operation=download_document&class=Attachment&field=contents&id='); define('ATTACHMENTS_RENDERER', 'TableDetailsAttachmentsRenderer'); @@ -180,7 +184,7 @@ abstract class AbstractAttachmentsRenderer $sMaxUploadLabel = AttachmentPlugIn::GetMaxUpload(); $sFileTooBigLabel = Dict::Format('Attachments:Error:FileTooLarge', $sMaxUploadLabel); $sFileTooBigLabelForJS = addslashes($sFileTooBigLabel); - $this->oPage->p(Dict::S('Attachments:AddAttachment').' '.$sMaxUploadLabel); + $this->oPage->p(Dict::S('Attachments:AddAttachment').' '.$sMaxUploadLabel); $this->oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.iframe-transport.js'); $this->oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.fileupload.js'); @@ -189,7 +193,7 @@ abstract class AbstractAttachmentsRenderer <<tbody>tr[id^="display_attachment_"]>td input[name="removed_attachments[]"]'), aAttachmentsDeletedIds = aAttachmentsDeletedHiddenInputs.map(function() { return $(this).val() }).toArray(); $(sContentNode).block(); @@ -313,7 +317,6 @@ abstract class AbstractAttachmentsRenderer }, 200 ); JS ); - $this->oPage->p(''); $this->oPage->p(''); $this->oPage->add_style(<<'; + $oButton = ButtonUIBlockFactory::MakeForAlternativeDestructiveAction(Dict::S('Attachments:DeleteBtn'), + Dict::S('Attachments:DeleteBtn'), + Dict::S('Attachments:DeleteBtn'), + false, + "btn_remove_".$iAttId); + $oButton->AddCSSClass('btn_hidden')->SetOnClickJsCode("RemoveAttachment('.$iAttId.');"); + return BlockRenderer::RenderBlockTemplates($oButton); } protected function GetDeleteAttachmentJs() @@ -387,49 +396,7 @@ class TableDetailsAttachmentsRenderer extends AbstractAttachmentsRenderer $sFileUploader = Dict::S('Attachments:File:Uploader'); $sFileType = Dict::S('Attachments:File:MimeType'); $sDeleteColumn = ''; - if ($bWithDeleteButton) - { - $sDeleteColumn = ''; - } - $this->oPage->add(<< - - $sThumbnail - $sFileName - $sFileSize - $sFileDate - $sFileUploader - $sFileType - $sDeleteColumn - - -HTML - ); - $iMaxWidth = MetaModel::GetModuleSetting('itop-attachments', 'preview_max_width', 290); - $sPreviewNotAvailable = addslashes(Dict::S('Attachments:PreviewNotAvailable')); - $this->oPage->add_ready_script( - <<tbody>tr>td a.trigger-preview', - position: { - my: 'left top', at: 'right top', using: function (position, feedback) { - $(this).css(position); - } - }, - content: function () { - if ($(this).hasClass("preview")) - { - return (''); - } - else - { - return '$sPreviewNotAvailable'; - } - } -}); -JS - ); if ($bWithDeleteButton) { $this->oPage->add_script($this->GetDeleteAttachmentJs()); @@ -437,36 +404,36 @@ JS $bIsEven = false; $aAttachmentsDate = AttachmentsHelper::GetAttachmentsDateAddedFromDb($this->sObjClass, $this->iObjKey); + $aData = array(); while ($oAttachment = $this->oAttachmentsSet->Fetch()) { $bIsEven = ($bIsEven) ? false : true; - $this->AddAttachmentsTableLine($bWithDeleteButton, $bIsEven, $oAttachment, $aAttachmentsDate, $aAttachmentsDeleted); + $aData[] = $this->AddAttachmentsTableLine($bWithDeleteButton, $bIsEven, $oAttachment, $aAttachmentsDate, $aAttachmentsDeleted); } while ($oTempAttachment = $this->oTempAttachmentsSet->Fetch()) { $bIsEven = ($bIsEven) ? false : true; - $this->AddAttachmentsTableLine($bWithDeleteButton, $bIsEven, $oTempAttachment, $aAttachmentsDate, $aAttachmentsDeleted); + $aData[] = $this->AddAttachmentsTableLine($bWithDeleteButton, $bIsEven, $oTempAttachment, $aAttachmentsDate, $aAttachmentsDeleted); } - $this->oPage->add(''.PHP_EOL); - $this->oPage->add(''.PHP_EOL); - - $this->oPage->add_ready_script(<<<'JS' -var $attachmentsTable = $("table.attachmentsList"); -$attachmentsTable.tablesorter( - { - textExtraction : - function(node, table, cellIndex) { - if ($(node).is("[data-order]")) { - return $(node).attr("data-order"); - } - - return $(node).text(); - } - } -); -JS + $aAttribs = array( + 'icon' => array('label' => $sThumbnail, 'description' => $sThumbnail), + 'filename' => array('label' => $sFileName, 'description' => $sFileName), + 'formatted-size' => array('label' => $sFileSize, 'description' => $sFileSize), + 'upload-date' => array('label' => $sFileDate, 'description' => $sFileDate), + 'uploader' => array('label' => $sFileUploader, 'description' => $sFileUploader), + 'type' => array('label' => $sFileType, 'description' => $sFileType), ); + + if($bWithDeleteButton) + { + $aAttribs['delete'] = array('label' => '', 'description' => ''); + } + + $oAttachmentTableBlock = DataTableUIBlockFactory::MakeForStaticData('',$aAttribs, $aData); + $oAttachmentTableBlock->AddCSSClass('ibo-attachment--datatable'); + $this->oPage->AddUiBlock($oAttachmentTableBlock); + } /** @@ -529,33 +496,42 @@ JS $sAttachmentThumbUrl = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName); $sIconClass = ''; + $iMaxWidth = MetaModel::GetModuleSetting('itop-attachments', 'preview_max_width', 290); + $sPreviewNotAvailable = addslashes(Dict::S('Attachments:PreviewNotAvailable')); + $sPreviewMarkup = $sPreviewNotAvailable; if ($oDoc->IsPreviewAvailable()) { $sIconClass = ' preview'; if ($oDoc->GetSize() <= self::MAX_SIZE_FOR_PREVIEW) { $sAttachmentThumbUrl = $sDocDownloadUrl; + $sPreviewMarkup = utils::HtmlEntities(''); } } - $sDeleteColumn = ''; + + $aAttachmentLine = array( + '@id' => $sTrId, + '@meta' => 'data-file-type="'.utils::HtmlEntities($sFileType).'" data-file-size-raw="'.utils::HtmlEntities($iFileSize).'" data-file-size-formatted="'.utils::HtmlEntities($sFileFormattedSize).'" data-file-uploader="'.utils::HtmlEntities($sAttachmentUploader).'"', + 'icon' => '', + 'filename' => ''.$sFileName.''.$sAttachmentMeta, + 'formatted-size' => $sFileFormattedSize, + 'upload-date' => $sAttachmentDateFormatted, + 'uploader' => $sAttachmentUploader, + 'type' => $sFileType + ); + if ($bWithDeleteButton) { $sDeleteButton = $this->GetDeleteAttachmentButton($iAttachmentId); - $sDeleteColumn = "$sDeleteButton"; + $aAttachmentLine['delete'] = $sDeleteButton; } + $this->oPage->add_ready_script( + <<oPage->add(<< - - $sFileName$sAttachmentMeta - $sFileFormattedSize - $sAttachmentDateFormatted - $sAttachmentUploader - $sFileType - $sDeleteColumn - -HTML ); + return $aAttachmentLine; } } diff --git a/templates/base/components/datatable/static/layout.html.twig b/templates/base/components/datatable/static/layout.html.twig index e939629cb..74b942bae 100644 --- a/templates/base/components/datatable/static/layout.html.twig +++ b/templates/base/components/datatable/static/layout.html.twig @@ -12,11 +12,11 @@ {% for data in oUIBlock.GetData() %} - {% if data['@class'] is not empty %} - - {% else %} - - {% endif %} + + {% for name,column in columns %}