N°3670 Add new file upload button

This commit is contained in:
Stephen Abello
2021-02-10 17:17:00 +01:00
parent d08adc43c1
commit 3be360dfb9
4 changed files with 45 additions and 8 deletions

View File

@@ -5,6 +5,12 @@ $ibo-attachment--datatable--line-height: $ibo-attachment--datatable--icon-previe
$ibo-attachment--datatable--first-column--line-height: 0px !default;
#ibo-attachment--upload-file{
.ibo-input-file-select--container{
display: inline-block;
}
}
.ibo-attachment--datatable--icon-preview{
max-height: $ibo-attachment--datatable--icon-preview--max-height;
max-width: $ibo-attachment--datatable--icon-preview--max-width;

View File

@@ -26,6 +26,7 @@
use Combodo\iTop\Application\UI\Base\Component\Button\ButtonUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\FileSelect\FileSelectUIBlockFactory;
use Combodo\iTop\Renderer\BlockRenderer;
define('ATTACHMENT_DOWNLOAD_URL', 'pages/ajax.document.php?operation=download_document&class=Attachment&field=contents&id=');
@@ -178,13 +179,17 @@ abstract class AbstractAttachmentsRenderer
{
$sClass = $this->sObjClass;
$sId = $this->iObjKey;
$this->oPage->add('<div style="clear:both"></div>');
$iMaxUploadInBytes = AttachmentPlugIn::GetMaxUploadSize();
$sMaxUploadLabel = AttachmentPlugIn::GetMaxUpload();
$sFileTooBigLabel = Dict::Format('Attachments:Error:FileTooLarge', $sMaxUploadLabel);
$sFileTooBigLabelForJS = addslashes($sFileTooBigLabel);
$this->oPage->p(Dict::S('Attachments:AddAttachment').'<input type="file" name="file" id="file"><span style="display:none;" id="attachment_loading"><img src="../images/indicator.gif"></span> '.$sMaxUploadLabel);
$this->oPage->add('<div id="ibo-attachment--upload-file">');
$this->oPage->add(Dict::S('Attachments:AddAttachment'));
$oAddButton = FileSelectUIBlockFactory::MakeStandard('file', 'file');
$oAddButton->SetShowFilename(false);
$this->oPage->AddUiBlock($oAddButton);
$this->oPage->add('<span style="display:none;" id="attachment_loading"><img src="../images/indicator.gif"></span> '.$sMaxUploadLabel);
$this->oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.iframe-transport.js');
$this->oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.fileupload.js');
@@ -318,6 +323,7 @@ abstract class AbstractAttachmentsRenderer
JS
);
$this->oPage->p('<input type="hidden" id="attachment_plugin" name="attachment_plugin"/>');
$this->oPage->add('</div>');
$this->oPage->add_style(<<<CSS
.drag_in {

View File

@@ -24,6 +24,8 @@ class FileSelect extends UIBlock
private $sFileName;
/** @var string */
private $sButtonText;
/** @var bool */
private $bShowFilename;
public function __construct(string $sName, string $sId = null)
{
@@ -31,6 +33,7 @@ class FileSelect extends UIBlock
$this->sName = $sName;
$this->sFileName = Dict::S('UI:InputFile:NoFileSelected');
$this->sButtonText = Dict::S('UI:InputFile:SelectFile');
$this->bShowFilename = true;
}
/**
@@ -80,4 +83,25 @@ class FileSelect extends UIBlock
{
return $this->sName;
}
/**
* @param bool $bShowFilename
*
* @return $this
*/
public function SetShowFilename(bool $bShowFilename)
{
$this->bShowFilename = $bShowFilename;
return $this;
}
/**
* @return bool
*/
public function GetShowFilename(): bool
{
return $this->bShowFilename;
}
}

View File

@@ -1,7 +1,8 @@
{# @copyright Copyright (C) 2010-2021 Combodo SARL #}
{# @license http://opensource.org/licenses/AGPL-3.0 #}
$('#{{ oUIBlock.GetId() }}').bind('change', function() {
var fileName = $(this).val().replace(/^.*[\\\/]/, '');
$('#{{ oUIBlock.GetId() }}-file-name').html(fileName);
});
{% if oUIBlock.GetShowFilename() == true %}
$('#{{ oUIBlock.GetId() }}').bind('change', function() {
var fileName = $(this).val().replace(/^.*[\\\/]/, '');
$('#{{ oUIBlock.GetId() }}-file-name').html(fileName);
});
{% endif %}