Explorar o código

Fix #167: New `deleteExtraData` property for ajax deletions

Kartik Visweswaran %!s(int64=10) %!d(string=hai) anos
pai
achega
2906b8e046
Modificáronse 4 ficheiros con 41 adicións e 16 borrados
  1. 3 2
      CHANGE.md
  2. 25 3
      README.md
  3. 13 11
      js/fileinput.js
  4. 0 0
      js/fileinput.min.js

+ 3 - 2
CHANGE.md

@@ -2,8 +2,9 @@ version 4.1.8
 =============
 **Date**: 21-Feb-2015
 
-1. (bug #171): Fix typo for files validation.
-2. (enh #173): Add ability to send extraData when no files are attached.
+1. (bug #167): New `deleteExtraData` property for ajax deletions.
+2. (bug #171): Fix typo for files validation.
+3. (enh #173): Add ability to send extraData when no files are attached.
 
 version 4.1.7
 =============

+ 25 - 3
README.md

@@ -625,6 +625,9 @@ _string_ the title to display on hover for the file remove button. Defaults to `
 #### uploadUrl
 _string_ the URL for the upload processing action (typically for ajax based processing). Defaults to `null`. If this is not set or `null`, then the upload button action will default to form submission. NOTE: This is MANDATORY if you want to use advanced features like drag & drop, append/remove files, selectively upload files via ajax etc.
 
+#### uploadAsync
+_bool_ whether the batch upload of multiple files will be asynchronous/in parallel. Defaults to `true`.
+
 #### uploadExtraData
 _object | function_ the extra data that will be passed as data to the url/AJAX server call via POST. This can be setup either as an object (associative array of keys and values) or as a function callback. As an object, it can be set for example as:
 
@@ -645,8 +648,25 @@ function() {
 }
 ```
 
-#### uploadAsync
-_bool_ whether the batch upload of multiple files will be asynchronous/in parallel. Defaults to `true`.
+#### deleteExtraData
+_object | function_ the extra data that will be passed as data to the initial preview delete url/AJAX server call via POST. This can be setup either as an object (associative array of keys and values) or as a function callback. As an object, it can be set for example as:
+
+```js
+ {id: 100, value: '100 Details'}
+```
+
+As a function callback, it can be setup for example as:
+
+```js
+function() {
+    var obj = {};
+    $('.your-form-class').find('input').each(function() {
+        var id = $(this).attr('id'), val = $(this).val();
+        obj[id] = val;
+    });
+    return obj;
+}
+```
 
 #### maxFileSize
 _float_ the maximum file size for upload in KB.  If set to `0`, it means size allowed is unlimited. Defaults to `0`.
@@ -1037,6 +1057,7 @@ This event is triggered before deletion of each thumbnail file in the `initialPr
 
 - `key`: the key passed within `initialPreviewConfig` for the selected file for delete.
 - `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction (if available).
+- `data`: the output of `deleteExtraData` object.
 
 ```js
 $('#input-id').on('filepredelete', function(event, key, jqXHR) {
@@ -1049,6 +1070,7 @@ This event is triggered after deletion of each thumbnail file in the `initialPre
 
 - `key`: the key passed within `initialPreviewConfig` for the selected file that will be passed as POST data to the `url`.
 - `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction (if available).
+- `data`: the output of `deleteExtraData` object.
 
 ```js
 $('#input-id').on('filedelete', function(event, key) {
@@ -1066,7 +1088,7 @@ $('#input-id').on('fileunlock', function(event, filestack) {
 #### filedeleteerror
 This event is triggered when an error is faced in deletion of each thumbnail file in the `initialPreview` content set. Additional parameters available are: 
 
-- `data`: this is always null for `filedeleteerror`.
+- `data`: the output of `deleteExtraData` object.
 - `previewId`: the identifier of the preview thumbnail container.
 - `index`: the zero-based index of the file in the preview container.
 - `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction (if available).

+ 13 - 11
js/fileinput.js

@@ -717,12 +717,15 @@
             self.$container.removeClass('file-input-new');
         },
         initPreviewDeletes: function () {
-            var self = this,
+            var self = this, extraData = self.deleteExtraData || {}, caption, $that,
                 resetProgress = function () {
                     if (self.$preview.find('.kv-file-remove').length === 0) {
                         self.reset();
                     }
                 };
+            if (typeof extraData === "function") { 
+                extraData = extraData();
+            }
             self.$preview.find('.kv-file-remove').each(function () {
                 var $el = $(this), $frame = $el.closest('.file-preview-frame'),
                     vUrl = $el.attr('data-url'), vKey = $el.attr('data-key'), $content;
@@ -734,17 +737,17 @@
                         url: vUrl,
                         type: 'POST',
                         dataType: 'json',
-                        data: {key: vKey},
+                        data: {key: vKey, extraData: extraData},
                         beforeSend: function (jqXHR) {
                             addCss($frame, 'file-uploading');
                             addCss($el, 'disabled');
-                            self.raise('filepredelete', [vKey, jqXHR]);
+                            self.raise('filepredelete', [vKey, jqXHR, extraData]);
                         },
                         success: function (data, textStatus, jqXHR) {
                             if (data.error === undefined) {
-                                self.raise('filedeleted', [vKey, jqXHR]);
+                                self.raise('filedeleted', [vKey, jqXHR, extraData]);
                             } else {
-                                self.showError(data.error, null, $el.attr('id'), vKey, 'filedeleteerror', jqXHR);
+                                self.showError(data.error, extraData, $el.attr('id'), vKey, 'filedeleteerror', jqXHR);
                                 resetProgress();
                             }
                             $frame.removeClass('file-uploading').addClass('file-deleted');
@@ -753,18 +756,16 @@
                                 $frame.remove();
                                 $content = $(document.createElement('div')).html(self.original.preview);
                                 $content.find('.file-preview-frame').each(function () {
-                                    var $that = $(this);
-                                    /*jshint eqeqeq: false*/
+                                    $that = $(this);
                                     if ($that.find('.kv-file-remove').attr('data-key') == vKey) {
                                         $that.remove();
                                     }
-                                    /*jshint eqeqeq: true*/
                                 });
                                 self.initialPreviewContent = $content.html();
                                 if (self.initialPreviewCount > 0) {
                                     self.initialPreviewCount -= 1;
                                 }
-                                var caption = self.initialCaption;
+                                caption = self.initialCaption;
                                 if (self.initialCaption.length === 0) {
                                     caption = self.msgSelected.repl('{n}', self.initialPreviewCount);
                                 }
@@ -776,7 +777,7 @@
                             });
                         },
                         error: function (jqXHR, textStatus, errorThrown) {
-                            self.showError(errorThrown, null, $el.attr('id'), vKey, 'filedeleteerror', jqXHR);
+                            self.showError(errorThrown, extraData, $el.attr('id'), vKey, 'filedeleteerror', jqXHR);
                             $frame.removeClass('file-uploading');
                             resetProgress();
                         }
@@ -1757,8 +1758,9 @@
         uploadIcon: '<i class="glyphicon glyphicon-upload"></i> ',
         uploadClass: 'btn btn-default',
         uploadUrl: null,
-        uploadExtraData: [],
         uploadAsync: true,
+        uploadExtraData: {},
+        deleteExtraData: {},
         maxFileSize: 0,
         maxFileCount: 0,
         msgSizeTooLarge: 'File "{name}" (<b>{size} KB</b>) exceeds maximum allowed upload size of <b>{maxSize} KB</b>. Please retry your upload!',

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
js/fileinput.min.js


Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio