From: Joshua Rüsweg Date: Wed, 22 Aug 2018 08:08:07 +0000 (+0200) Subject: Use multiple promises instead of one to make it easier to validate data X-Git-Tag: 5.2.0_Alpha_1~364^2~71^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=376046e96d12927f765fd1ab36de5b991accfd40;p=GitHub%2FWoltLab%2FWCF.git Use multiple promises instead of one to make it easier to validate data See #2743 --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/InlineEditor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/InlineEditor.js index 12588f8160..9e0c696a17 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/InlineEditor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/InlineEditor.js @@ -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); }, /**