From: Matthias Schmidt Date: Wed, 3 Apr 2019 17:59:17 +0000 (+0200) Subject: Fix issues with JavaScript form builder data handling X-Git-Tag: 5.2.0_Alpha_1~172 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d6d6b476467756c1e2c6ea542900a9f53b0f89f3;p=GitHub%2FWoltLab%2FWCF.git Fix issues with JavaScript form builder data handling See #2509 See 477f6668abcef42b09b5bcc8cdfd70be8f463983 --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Dialog.js index b833273669..efac16a974 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Dialog.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Dialog.js @@ -63,22 +63,39 @@ define(['Ajax', 'Core', './Manager', 'Ui/Dialog'], function(Ajax, Core, FormBuil * @param {object} data response data */ _ajaxSuccess: function(data) { - if (data.returnValues === undefined) { - throw new Error("Missing return data."); - } - else if (data.returnValues.dialog === undefined) { - throw new Error("Missing dialog template in return data."); - } - else if (data.returnValues.formId === undefined) { - throw new Error("Missing form id in return data."); + switch (data.actionName) { + case this._actionName: + if (data.returnValues === undefined) { + throw new Error("Missing return data."); + } + else if (data.returnValues.dialog === undefined) { + throw new Error("Missing dialog template in return data."); + } + else if (data.returnValues.formId === undefined) { + throw new Error("Missing form id in return data."); + } + + this.destroy(true); + + this._formId = data.returnValues.formId; + this._dialogContent = data.returnValues.dialog; + + UiDialog.open(this, this._dialogContent); + + break; + + case this._options.submitActionName: + this.destroy(); + + if (typeof this._options.successCallback === 'function') { + this._options.successCallback(data.returnValues || {}); + } + + break; + + default: + throw new Error("Cannot handle action '" + data.actionName + "'."); } - - this.destroy(true); - - this._formId = data.returnValues.formId; - this._dialogContent = data.returnValues.dialog; - - UiDialog.open(this, this._dialogContent); }, /** diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Field.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Field.js index 59edc17076..d4d6dee6a3 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Field.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Field.js @@ -64,13 +64,7 @@ define([], function() { * @return {Promise} */ getData: function() { - var data = this._getData(); - - if (!(data instanceof Promise)) { - return Promise.resolve(data); - } - - return data; + return Promise.resolve(this._getData()); }, /** diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Manager.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Manager.js index 550a32e66f..9bdcc79e79 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Manager.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Manager.js @@ -48,16 +48,14 @@ define([ promises.push(fieldData); }); - return new Promise(function(resolve, reject) { - Promise.all(promises).then(function(promiseData) { - var data = {}; - - for (var i = 0, length = promiseData.length; i < length; i++) { - data = Core.extend(data, promiseData[i]); - } - - resolve(data); - }); + return Promise.all(promises).then(function(promiseData) { + var data = {}; + + for (var i = 0, length = promiseData.length; i < length; i++) { + data = Core.extend(data, promiseData[i]); + } + + return data; }); },