[FIX] web_editor: don't run code when input is emptied
Before this commit:
- Edit mode, open image dialog
- Upload an image to the media dialog
- Reclick on Upload but don't select an image, close the browser image
selector
- This will trigger the input change event, as the input was emptied
This is needed since in later commit, `_addData()` will do some code outside
of the `files` loop, which is useless if there is no files selected.
In thise case, the issue would be that it would open an empty toastr.
task-2345082
Coming from #65828
Closes #68326
closes odoo/odoo#68340
X-original-commit: 94c45412714c1263788b2567ce3c9581453b2cd4
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
@@ -557,13 +557,18 @@ var FileWidget = SearchableMediaWidget.extend({
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
_addData: function () {
|
||||
async _addData() {
|
||||
let files = this.$fileInput[0].files;
|
||||
if (!files.length) {
|
||||
// Case if the input is emptied, return resolved promise
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
var uploadMutex = new concurrency.Mutex();
|
||||
|
||||
// Upload the smallest file first to block the user the least possible.
|
||||
var files = _.sortBy(this.$fileInput[0].files, 'size');
|
||||
|
||||
files = _.sortBy(files, 'size');
|
||||
_.each(files, function (file) {
|
||||
// Upload one file at a time: no need to parallel as upload is
|
||||
// limited by bandwidth.
|
||||
|
||||
Reference in New Issue
Block a user