Add missing changes in previous commit
authorMatthias Schmidt <gravatronics@live.com>
Tue, 3 Nov 2020 10:21:53 +0000 (11:21 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 3 Nov 2020 10:21:53 +0000 (11:21 +0100)
wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Manager.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Poll/Editor.js

index fea4254603c5828be199ae3a84e569ee7da484d4..4ef70671743a3bd09f814129f833a133f55dbcf2 100644 (file)
@@ -139,6 +139,11 @@ define([
                        }
                        
                        _fields.get(formId).set(fieldId, field);
+                       
+                       EventHandler.fire('WoltLabSuite/Core/Form/Builder/Manager', 'registerField', {
+                               field: field,
+                               formId: formId,
+                       });
                },
                
                /**
index b8cb981d0f1186d8576abc807e0ce9d70f0cc10c..2aa13c887bf45f05b496373f25d6f44f41617516 100644 (file)
@@ -2,7 +2,7 @@
  * Handles the data to create and edit a poll in a form created via form builder.
  * 
  * @author     Alexander Ebert, Matthias Schmidt
- * @copyright  2001-2019 WoltLab GmbH
+ * @copyright  2001-2020 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module     WoltLabSuite/Core/Ui/Poll/Editor
  * @since      5.2
@@ -318,27 +318,8 @@ define([
                 * @param       {Event?}        event   form submit event
                 */
                _submit: function(event) {
-                       var options = [];
-                       for (var i = 0, length = this.optionList.children.length; i < length; i++) {
-                               var listItem = this.optionList.children[i];
-                               var optionValue = elBySel('input[type=text]', listItem).value.trim();
-                               
-                               if (optionValue !== '') {
-                                       options.push(elData(listItem, 'option-id') + '_' + optionValue);
-                               }
-                       }
-                       
                        if (this._options.isAjax) {
-                               event.poll = {};
-                               
-                               event.poll[this.questionField.id] = this.questionField.value;
-                               event.poll[this._wysiwygId + 'Poll_options'] = options;
-                               event.poll[this.endTimeField.id] = this.endTimeField.value;
-                               event.poll[this.maxVotesField.id] = this.maxVotesField.value;
-                               event.poll[this.isChangeableYesField.id] = !!this.isChangeableYesField.checked;
-                               event.poll[this.isPublicYesField.id] = !!this.isPublicYesField.checked;
-                               event.poll[this.resultsRequireVoteYesField.id] = !!this.resultsRequireVoteYesField.checked;
-                               event.poll[this.sortByVotesYesField.id] = !!this.sortByVotesYesField.checked;
+                               event.poll = this.getData();
                                
                                EventHandler.fire(
                                        'com.woltlab.wcf.poll.editor',
@@ -352,6 +333,7 @@ define([
                        else {
                                var form = this._container.closest('form');
                                
+                               var options = this.getOptions();
                                for (var i = 0, length = options.length; i < length; i++) {
                                        var input = elCreate('input');
                                        elAttr(input, 'type', 'hidden');
@@ -402,6 +384,45 @@ define([
                                        );
                                }
                        }
+               },
+               
+               /**
+                * Returns all poll data.
+                *
+                * @return      {object}
+                */
+               getData: function() {
+                       var data = {};
+                       
+                       data[this.questionField.id] = this.questionField.value;
+                       data[this._wysiwygId + 'Poll_options'] = this.getOptions();
+                       data[this.endTimeField.id] = this.endTimeField.value;
+                       data[this.maxVotesField.id] = this.maxVotesField.value;
+                       data[this.isChangeableYesField.id] = !!this.isChangeableYesField.checked;
+                       data[this.isPublicYesField.id] = !!this.isPublicYesField.checked;
+                       data[this.resultsRequireVoteYesField.id] = !!this.resultsRequireVoteYesField.checked;
+                       data[this.sortByVotesYesField.id] = !!this.sortByVotesYesField.checked;
+                       
+                       return data;
+               },
+               
+               /**
+                * Returns all entered poll options.
+                *
+                * @return      {string[]}
+                */
+               getOptions: function() {
+                       var options = [];
+                       for (var i = 0, length = this.optionList.children.length; i < length; i++) {
+                               var listItem = this.optionList.children[i];
+                               var optionValue = elBySel('input[type=text]', listItem).value.trim();
+                               
+                               if (optionValue !== '') {
+                                       options.push(elData(listItem, 'option-id') + '_' + optionValue);
+                               }
+                       }
+                       
+                       return options;
                }
        };