Commit a8b8f4a0 authored by Henning Leutz's avatar Henning Leutz 🥋

fix: form upload

parent 1a4dcc8e
......@@ -34,7 +34,8 @@ define('controls/upload/Form', [
], function (QUI, QUIControl, QUIProgressbar, QUIButton, MediaUtils, Upload, Locale) {
"use strict";
var lg = 'quiqqer/quiqqer';
var lg = 'quiqqer/quiqqer';
var delayClick = false;
/**
* @class controls/upload/Form
......@@ -48,6 +49,7 @@ define('controls/upload/Form', [
Type : 'controls/upload/Form',
options: {
name : false,
action : URL_LIB_DIR + 'QUI/Upload/bin/upload.php',
method : 'POST', // form method
maxuploads : false, // how many uploads are allowed
......@@ -89,6 +91,10 @@ define('controls/upload/Form', [
var self = this;
if (typeof options.name !== 'undefined' && options.name === '') {
options.name = false;
}
this.parent(options);
this.$Add = null;
......@@ -276,8 +282,6 @@ define('controls/upload/Form', [
this.$Form.setStyle('cursor', 'pointer');
this.$formClick = false;
var delayClick = false;
this.$Form.addEvent('click', function (event) {
if (self.$formClick || delayClick) {
return;
......@@ -293,7 +297,9 @@ define('controls/upload/Form', [
return;
}
event.stop();
if (event.target.nodeName === 'FORM') {
event.stop();
}
var Input = self.addInput();
......@@ -375,10 +381,6 @@ define('controls/upload/Form', [
this.refreshDisplay();
if (this.getAttribute('typeOfLook') === 'Icon') {
//this.$Form.setStyle('display', 'none');
}
return this.$Elm;
},
......@@ -402,6 +404,10 @@ define('controls/upload/Form', [
html : '<input type="file" />'
}).inject(this.$Elm);
if (this.getAttribute('name')) {
IconForm.getElement('input').set('name', this.getAttribute('name'));
}
var self = this;
var UploadIcon = new Element('span').inject(IconForm);
var Input = IconForm.getElement('input');
......@@ -449,7 +455,7 @@ define('controls/upload/Form', [
},
/**
*
* create the single view
*/
$createSingleView: function () {
if (this.getAttribute('typeOfLook') !== 'Single') {
......@@ -471,6 +477,10 @@ define('controls/upload/Form', [
html : '<input type="file" />'
}).inject(this.$Elm);
if (this.getAttribute('name')) {
IconForm.getElement('input').set('name', this.getAttribute('name'));
}
var self = this;
var Input = IconForm.getElement('input');
......@@ -632,20 +642,29 @@ define('controls/upload/Form', [
if (this.getAttribute('maxuploads') !== false &&
elms.length !== 0 &&
this.getAttribute('maxuploads') <= elms.length) {
QUI.getMessageHandler(function (MH) {
MH.addError(
Locale.get(lg, 'upload.form.message.limit', {
limit: self.getAttribute('maxuploads')
})
);
});
return false;
return elms[0];
}
var Container = new Element('div.qui-form-upload');
Container.addEvents({
mouseenter: function () {
var Button = Container.getElement('button');
var Btn = QUI.Controls.getById(Button.get('data-quiid'));
Btn.enable();
Container.getElement('button').setStyle('display', null);
},
mouseleave: function () {
var Button = Container.getElement('button');
var Btn = QUI.Controls.getById(Button.get('data-quiid'));
Btn.disable();
Container.getElement('button').setStyle('display', 'none');
}
});
var Input = new Element('input', {
type : "file",
name : "files",
......@@ -654,10 +673,14 @@ define('controls/upload/Form', [
change: this.$onInputChange.bind(this)
},
styles : {
display: 'inline'
display: 'none'
}
}).inject(Container);
if (this.getAttribute('name')) {
Input.set('name', this.getAttribute('name'));
}
if (this.getAttribute('accept')) {
Input.accept = this.getAttribute('accept');
}
......@@ -689,8 +712,14 @@ define('controls/upload/Form', [
name : 'remove',
image : 'fa fa-remove',
Container: Container,
disabled : true,
styles : {
display: 'none'
},
events : {
onClick: function (Btn) {
onClick: function (Btn, event) {
event.stop();
var Container = Btn.getAttribute('Container');
var fid = Slick.uidOf(Input);
......@@ -706,7 +735,6 @@ define('controls/upload/Form', [
}
}).inject(Container);
Container.inject(this.$Form);
if (this.$Add &&
......@@ -757,10 +785,11 @@ define('controls/upload/Form', [
'url(' + MediaUtils.getIconByMimeType(File.type) + ')'
);
this.refreshDisplay();
this.fireEvent('add', [this, File]);
Input.setStyle('display', 'none');
//Input.setStyle('display', 'none');
Container.setStyle('visibility', 'visible');
moofx(this.$BgText).animate({
......@@ -996,6 +1025,8 @@ define('controls/upload/Form', [
var Target = event.target,
files = Target.files;
event.stop();
if (typeof files === 'undefined') {
return;
}
......@@ -1010,14 +1041,6 @@ define('controls/upload/Form', [
sum = current + files.length;
if (maxUploads && maxUploads < sum) {
QUI.getMessageHandler().then(function (MH) {
MH.addError(
Locale.get(lg, 'upload.form.message.limit', {
limit: maxUploads
})
);
});
return;
}
......@@ -1176,11 +1199,11 @@ define('controls/upload/Form', [
},
events : {
click: function () {
self.getElm().set('html', '');
var Old = self.getElm();
Old.set('html', '');
self.$files = {};
self.$Form = self.createForm();
self.$Form.inject(self.getElm());
self.create().replaces(Old);
}
}
}).inject(this.$Info);
......
......@@ -7,6 +7,7 @@
var allowedFileTypes = {$allowedFileTypes};
var Form = new UploadForm({
name : '{$name}',
contextMenu: {$contextMenu},
multiple : {$multiple},
sendbutton : {$sendbutton},
......
......@@ -21,7 +21,7 @@ class Form extends QUI\QDOM
{
// defaults
$this->setAttributes([
'name' => '', // @todo input field name
'name' => 'test-upload',
'contextMenu' => true,
'multiple' => true,
'sendbutton' => true,
......@@ -80,6 +80,7 @@ class Form extends QUI\QDOM
$Engine->assign([
'this' => $this,
'name' => $this->getAttribute('name'),
'id' => QUI\Utils\Uuid::get(),
'uploads' => \intval($this->getAttribute('uploads')),
'contextMenu' => $this->phpBool2JsBool(\boolval($this->getAttribute('contextMenu'))),
......
......@@ -10,12 +10,3 @@
{$Site->getAttribute('content')}
</div>
{/if}
{$FormUpload->create()}
<style>
footer {
display: inline-block;
margin-top: 40px;
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment