From 376046e96d12927f765fd1ab36de5b991accfd40 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Wed, 22 Aug 2018 10:08:07 +0200 Subject: [PATCH] Use multiple promises instead of one to make it easier to validate data See #2743 --- .../Core/Ui/Message/InlineEditor.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) 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); }, /** -- 2.20.1