Ver Fonte

Fix #1136: Allow proper retry of error uploads based on `retryErrorUploads` setting

Kartik Visweswaran há 6 anos atrás
pai
commit
47e42c043f
4 ficheiros alterados com 28 adições e 11 exclusões
  1. 1 0
      CHANGE.md
  2. 8 1
      examples/index.html
  3. 19 10
      js/fileinput.js
  4. 0 0
      js/fileinput.min.js

+ 1 - 0
CHANGE.md

@@ -5,6 +5,7 @@ Change Log: `bootstrap-fileinput`
 
 **Date:** 18-Apr-2019
 
+- (enh #1136): Allow proper retry of error uploads based on `retryErrorUploads` setting.
 - Better management of console log messages.
 - (bug #1391): Correct resumable upload progress update behavior when `showPreview` is `false`.
 - (bug #1390): Correct remove button display validation set via `fileActionSettings`.

+ 8 - 1
examples/index.html

@@ -40,6 +40,11 @@
         <button type="reset" class="btn btn-outline-secondary">Reset</button>
     </form>
     <hr>
+    <h5>Preupload Validation</h5>
+    <input id="file-0" name="file-0" type="file">
+    <br>
+    <textarea id="description" rows=3" class="form-control" placeholder="Enter description for the files selected..."></textarea>
+    <br>
     <form enctype="multipart/form-data">
         <label for="file-0b">Test invalid input type</label>
         <div class="file-loading">
@@ -142,7 +147,9 @@
     });
     $("#file-0").fileinput({
         theme: 'fas',
-        'allowedFileExtensions': ['jpg', 'png', 'gif']
+        uploadUrl: '#'
+    }).on('filepreupload', function(event, data, previewId, index) {
+        alert('The description entered is:\n\n' + ($('#description').val() || ' NULL'));
     });
     $("#file-1").fileinput({
         theme: 'fas',

+ 19 - 10
js/fileinput.js

@@ -771,6 +771,7 @@
             self.fileManager = {
                 stack: {},
                 processed: [],
+                errors: [],
                 loadedImages: {},
                 totalImages: 0,
                 totalFiles: null,
@@ -904,6 +905,7 @@
                     fm.totalSize = null;
                     fm.uploadedSize = 0;
                     fm.stack = {};
+                    fm.errors = [];
                     fm.processed = [];
                     fm.stats = {};
                     fm.clearImages();
@@ -2042,9 +2044,9 @@
             self._raise('filefoldererror', [folders, msg]);
         },
         _showUploadError: function (msg, params, event) {
-            var self = this, $error = self.$errorContainer, ev = event || 'fileuploaderror', fId = params.fileId || '',
-                e = params && params.id ?
-                    '<li data-thumb-id="' + params.id + '" data-file-id="' + fId + '">' + msg + '</li>' : '<li>' + msg + '</li>';
+            var self = this, $error = self.$errorContainer, ev = event || 'fileuploaderror',
+                fId = params && params.fileId || '', e = params && params.id ?
+                '<li data-thumb-id="' + params.id + '" data-file-id="' + fId + '">' + msg + '</li>' : '<li>' + msg + '</li>';
             if ($error.find('ul').length === 0) {
                 self._addError('<ul>' + e + '</ul>');
             } else {
@@ -2755,7 +2757,7 @@
             }
             if (self.isAjaxUpload) {
                 if (self.fileManager.count() > 0) {
-                    files = self.fileManager.stack;
+                    files = $.extend(true, {}, self.fileManager.stack);
                     self.fileManager.clear();
                     self._clearFileInput();
                 } else {
@@ -3178,10 +3180,12 @@
             }
             updateUploadLog = function () {
                 if (!uploadFailed) {
-                    self.fileManager.removeFile(id);
+                    fm.removeFile(id);
+                } else {
+                    fm.errors.push(id);
                 }
-                self.fileManager.setProcessed(id);
-                if (self.fileManager.isProcessed()) {
+                fm.setProcessed(id);
+                if (fm.isProcessed()) {
                     self.fileBatchCompleted = true;
                 }
             };
@@ -3191,7 +3195,7 @@
                     return;
                 }
                 setTimeout(function () {
-                    var triggerReset = self.fileManager.count() === 0;
+                    var triggerReset = fm.count() === 0, errCount = fm.errors.length;
                     self._updateInitialPreview();
                     self.unlock(triggerReset);
                     if (triggerReset) {
@@ -3202,8 +3206,10 @@
                         $h.addCss($initThumbs, $h.SORT_CSS);
                         self._initSortable();
                     }
-                    self._raise('filebatchuploadcomplete', [self.fileManager.stack, self._getExtraData()]);
-                    self.fileManager.clear();
+                    self._raise('filebatchuploadcomplete', [fm.stack, self._getExtraData()]);
+                    if (!self.retryErrorUploads || errCount === 0) {
+                        fm.clear();
+                    }
                     self._setProgress(101);
                     self.ajaxAborted = false;
                 }, self.processDelay);
@@ -3226,6 +3232,9 @@
                 if (!isBatch) {
                     self.lock();
                 }
+                if (fm.errors.indexOf(id) !== -1) {
+                    delete fm.errors[id];
+                }
                 self._raise('filepreupload', [outData, previewId, i]);
                 $.extend(true, params, outData);
                 if (self._abort(params)) {

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
js/fileinput.min.js


Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff