mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 18:18:46 +02:00
N°330 Attachments as table : fix table sorting on size and date
* portal : use data-order attribute for the DataTable plugin (https://datatables.net/manual/data/orthogonal-data) * console : add textExtraction override for the attachments table (https://mottie.github.io/tablesorter/docs/example-option-text-extraction.html)
This commit is contained in:
@@ -414,6 +414,23 @@ JS
|
||||
|
||||
$this->oPage->add('</tbody>'.PHP_EOL);
|
||||
$this->oPage->add('</table>'.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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -452,10 +469,11 @@ JS
|
||||
$sFileName = utils::HtmlEntities($oDoc->GetFileName());
|
||||
$sTrId = $this->GetAttachmentContainerId($iAttachmentId);
|
||||
$sAttachmentMeta = $this->GetAttachmentHiddenInput($iAttachmentId, $bIsDeletedAttachment);
|
||||
$sFileSize = $oDoc->GetSize();
|
||||
$iFileSize = $oDoc->GetSize();
|
||||
$sFileFormattedSize = $oDoc->GetFormattedSize();
|
||||
$bIsTempAttachment = ($oAttachment->Get('item_id') === 0);
|
||||
$sAttachmentDate = '';
|
||||
$sAttachmentDateFormatted = '';
|
||||
$iAttachmentDateRaw = '';
|
||||
if (!$bIsTempAttachment)
|
||||
{
|
||||
$sAttachmentDate = $oAttachment->Get('creation_date');
|
||||
@@ -463,6 +481,9 @@ JS
|
||||
{
|
||||
$sAttachmentDate = $aAttachmentsDate[$iAttachmentId];
|
||||
}
|
||||
$oAttachmentDate = DateTime::createFromFormat(AttributeDateTime::GetInternalFormat(), $sAttachmentDate);
|
||||
$sAttachmentDateFormatted = AttributeDateTime::GetFormat()->Format($oAttachmentDate);
|
||||
$iAttachmentDateRaw = AttributeDateTime::GetAsUnixSeconds($sAttachmentDate);
|
||||
}
|
||||
|
||||
$sAttachmentUploader = $oAttachment->Get('contact_id_friendlyname');
|
||||
@@ -489,11 +510,11 @@ JS
|
||||
}
|
||||
|
||||
$this->oPage->add(<<<HTML
|
||||
<tr id="$sTrId" $sLineClass $sLineStyle data-file-type="$sFileType" data-file-size-raw="$sFileSize" data-file-size-formatted="$sFileFormattedSize" data-file-uploader="$sAttachmentUploaderForHtml">
|
||||
<tr id="$sTrId" $sLineClass $sLineStyle data-file-type="$sFileType" data-file-size-raw="$iFileSize" data-file-size-formatted="$sFileFormattedSize" data-file-uploader="$sAttachmentUploaderForHtml">
|
||||
<td role="icon"><a href="$sDocDownloadUrl" target="_blank" class="trigger-preview $sIconClass"><img $sIconClass style="max-height: 48px;" src="$sAttachmentThumbUrl"></a></td>
|
||||
<td role="filename"><a href="$sDocDownloadUrl" target="_blank" class="$sIconClass">$sFileName</a>$sAttachmentMeta</td>
|
||||
<td role="formatted-size">$sFileFormattedSize</td>
|
||||
<td role="upload-date">$sAttachmentDate</td>
|
||||
<td role="formatted-size" data-order="$iFileSize">$sFileFormattedSize</td>
|
||||
<td role="upload-date" data-order="$iAttachmentDateRaw">$sAttachmentDateFormatted</td>
|
||||
<td role="uploader">$sAttachmentUploader</td>
|
||||
<td role="type">$sFileType</td>
|
||||
$sDeleteColumn
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer;
|
||||
|
||||
use AbstractAttachmentsRenderer;
|
||||
use AttachmentPlugIn;
|
||||
use AttributeDateTime;
|
||||
use Combodo\iTop\Form\Field\Field;
|
||||
use Combodo\iTop\Renderer\RenderingOutput;
|
||||
use DBObjectSearch;
|
||||
@@ -185,7 +186,9 @@ JS
|
||||
'{{sFileName}}',
|
||||
'{{sAttachmentMeta}}',
|
||||
'{{sFileSize}}',
|
||||
'{{iFileSizeRaw}}',
|
||||
'{{sAttachmentDate}}',
|
||||
'{{iAttachmentDateRaw}}',
|
||||
$bIsDeleteAllowed
|
||||
));
|
||||
$sAttachmentTableId = $this->GetAttachmentsTableId();
|
||||
@@ -423,13 +426,16 @@ HTML
|
||||
}
|
||||
}
|
||||
|
||||
$iFileSizeRaw = $oDoc->GetSize();
|
||||
$sFileSize = $oDoc->GetFormattedSize();
|
||||
|
||||
$bIsTempAttachment = ($oAttachment->Get('item_id') === 0);
|
||||
$sAttachmentDate = '';
|
||||
$iAttachmentDateRaw = '';
|
||||
if (!$bIsTempAttachment)
|
||||
{
|
||||
$sAttachmentDate = $oAttachment->Get('creation_date');
|
||||
$iAttachmentDateRaw = AttributeDateTime::GetAsUnixSeconds($sAttachmentDate);
|
||||
}
|
||||
|
||||
$oOutput->Addhtml(self::GetAttachmentTableRow(
|
||||
@@ -441,7 +447,9 @@ HTML
|
||||
$sFileName,
|
||||
$sAttachmentMeta,
|
||||
$sFileSize,
|
||||
$iFileSizeRaw,
|
||||
$sAttachmentDate,
|
||||
$iAttachmentDateRaw,
|
||||
$bIsDeleteAllowed
|
||||
));
|
||||
}
|
||||
@@ -490,7 +498,9 @@ HTML;
|
||||
* @param string $sFileName
|
||||
* @param string $sAttachmentMeta
|
||||
* @param string $sFileSize
|
||||
* @param integer $iFileSizeRaw
|
||||
* @param string $sAttachmentDate
|
||||
* @param integer $iAttachmentDateRaw
|
||||
* @param boolean $bIsDeleteAllowed
|
||||
*
|
||||
* @return string
|
||||
@@ -498,7 +508,7 @@ HTML;
|
||||
*/
|
||||
protected static function GetAttachmentTableRow(
|
||||
$iAttId, $sLineStyle, $sDocDownloadUrl, $sIconClass, $sAttachmentThumbUrl, $sFileName, $sAttachmentMeta, $sFileSize,
|
||||
$sAttachmentDate, $bIsDeleteAllowed
|
||||
$iFileSizeRaw, $sAttachmentDate, $iAttachmentDateRaw, $bIsDeleteAllowed
|
||||
) {
|
||||
$sDeleteCell = '';
|
||||
if ($bIsDeleteAllowed)
|
||||
@@ -511,8 +521,8 @@ HTML;
|
||||
<tr id="display_attachment_{$iAttId}" class="attachment" $sLineStyle>
|
||||
<td role="icon"><a href="$sDocDownloadUrl" target="_blank" class="$sIconClass"><img $sIconClass src="$sAttachmentThumbUrl"></a></td>
|
||||
<td role="filename"><a href="$sDocDownloadUrl" target="_blank">$sFileName</a>$sAttachmentMeta</td>
|
||||
<td role="formatted-size">$sFileSize</td>
|
||||
<td role="upload-date">$sAttachmentDate</td>
|
||||
<td role="formatted-size" data-order="$iFileSizeRaw">$sFileSize</td>
|
||||
<td role="upload-date" data-order="$iAttachmentDateRaw">$sAttachmentDate</td>
|
||||
$sDeleteCell
|
||||
</tr>
|
||||
HTML;
|
||||
|
||||
Reference in New Issue
Block a user