Enh: Enhanced file upload handling. Added humhub:file:uploadStart and humhub:file:uploadEnd frontend events.

This commit is contained in:
buddh4 2017-02-17 14:46:39 +01:00
parent 18d39adfbd
commit 0958b9e01b
6 changed files with 49 additions and 12 deletions

View File

@ -32,9 +32,14 @@ class DownloadFileHandler extends BaseFileHandler
{
return [
'label' => Yii::t('FileModule.base', 'Download') . ' <small>(' . Yii::$app->formatter->asShortSize($this->file->size, 1) . ')</small>',
'href' => Url::to(['/file/file/download', 'guid' => $this->file->guid]),
'href' => self::getUrl($this->file),
'target' => '_blank',
];
}
public static function getUrl($file, $download = 0)
{
return Url::to(['/file/file/download', 'guid' => $file->guid, 'download' => $download]);
}
}

View File

@ -163,6 +163,8 @@ humhub.module('file', function (module, require, $) {
if (this.callbacks.start) {
this.callbacks.start(e, data);
}
this.fire('humhub:file:uploadStart', [data]);
};
Upload.prototype.updateProgress = function (e, data) {
@ -185,7 +187,7 @@ humhub.module('file', function (module, require, $) {
this.callbacks.done(e, response);
}
this.fire('humhub:file:upload', [response]);
this.fire('humhub:file:uploadEnd', [response]);
};
Upload.prototype.handleFileResponse = function (file) {

View File

@ -35,6 +35,11 @@ class FileHandlerButtonDropdown extends \humhub\components\Widget
*/
public $handlers;
/**
* @var boolean if true the dropdown-menu will be assigned with an dropdown-menu-right class.
*/
public $pullRight = false;
/**
* @inheritdoc
*/
@ -57,7 +62,10 @@ class FileHandlerButtonDropdown extends \humhub\components\Widget
if (count($this->handlers) !== 0) {
$output .= '<button type="button" class="btn ' . $this->cssButtonClass . ' dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="caret"></span><span class="sr-only">Toggle Dropdown</span></button>';
$output .= Html::beginTag('ul', ['class' => 'dropdown-menu']);
$cssClass = ($this->pullRight) ? 'dropdown-menu dropdown-menu-right' : 'dropdown-menu';
$output .= Html::beginTag('ul', ['class' => $cssClass]);
foreach ($this->handlers as $handler) {
$output .= Html::beginTag('li');
$output .= $this->renderLink($handler->getLinkAttributes());

View File

@ -30,13 +30,34 @@ class UploadButton extends UploadInput
*/
public $tooltipPosition = 'bottom';
/**
* Defines the button color class like btn-default, btn-primary
* @var type
*/
public $cssButtonClass = 'btn-default';
/**
* Either defines a label string or true to use the default label.
* If set to false, no button label is printed.
* @var type
*/
public $label = false;
/**
* Draws the Upload Button output.
*/
public function run()
{
if($this->label === true) {
$this->label = '&nbsp;'.Yii::t('base', 'Upload');
} else if($this->label === false) {
$this->label = '';
} else {
$this->label = '&nbsp;'.$this->label;
}
$defaultButtonOptions = [
'class' => ($this->tooltip) ? 'btn btn-default fileinput-button tt' : 'btn btn-default fileinput-button',
'class' => ($this->tooltip) ? 'btn '.$this->cssButtonClass.' fileinput-button tt' : 'btn '.$this->cssButtonClass.' fileinput-button',
'title' => Yii::t('FileModule.widgets_views_fileUploadButton', 'Upload files'),
'data' => [
'placement' => $this->tooltipPosition,
@ -49,7 +70,8 @@ class UploadButton extends UploadInput
return $this->render('uploadButton', [
'input' => parent::run(),
'options' => $options
'options' => $options,
'label' => $this->label
]);
}
}

View File

@ -3,6 +3,6 @@ use yii\helpers\Html;
?>
<?= Html::beginTag('span', $options) ?>
<i class="fa fa-cloud-upload" aria-hidden="true"></i>
<i class="fa fa-cloud-upload" aria-hidden="true"></i> <?= $label ?>
<?= $input ?>
<?= Html::endTag('span') ?>

View File

@ -616,15 +616,15 @@ humhub.module('ui.modal', function(module, require, $) {
var _getConfirmOptionsByTrigger = function($trigger) {
return {
'body' : $trigger.data('confirm'),
'header' : $trigger.data('confirm-header'),
'confirmText' : $trigger.data('confirm-text'),
'cancelText' : $trigger.data('cancel-text')
'body' : $trigger.data('action-confirm'),
'header' : $trigger.data('action-confirm-header'),
'confirmText' : $trigger.data('action-confirm-text'),
'cancelText' : $trigger.data('action-cancel-text')
};
};
var post = function(evt) {
module.global.post(evt).catch(function(err) {
return module.global.post(evt).catch(function(err) {
module.log.error(err, true);
});
};