Use multiple promises instead of one to make it easier to validate data
authorJoshua Rüsweg <josh@bastelstu.be>
Wed, 22 Aug 2018 08:08:07 +0000 (10:08 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Wed, 22 Aug 2018 08:08:07 +0000 (10:08 +0200)
See #2743

wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/InlineEditor.js

index 12588f8160bb342a938a8bd51ce26349a67c05d5..9e0c696a170e5f5cec6243b4cbb3cb7f6e62a63c 100644 (file)
@@ -497,12 +497,15 @@ define(
                        var validateResult = this._validate(parameters);
                        
                        if (!(validateResult instanceof Promise)) {
-                               validateResult = Promise.resolve(validateResult);
+                               if (validateResult === false) {
+                                       validateResult = Promise.reject();
+                               }
+                               else {
+                                       validateResult = Promise.resolve();
+                               }
                        }
                        
-                       validateResult.then(function (result) {
-                               if (!result) return; 
-                               
+                       validateResult.then(function () {
                                EventHandler.fire('com.woltlab.wcf.redactor2', 'submit_' + id, parameters);
                                
                                Ajax.api(this, {
@@ -511,7 +514,9 @@ define(
                                });
                                
                                this._hideEditor();
-                       }.bind(this));
+                       }.bind(this), function() {
+                               // ignore failure
+                       });
                },
                
                /**
@@ -529,16 +534,14 @@ define(
                                api: this,
                                parameters: parameters,
                                valid: true,
-                               promise: null
+                               promises: []
                        };
                        
                        EventHandler.fire('com.woltlab.wcf.redactor2', 'validate_' + this._getEditorId(), data);
                        
-                       if (data.valid !== false && data.promise !== null) {
-                               return data.promise;
-                       }
+                       data.promises.push(Promise[data.valid ? 'resolve' : 'reject']());
                        
-                       return (data.valid !== false);
+                       return Promise.all(data.promises);
                },
                
                /**