[WIP] Ajax Files Upload (#748)

* Reworked the `file` field. All files get uploaded via Ajax and are stored upon Save

This improves the Save task tremendously as now there is no longer the need of waiting for the files to finish uploading. Fully backward compatible, `file` field now includes also a `limit` and `filesize` option in the blueprints. The former determines how many files are allowed to be uploaded when in combination with `multiple: true` (default: 10), the latter determines the file size limit (in MB) allowed for each file (default: 5MB)

* Added support for `accept: [‘*’]` to allow any file type

* Minor tweaks in the comments and messages

* Delete any orphan file when discarding the uploaded files session

* Minor optimization

* Fixed issue with `_json` elements where nested fields merging would get stored in an unexpected way

* Potential fix for wrong order of value in Datetime

* Fixed nested fields for files

* Fixed tmp streams

* Minor cleanup

* Update JSON data when removing a file. Implemented task to remove files that haven’t been saved yet, from the flash object session

* Ensure temporary files are deleted when removing un-saved files from the flash object session

* Fixed wrong reference of HTML file field when clicking on the drop zone area to pick a file

* Added JSON template for pages

* fix a CSS issue in page order

* More CSS fixes

* Trigger file field mutation when adding or removing a file

* Recompiled JS

* Removed twig templates that are no longer needed

* Fixed issue with nested header fields in a page, not properly merging data

* [internal] Fixed issue with collections not capable of handling both param and dot notations at the same time

* Reorganized FileField structure to be more consistent with the other fields

* Added support for dynamically created file fields (ie, autoinitialization on new lists items)

* Added translationable strings for file uploads errors

* Added translasions for all Dropzone available strings

* Changed default values
This commit is contained in:
Djamil Legato
2016-08-29 11:12:09 -07:00
committed by GitHub
parent 2c07a1f209
commit 6b34336599
24 changed files with 807 additions and 483 deletions

View File

@@ -364,6 +364,23 @@ class AdminPlugin extends Plugin
exit();
}
// Clear flash objects for previously uploaded files
// whenever the user switches page / reloads
// ignoring any JSON / extension call
if (is_null($this->uri->extension()) && $task !== 'save') {
// Discard any previously uploaded files session.
// and if there were any uploaded file, remove them from the filesystem
if ($flash = $this->session->getFlashObject('files-upload')) {
$flash = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($flash));
foreach ($flash as $key => $value) {
if ($key !== 'tmp_name') {
continue;
}
@unlink($value);
}
}
}
$self = $this;
// make sure page is not frozen!
@@ -583,6 +600,9 @@ class AdminPlugin extends Plugin
],
'list' => [
'array' => true
],
'file' => [
'array' => true
]
];
}
@@ -722,7 +742,17 @@ class AdminPlugin extends Plugin
'THEMES',
'ALL',
'FROM',
'TO'
'TO',
'DROPZONE_CANCEL_UPLOAD',
'DROPZONE_CANCEL_UPLOAD_CONFIRMATION',
'DROPZONE_DEFAULT_MESSAGE',
'DROPZONE_FALLBACK_MESSAGE',
'DROPZONE_FALLBACK_TEXT',
'DROPZONE_FILE_TOO_BIG',
'DROPZONE_INVALID_FILE_TYPE',
'DROPZONE_MAX_FILES_EXCEEDED',
'DROPZONE_REMOVE_FILE',
'DROPZONE_RESPONSE_ERROR'
];
foreach ($strings as $string) {