Forráskód Böngészése

Fix #156: Fix reset of file stack for various upload modes

Kartik Visweswaran 10 éve
szülő
commit
2717793134
3 módosított fájl, 33 hozzáadás és 26 törlés
  1. 1 0
      CHANGE.md
  2. 32 26
      js/fileinput.js
  3. 0 0
      js/fileinput.min.js

+ 1 - 0
CHANGE.md

@@ -8,6 +8,7 @@ version 4.1.7
 4. (enh #153): Improve error handler for trapping FileReader security exceptions and new property `msgFileSecured` will display the security exception message.
 5. (enh #154): Code cleanup and restructure for JS lint changes (using JSHint Code cleanup library).
 6. (enh #155): Allow display of long file names without spaces/word breaks.
+7. (enh #156): Fix reset of file stack for various upload modes (single, batch async and batch sync).
 
 version 4.1.6
 =============

+ 32 - 26
js/fileinput.js

@@ -292,7 +292,6 @@
         constructor: FileInput,
         init: function (options) {
             var self = this, $el = self.$element, content;
-            self.locked = false;
             $.each(options, function (key, value) {
                 self[key] = value;
             });
@@ -459,18 +458,6 @@
                         self.uploadSingle(i, self.filestack, true);
                     }
                 }
-                setTimeout(function () {
-                    $(document).off('.kvfileinput').on('ajaxStop.kvfileinput', function () {
-                        if (!self.locked) {
-                            return;
-                        }
-                        self.setProgress(100);
-                        self.$preview.find('file-preview-frame').removeClass('file-loading');
-                        self.unlock();
-                        self.clearFileInput();
-                        self.raise('filebatchuploadcomplete', [self.filestack, self.getExtraData()]);
-                    });
-                }, 100);
                 return;
             }
             self.uploadBatch();
@@ -485,11 +472,13 @@
             if (self.showCancel) {
                 self.$container.find('.fileinput-cancel').removeClass('hide');
             }
-            self.locked = true;
             self.raise('filelock', [self.filestack, self.getExtraData()]);
         },
-        unlock: function () {
+        unlock: function (reset) {
             var self = this;
+            if (reset === undefined) {
+                reset = true;
+            }
             self.enable();
             if (self.showCancel) {
                 addCss(self.$container.find('.fileinput-cancel'), 'hide');
@@ -497,8 +486,9 @@
             if (self.showRemove) {
                 self.$container.find('.fileinput-remove').removeClass('hide');
             }
-            self.resetFileStack();
-            self.locked = false;
+            if (reset) {
+                self.resetFileStack();
+            }
             self.raise('fileunlock', [self.filestack, self.getExtraData()]);
         },
         resetFileStack: function () {
@@ -506,16 +496,19 @@
             self.$preview.find('.file-preview-frame').each(function () {
                 var $thumb = $(this), ind = $thumb.attr('data-fileindex'),
                     file = self.filestack[ind];
+                if (ind == -1) {
+                    return;
+                }
                 if (file !== undefined) {
                     newstack[i] = file;
                     $thumb.attr({
                         'id': self.previewInitId + '-' + i,
                         'data-fileindex': i
                     });
-                    i = i + 1;
+                    i += 1;
                 } else {
                     $thumb.attr({
-                        'id': $thumb.attr('id') + '-1',
+                        'id': 'uploaded-' + uniqId(),
                         'data-fileindex': '-1'
                     });
                 }
@@ -606,7 +599,7 @@
                 $el.off('click').on('click', function () {
                     var $frame = $el.closest('.file-preview-frame'),
                         ind = $frame.attr('data-fileindex');
-                    self.uploadSingle(ind, self.filestack);
+                    self.uploadSingle(ind, self.filestack, false);
                 });
             });
         },
@@ -843,7 +836,6 @@
                 }
                 self.unlock();
             });
-            self.locked = false;
         },
         clear: function (trig) {
             var self = this, cap;
@@ -983,7 +975,7 @@
         },
         uploadSingle: function (i, files, allFiles) {
             var self = this, total = self.getFileStack().length, formdata = new FormData(), outData,
-                previewId = self.previewInitId + "-" + i, $thumb = $('#' + previewId), cap, pct,
+                previewId = self.previewInitId + "-" + i, $thumb = $('#' + previewId), cap, pct, chkComplete,
                 $btnUpload = $thumb.find('.kv-file-upload'), $btnDelete = $thumb.find('.kv-file-remove'),
                 $indicator = $thumb.find('.file-upload-indicator'), config = self.fileActionSettings,
                 hasPostData = self.filestack.length > 0 || !$.isEmptyObject(self.uploadExtraData),
@@ -992,7 +984,16 @@
             if (total === 0 || !hasPostData || $btnUpload.hasClass('disabled')) {
                 return;
             }
-            allFiles = allFiles || false;
+            chkComplete = function () {
+                var $thumbs = self.$preview.find('.file-preview-frame.file-uploading'), chk = $thumbs.length;
+                if (chk > 0) {
+                    return;
+                }
+                self.setProgress(100);
+                self.unlock();
+                self.clearFileInput();
+                self.raise('filebatchuploadcomplete', [self.filestack, self.getExtraData()]);
+            };
             setIndicator = function (icon, msg) {
                 $indicator.html(config[icon]);
                 $indicator.attr('title', config[msg]);
@@ -1031,6 +1032,9 @@
                         $btnUpload.hide();
                         $btnDelete.hide();
                         self.filestack[i] = undefined;
+                        if (!allFiles) {
+                            self.resetFileStack();
+                        }
                         self.raise('fileuploaded', [outData, previewId, i]);
                     } else {
                         setIndicator('indicatorError', 'indicatorErrorTitle');
@@ -1042,10 +1046,12 @@
                 setTimeout(function () {
                     updateProgress();
                     resetActions();
+                    if (!allFiles) {
+                        self.unlock(false);
+                    } else {
+                        chkComplete();
+                    }
                 }, 100);
-                if (!allFiles) {
-                    self.unlock();
-                }
             };
             fnError = function (jqXHR, textStatus, errorThrown) {
                 setIndicator('indicatorError', 'indicatorErrorTitle');

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
js/fileinput.min.js


Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott