mirror of
https://github.com/humhub/humhub.git
synced 2025-01-16 21:58:17 +01:00
Fix: Setting of submitName and upload input name in file upload JsWidget
Fix: Rendering of UploadButton without given id Enh: Added preventPopover and popoverPosition options to file preview Enh: Added uploadSingle option for uploads with only one file
This commit is contained in:
parent
b58aba384f
commit
7ed5f781cf
@ -16,7 +16,8 @@ use yii\base\Behavior;
|
||||
*
|
||||
* @since 0.5
|
||||
*/
|
||||
class PolymorphicRelation extends Behavior {
|
||||
class PolymorphicRelation extends Behavior
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string the class name attribute
|
||||
@ -43,7 +44,8 @@ class PolymorphicRelation extends Behavior {
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPolymorphicRelation() {
|
||||
public function getPolymorphicRelation()
|
||||
{
|
||||
|
||||
if ($this->_cached !== null) {
|
||||
return $this->_cached;
|
||||
@ -77,7 +79,8 @@ class PolymorphicRelation extends Behavior {
|
||||
*
|
||||
* @param mixed $object
|
||||
*/
|
||||
public function setPolymorphicRelation($object) {
|
||||
public function setPolymorphicRelation($object)
|
||||
{
|
||||
if ($this->validateUnderlyingObjectType($object)) {
|
||||
$this->_cached = $object;
|
||||
|
||||
@ -91,7 +94,8 @@ class PolymorphicRelation extends Behavior {
|
||||
/**
|
||||
* Resets the already loaded $_cached instance of related object
|
||||
*/
|
||||
public function resetPolymorphicRelation() {
|
||||
public function resetPolymorphicRelation()
|
||||
{
|
||||
$this->_cached = null;
|
||||
}
|
||||
|
||||
@ -101,7 +105,8 @@ class PolymorphicRelation extends Behavior {
|
||||
* @param mixed $object
|
||||
* @return boolean
|
||||
*/
|
||||
private function validateUnderlyingObjectType($object) {
|
||||
private function validateUnderlyingObjectType($object)
|
||||
{
|
||||
|
||||
if (count($this->mustBeInstanceOf) == 0) {
|
||||
return true;
|
||||
|
@ -3,7 +3,11 @@ HumHub Change Log
|
||||
|
||||
1.2.0-beta.3 under developement
|
||||
--------------------------------
|
||||
- Fix: missing margin of wall-entry-controls in comments
|
||||
- Fix: Setting of submitName and upload input name in file upload JsWidget
|
||||
- Fix: Rendering of UploadButton without given id
|
||||
- Enh: Added preventPopover and popoverPosition options to file preview
|
||||
- Enh: Added uploadSingle option for uploads with only one file
|
||||
- Fix: Missing margin of wall-entry-controls in comments
|
||||
- Enh: Added alignHeight setting to js loader module
|
||||
- Enh: Allow Response as arguments for modal.setDialog
|
||||
- Enh: Enable modal loading events with dataType json
|
||||
|
@ -226,8 +226,15 @@ humhub.module('file', function (module, require, $) {
|
||||
this.errors.push(file.errors);
|
||||
this.errors.push(' ');
|
||||
} else if (this.$form && this.$form.length) {
|
||||
this.fileCount++;
|
||||
var name = this.options.name || 'fileList[]';
|
||||
var name = this.options.uploadSubmitName || 'fileList[]';
|
||||
|
||||
if(this.options.uploadSingle) {
|
||||
this.$form.find('input[name="'+name+'"]').remove();
|
||||
this.fileCount = 1;
|
||||
} else {
|
||||
this.fileCount++;
|
||||
}
|
||||
|
||||
this.$form.append('<input type="hidden" name="' + name + '" value="' + file.guid + '">');
|
||||
if (this.preview) {
|
||||
this.preview.show();
|
||||
@ -313,23 +320,27 @@ humhub.module('file', function (module, require, $) {
|
||||
file.galleryId = this.$.attr('id') + '_file_preview_gallery';
|
||||
var template = this.getTemplate(file);
|
||||
var $file = $(string.template(template, file));
|
||||
|
||||
if(this.source && this.source.options.uploadSingle) {
|
||||
this.$list.find('li').remove();
|
||||
}
|
||||
|
||||
this.$list.append($file);
|
||||
|
||||
if (file.thumbnailUrl) {
|
||||
if (file.thumbnailUrl && !this.options.preventPopover) {
|
||||
// Preload image
|
||||
new Image().src = file.thumbnailUrl;
|
||||
|
||||
$file.find('.file-preview-content').popover({
|
||||
html: true,
|
||||
trigger: 'hover',
|
||||
animation: 'fade',
|
||||
delay: 100,
|
||||
placement: this.options.popoverPosition || 'right',
|
||||
content: function () {
|
||||
return string.template(Preview.template.popover, file);
|
||||
}
|
||||
});
|
||||
}
|
||||
;
|
||||
};
|
||||
|
||||
var that = this;
|
||||
$file.find('.file_upload_remove_link').on('click', function () {
|
||||
@ -345,9 +356,8 @@ humhub.module('file', function (module, require, $) {
|
||||
|
||||
Preview.prototype.isImage = function (file) {
|
||||
return file.mimeIcon === 'mime-image';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Preview.prototype.getTemplate = function (file) {
|
||||
if (this.options.fileEdit) {
|
||||
return Preview.template.file_edit;
|
||||
|
@ -4,12 +4,11 @@ use humhub\libs\Html;
|
||||
use humhub\widgets\ModalDialog;
|
||||
use humhub\modules\file\converter\PreviewImage;
|
||||
use humhub\modules\file\widgets\FileHandlerButtonDropdown;
|
||||
use yii\bootstrap\ButtonDropdown;
|
||||
|
||||
$modal = ModalDialog::begin(['header' => Yii::t('FileModule.base', '<strong>Open</strong> file', ['fileName' => Html::encode($file->file_name)])])
|
||||
?>
|
||||
|
||||
<?php ModalDialog::begin(['header' => Yii::t('FileModule.base', '<strong>Open</strong> file', ['fileName' => Html::encode($file->file_name)])]) ?>
|
||||
<div class="modal-body">
|
||||
|
||||
<?php
|
||||
$thumbnailUrl = '';
|
||||
$previewImage = new PreviewImage();
|
||||
|
@ -18,6 +18,9 @@ class FilePreview extends \humhub\widgets\JsWidget
|
||||
public $hideImageFileInfo = false;
|
||||
public $edit = false;
|
||||
public $visible = false;
|
||||
|
||||
public $preventPopover = false;
|
||||
public $popoverPosition = 'right';
|
||||
|
||||
/**
|
||||
* Draws the Upload Button output.
|
||||
@ -37,6 +40,8 @@ class FilePreview extends \humhub\widgets\JsWidget
|
||||
public function getData()
|
||||
{
|
||||
return [
|
||||
'prevent-popover' => $this->preventPopover,
|
||||
'popover-position' => $this->popoverPosition,
|
||||
'file-edit' => $this->edit,
|
||||
'hide-image-file-info' => $this->hideImageFileInfo
|
||||
];
|
||||
@ -45,10 +50,13 @@ class FilePreview extends \humhub\widgets\JsWidget
|
||||
protected function getFileData()
|
||||
{
|
||||
$files = $this->getFiles();
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
$result[] = FileHelper::getFileInfos($file);
|
||||
if($file) {
|
||||
$result[] = FileHelper::getFileInfos($file);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -42,7 +42,7 @@ class UploadButton extends UploadInput
|
||||
* @var type
|
||||
*/
|
||||
public $label = false;
|
||||
|
||||
|
||||
/**
|
||||
* Draws the Upload Button output.
|
||||
*/
|
||||
@ -58,11 +58,11 @@ class UploadButton extends UploadInput
|
||||
|
||||
$defaultButtonOptions = [
|
||||
'class' => ($this->tooltip) ? 'btn '.$this->cssButtonClass.' fileinput-button tt' : 'btn '.$this->cssButtonClass.' fileinput-button',
|
||||
'title' => Yii::t('FileModule.widgets_views_fileUploadButton', 'Upload files'),
|
||||
'title' => ($this->tooltip === true) ? Yii::t('FileModule.widgets_views_fileUploadButton', 'Upload files') : $this->tooltip,
|
||||
'data' => [
|
||||
'placement' => $this->tooltipPosition,
|
||||
'action-click' => "file.upload",
|
||||
'action-target' => '#'.$this->id
|
||||
'action-target' => '#'.$this->getId(true)
|
||||
]
|
||||
];
|
||||
|
||||
|
@ -21,7 +21,7 @@ use yii\helpers\Html;
|
||||
class UploadInput extends \humhub\widgets\JsWidget
|
||||
{
|
||||
|
||||
const DEFAULT_FORM_NAME = 'guids[]';
|
||||
const DEFAULT_FORM_NAME = 'fileList';
|
||||
|
||||
/**
|
||||
* javascript widget implementation.
|
||||
@ -44,7 +44,7 @@ class UploadInput extends \humhub\widgets\JsWidget
|
||||
public $model;
|
||||
|
||||
/**
|
||||
* Can be used to overwrite the default result input name guids[] with a model
|
||||
* Can be used to overwrite the default result input name files[] with a model
|
||||
* bound attribute formName.
|
||||
*
|
||||
* @var string
|
||||
@ -52,12 +52,19 @@ class UploadInput extends \humhub\widgets\JsWidget
|
||||
public $attribute;
|
||||
|
||||
/**
|
||||
* Can be used to overwrite the default result input name guids[] with a model
|
||||
* Can be used to overwrite the default result input name files[] with a model
|
||||
* bound attribute formName.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Defines the input name of the submitted array field containing the result guids.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $submitName;
|
||||
|
||||
/**
|
||||
* Can be set if the upload button is not contained in the form itself.
|
||||
@ -103,6 +110,14 @@ class UploadInput extends \humhub\widgets\JsWidget
|
||||
* @var type
|
||||
*/
|
||||
public $visible = false;
|
||||
|
||||
|
||||
/**
|
||||
* This flag can be used in order to only allow a single guid to be submitted.
|
||||
* Note that already attached files have to be removed manually.
|
||||
* @var boolean
|
||||
*/
|
||||
public $single = false;
|
||||
|
||||
/**
|
||||
* Draws the Upload Button output.
|
||||
@ -122,7 +137,15 @@ class UploadInput extends \humhub\widgets\JsWidget
|
||||
public function getData()
|
||||
{
|
||||
$formSelector = ($this->form instanceof \yii\widgets\ActiveForm) ? '#' + $this->form->getId() : $this->form;
|
||||
$resultFieldName = ($this->model && $this->attribute) ? $this->model->formName() + '[' + $this->attribute + '][]' : self::DEFAULT_FORM_NAME;
|
||||
|
||||
if($this->submitName) {
|
||||
$submitName = $this->submitName;
|
||||
} else {
|
||||
$submitName = ($this->model && $this->attribute) ? $this->model->formName() . '[' . $this->attribute . ']' : self::DEFAULT_FORM_NAME;
|
||||
if(!$this->single) {
|
||||
$submitName .= '[]';
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
'upload-url' => $this->url,
|
||||
@ -130,7 +153,8 @@ class UploadInput extends \humhub\widgets\JsWidget
|
||||
'upload-progress' => $this->progress,
|
||||
'upload-preview' => $this->preview,
|
||||
'upload-form' => $formSelector,
|
||||
'result-field-name' => $resultFieldName
|
||||
'upload-single' => $this->single,
|
||||
'upload-submit-name' => $submitName
|
||||
];
|
||||
|
||||
if ($this->model) {
|
||||
|
@ -17,14 +17,6 @@ class UploadProgress extends \humhub\widgets\JsWidget
|
||||
|
||||
public $visible = false;
|
||||
|
||||
/**
|
||||
* Draws the Upload Button output.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
return Html::beginTag('div', $this->getOptions()).Html::endTag('div');
|
||||
}
|
||||
|
||||
public function getAttributes()
|
||||
{
|
||||
return [
|
||||
|
Loading…
x
Reference in New Issue
Block a user