Fixes issues with attachment limits
authorMatthias Schmidt <gravatronics@live.com>
Mon, 3 Jun 2013 14:42:30 +0000 (16:42 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 3 Jun 2013 14:42:30 +0000 (16:42 +0200)
When having uploaded attachments, the input field/upload button is removed and recreated again to "reset" its `files` property which can't be directly reseted since its read-only.

wcfsetup/install/files/js/WCF.Attachment.js
wcfsetup/install/files/js/WCF.js

index edc9f92090f74ab6898011232fd913f36c38fa80..5065da818b8e6b1dd6b7c7a58ed37d0722997bd1 100644 (file)
@@ -75,11 +75,6 @@ WCF.Attachment.Upload = WCF.Upload.extend({
                        
                        $innerError.html($errorMessage);
                        
-                       // reset value of file input (the 'files' prop is actually readonly!)
-                       if (this._fileUpload) {
-                               this._fileUpload.attr('value', '');
-                       }
-                       
                        return false;
                }
                
@@ -94,15 +89,15 @@ WCF.Attachment.Upload = WCF.Upload.extend({
         * @see WCF.Upload._upload()
         */
        _upload: function() {
-               if (!this._validateLimit()) {
-                       return false;
+               if (this._validateLimit()) {
+                       this._super();
                }
                
-               this._super();
-               
-               // reset value of file input (the 'files' prop is actually readonly!)
                if (this._fileUpload) {
-                       this._fileUpload.attr('value', '');
+                       // remove and re-create the upload button since the 'files' property
+                       // of the input field is readonly thus it can't be reset
+                       this._removeButton();
+                       this._createButton();
                }
        },
        
index 0c2031608c91a93bc05e068d0613d1cf3603ac7f..715599cc2deb3c6b721226ff13f835d9d49d943f 100755 (executable)
@@ -6457,13 +6457,13 @@ WCF.Upload = Class.extend({
         */
        _createButton: function() {
                if (this._supportsAJAXUpload) {
-                       this._fileUpload = $('<input type="file" name="'+this._name+'" '+(this._options.multiple ? 'multiple="true" ' : '')+'/>');
+                       this._fileUpload = $('<input type="file" name="' + this._name + '" ' + (this._options.multiple ? 'multiple="true" ' : '') + '/>');
                        this._fileUpload.change($.proxy(this._upload, this));
-                       var $button = $('<p class="button uploadButton"><span>'+WCF.Language.get('wcf.global.button.upload')+'</span></p>');
+                       var $button = $('<p class="button uploadButton"><span>' + WCF.Language.get('wcf.global.button.upload') + '</span></p>');
                        $button.prepend(this._fileUpload);
                }
                else {
-                       var $button = $('<p class="button uploadFallbackButton"><span>'+WCF.Language.get('wcf.global.button.upload')+'</span></p>');
+                       var $button = $('<p class="button uploadFallbackButton"><span>' + WCF.Language.get('wcf.global.button.upload') + '</span></p>');
                        $button.click($.proxy(this._showOverlay, this));
                }
                
@@ -6479,6 +6479,18 @@ WCF.Upload = Class.extend({
                this._buttonSelector.append(button);
        },
        
+       /**
+        * Removes the upload button.
+        */
+       _removeButton: function() {
+               var $selector = '.uploadButton';
+               if (!this._supportsAJAXUpload) {
+                       $selector = '.uploadFallbackButton';
+               }
+               
+               this._buttonSelector.find($selector).remove();
+       },
+       
        /**
         * Callback for file uploads.
         */