';
}
});
}
// Remove button handler
$('#display_attachment_'+data.result.att_id+' :button').click(function(oEvent){
oEvent.preventDefault();
RemoveAttachment(data.result.att_id);
});
}
},
send: function(e, data){
// Don't send attachment if size is greater than PHP post_max_size, otherwise it will break the request and all its parameters (\$_REQUEST, \$_POST, ...)
// Note: We loop on the files as the data structures is an array but in this case, we only upload 1 file at a time.
var iTotalSizeInBytes = 0;
for(var i = 0; i < data.files.length; i++)
{
iTotalSizeInBytes += data.files[i].size;
}
if(iTotalSizeInBytes > $iMaxUploadInBytes)
{
alert('$sFileTooBigLabelForJS');
return false;
}
},
start: function() {
// Scrolling to dropzone so the user can see that attachments are uploaded
$(this)[0].scrollIntoView();
// Showing loader
$(this).closest('.upload_container').find('.loader').css('visibility', 'visible');
},
stop: function() {
// Hiding the loader
$(this).closest('.upload_container').find('.loader').css('visibility', 'hidden');
// Adding this field to the touched fields of the field set so the cancel event is called if necessary
$(this).closest(".field_set").trigger("field_change", {
id: '{$this->oField->GetGlobalId()}',
name: '{$this->oField->GetId()}'
});
}
});
// Preview tooltip
$('table#$sAttachmentTableId>tbody>tr>td a.trigger-preview').each(function(iIndex, oElem){
$(oElem).parent().tooltip({
container: 'body',
html: true,
title: function(){ return '
') );
}
// Handles highlighting of the drop zone
// Note : This is inspired by itop-attachments/main.attachments.php
$(document).on('dragover', function(oEvent){
var bFiles = false;
if (oEvent.dataTransfer && oEvent.dataTransfer.types)
{
for (var i = 0; i < oEvent.dataTransfer.types.length; i++)
{
if (oEvent.dataTransfer.types[i] == "application/x-moz-nativeimage")
{
bFiles = false; // mozilla contains "Files" in the types list when dragging images inside the page, but it also contains "application/x-moz-nativeimage" before
break;
}
if (oEvent.dataTransfer.types[i] == "Files")
{
bFiles = true;
break;
}
}
}
if (!bFiles) return; // Not dragging files
var oDropZone = $('#drag_overlay');
var oTimeout = window.dropZoneTimeout;
// This is to detect when there is no drag over because there is no "drag out" event
if (!oTimeout) {
oDropZone.removeClass('drag_out').addClass('drag_in');
} else {
clearTimeout(oTimeout);
}
window.dropZoneTimeout = setTimeout(function () {
window.dropZoneTimeout = null;
oDropZone.removeClass('drag_in').addClass('drag_out');
}, 200);
});
JS
);
return $oOutput;
}
/**
*
* @param \Combodo\iTop\Renderer\RenderingOutput $oOutput
* @param boolean $bIsDeleteAllowed
*
* @throws \Exception
* @throws \CoreException
* @throws \OQLException
*/
protected function PrepareExistingFiles(RenderingOutput $oOutput, $bIsDeleteAllowed)
{
$sAttachmentTableId = $this->GetAttachmentsTableId();
$sObjectClass = get_class($this->oField->GetObject());
$sDeleteBtn = Dict::S('Portal:Button:Delete');
$oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE item_class = :class AND item_id = :item_id");
// Note : AllowAllData set to true here instead of checking scope's flag because we are displaying a value that has been set and validated
$oSearch->AllowAllData();
$oSet = new DBObjectSet($oSearch, array(), array('class' => $sObjectClass, 'item_id' => $this->oField->GetObject()->GetKey()));
// 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
{
$sTitleThumbnail = Dict::S('Attachments:File:Thumbnail');
$sTitleFileName = Dict::S('Attachments:File:Name');
$sTitleFileSize = Dict::S('Attachments:File:Size');
$sTitleFileDate = Dict::S('Attachments:File:Date');
$sTitleFileCreator = Dict::S('Attachments:File:Creator');
$sTitleFileType = Dict::S('Attachments:File:MimeType');
$oOutput->Addhtml(<<