Fix issues with JavaScript form builder data handling
authorMatthias Schmidt <gravatronics@live.com>
Wed, 3 Apr 2019 17:59:17 +0000 (19:59 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 3 Apr 2019 17:59:17 +0000 (19:59 +0200)
See #2509
See 477f6668abcef42b09b5bcc8cdfd70be8f463983

wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Dialog.js
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Field.js
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Manager.js

index b833273669970e4ba38fa3c0cb44b2598919b88e..efac16a974bebb4b6bc363fc04fe4a4a726b5dab 100644 (file)
@@ -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);
                },
                
                /**
index 59edc1707633ffca436b5886549f2ba3dcd7f3fb..d4d6dee6a3a59848d90c8b4e932a56894bc6df35 100644 (file)
@@ -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());
                },
                
                /**
index 550a32e66f114599304584b82cc3318c6e4561b6..9bdcc79e79ce2f61f8eb42bf133599aa2bea3dba 100644 (file)
@@ -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;
                        });
                },