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