Procházet zdrojové kódy

Ticket #4447 - Timeline: Doesn't allow to submit while media is uploading.

AntonLV před 3 roky
rodič
revize
547ddf6d6f

+ 1 - 0
inc/classes/BxDolUploader.php

@@ -290,6 +290,7 @@ abstract class BxDolUploader extends BxDolFactory
                     'is_init_reordering' => isset($aParams['is_init_reordering']) ? $aParams['is_init_reordering'] : 0,
                 ]
             ],
+            'on_upload_before' => 'false',
             'on_upload' => 'false',
             'on_restore_ghosts' => 'false'
         ], $aParams));

+ 13 - 4
inc/js/classes/BxDolUploader.js

@@ -53,6 +53,7 @@ BxDolUploaderBase.prototype.init = function (sUploaderObject, sStorageObject, sU
 
     this._isErrorShown = false;
 
+    this._onUploadBefore = typeof options.on_upload_before === 'function' ? options.on_upload_before : function () {};
     this._onUpload = typeof options.on_upload === 'function' ? options.on_upload : function () {};
     this._onRestoreGhosts = typeof options.on_restore_ghosts === 'function' ? options.on_restore_ghosts : function () {};
 }
@@ -114,6 +115,9 @@ BxDolUploaderBase.prototype.onBeforeUpload = function (params) {
     this._isUploadsInProgress = true;
     this._lockPageFromLeaving();
     this._clearErrors();
+
+    if(typeof this._onUploadBefore === 'function')
+        this._onUploadBefore(this);
 }
 
 BxDolUploaderBase.prototype.onProgress = function (params) {
@@ -134,7 +138,7 @@ BxDolUploaderBase.prototype.onUploadCompleted = function (sErrorMsg) {
         $('#' + this._sPopupContainerId).dolPopupHide({});
 
         if(typeof this._onUpload === 'function')
-            this._onUpload(this._iContentId);
+            this._onUpload(this, this._iContentId);
     }
 }
 
@@ -148,7 +152,6 @@ BxDolUploaderBase.prototype.restoreGhosts = function (bInitReordering, onComplet
     var $this = this;
 
     bInitReordering = bInitReordering !== undefined ? bInitReordering : this._isReordering;
-    onComplete = typeof onComplete === 'function' ? onComplete : this._onRestoreGhosts;
 
     $.getJSON(sUrl, function (aData) {
 
@@ -197,7 +200,10 @@ BxDolUploaderBase.prototype.restoreGhosts = function (bInitReordering, onComplet
         }
 
         if(typeof onComplete === 'function')
-            return onComplete(aData);
+            onComplete(aData);
+
+        if(typeof this._onRestoreGhosts === 'function')
+            this._onRestoreGhosts($this, aData);
     });
 };
 
@@ -648,7 +654,7 @@ function BxDolUploaderHTML5 (sUploaderObject, sStorageObject, sUniqId, options)
             }
 
             if(typeof this._onUpload === 'function')
-                this._onUpload(this._iContentId);
+                this._onUpload(this, this._iContentId);
         }
     }
 
@@ -666,6 +672,9 @@ function BxDolUploaderHTML5 (sUploaderObject, sStorageObject, sUniqId, options)
     this.onBeforeUpload = function (params) {
         this._isUploadsInProgress = true;
         this._clearErrors();
+
+        if(typeof this._onUploadBefore === 'function')
+            this._onUploadBefore(this);
     }
 
     this.onProgress = function (params) {

+ 3 - 2
modules/boonex/timeline/classes/BxTimelineUploaderHTML5Attach.php

@@ -29,8 +29,9 @@ class BxTimelineUploaderHTML5Attach extends BxTemplUploaderHTML5
         $sJsObject = $this->_oModule->_oConfig->getJsObject('post');
 
         $aParams = array_merge($aParams, [
-            'on_upload' => 'function(iContentId) {' . $sJsObject . '.onAttachMediaUpload(iContentId);}',
-            'on_restore_ghosts' => 'function(aData) {' . $sJsObject . '.onAttachMediaRestoreGhosts(aData);}',
+            'on_upload_before' => 'function(oUploader) {' . $sJsObject . '.onAttachMediaUploadBefore(oUploader);}',
+            'on_upload' => 'function(oUploader, iContentId) {' . $sJsObject . '.onAttachMediaUpload(oUploader, iContentId);}',
+            'on_restore_ghosts' => 'function(oUploader, aData) {' . $sJsObject . '.onAttachMediaRestoreGhosts(oUploader, aData);}',
         ]);
 
         return parent::getUploaderJs($mixedGhostTemplate, $isMultiple, $aParams, $bDynamic);

+ 9 - 2
modules/boonex/timeline/js/post.js

@@ -236,7 +236,12 @@ BxTimelinePost.prototype.showAttachLink = function(oLink, iEventId)
     return false;
 };
 
-BxTimelinePost.prototype.onAttachMediaUpload = function(iEventId)
+BxTimelinePost.prototype.onAttachMediaUploadBefore = function(oUploader)
+{
+    $('#' + oUploader._sResultContainerId).parents('form:first').find(":submit").prop('disabled', true).addClass('bx-btn-disabled');
+};
+
+BxTimelinePost.prototype.onAttachMediaUpload = function(oUploader, iEventId)
 {
     var $this = this;
     var oData = this._getDefaultData();
@@ -281,9 +286,11 @@ BxTimelinePost.prototype.onAttachMediaUpload = function(iEventId)
             );
         }
     }
+
+    $('#' + oUploader._sResultContainerId).parents('form:first').find(":submit").prop('disabled', false).removeClass('bx-btn-disabled');
 };
 
-BxTimelinePost.prototype.onAttachMediaRestoreGhosts = function(aData)
+BxTimelinePost.prototype.onAttachMediaRestoreGhosts = function(oUploader, aData)
 {
     //perform some action after attached media's ghosts restoration.
 };

+ 1 - 0
template/uploader_button_crop_js.html

@@ -6,6 +6,7 @@ __uploader_instance_name__ = new BxDolUploaderCrop('__engine__', '__storage_obje
     'template_error_msg': '<div class="bx-uploader-msg-err">{error}</div>',
     'template_ghost': __template_ghost__,
     'reordering': __is_init_reordering__,
+    'on_upload_before': __on_upload_before__,
     'on_upload': __on_upload__,
     'on_restore_ghosts': __on_restore_ghosts__
 });

+ 1 - 0
template/uploader_button_html5_js.html

@@ -15,6 +15,7 @@ __uploader_instance_name__ = new BxDolUploaderHTML5('__engine__', '__storage_obj
     'dictFileTooBig': '<bx_text_js:_sys_uploader_html5_file_is_too_big />',
     'dictMaxFilesExceeded': '<bx_text_js:_sys_uploader_html5_number_of_files_exceeded />',
     'dictInvalidFileType': '<bx_text_js:_sys_uploader_html5_invalid_file_type />',
+    'on_upload_before': __on_upload_before__,
     'on_upload': __on_upload__,
     'on_restore_ghosts': __on_restore_ghosts__
 });