import * as EventHandler from "../../Event/Handler";
import * as DatePicker from "../../Date/Picker";
import { DatabaseObjectActionResponse } from "../../Ajax/Data";
+import { listenToCkeditor } from "../../Component/Ckeditor/Event";
interface UiPollEditorOptions {
isAjax: boolean;
valid: boolean;
}
+type PollData = {
+ pollEndTime: string;
+ pollIsChangeable?: boolean;
+ pollIsPublic?: boolean;
+ pollMaxVotes: number;
+ pollOptions: string[];
+ pollQuestion: string;
+ pollResultsRequireVote?: true;
+ pollSortByVotes?: boolean;
+};
+
class UiPollEditor {
private readonly container: HTMLElement;
private readonly endTimeField: HTMLInputElement;
this.reset();
});
+ listenToCkeditor(element).collectMetaData((payload) => {
+ payload.metaData.poll = this.#getPollData();
+ });
+
["handleError", "submit", "validate"].forEach((event) => {
EventHandler.add("com.woltlab.wcf.ckeditor5", event + "_" + this.wysiwygId, (...args: unknown[]) =>
this[event](...args),
}
}
+ #getPollData(): PollData {
+ const data: PollData = {
+ pollEndTime: DatePicker.getValue(this.endTimeField),
+ pollMaxVotes: parseInt(this.maxVotesField.value) || 0,
+ pollQuestion: this.questionField.value,
+ pollOptions: [],
+ };
+
+ if (this.isChangeableYesField.checked) {
+ data.pollIsChangeable = true;
+ }
+
+ if (this.resultsRequireVoteYesField.checked) {
+ data.pollResultsRequireVote = true;
+ }
+
+ if (this.sortByVotesYesField.checked) {
+ data.pollSortByVotes = true;
+ }
+
+ if (this.isPublicYesField?.checked) {
+ data.pollIsPublic = true;
+ }
+
+ data.pollOptions = this.getOptions();
+
+ return data;
+ }
+
/**
* Validates the poll data.
*/
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @woltlabExcludeBundle all
*/
-define(["require", "exports", "tslib", "../../Core", "../../Language", "../Sortable/List", "../../Event/Handler", "../../Date/Picker"], function (require, exports, tslib_1, Core, Language, List_1, EventHandler, DatePicker) {
+define(["require", "exports", "tslib", "../../Core", "../../Language", "../Sortable/List", "../../Event/Handler", "../../Date/Picker", "../../Component/Ckeditor/Event"], function (require, exports, tslib_1, Core, Language, List_1, EventHandler, DatePicker, Event_1) {
"use strict";
Core = tslib_1.__importStar(Core);
Language = tslib_1.__importStar(Language);
element.addEventListener("reset", () => {
this.reset();
});
+ (0, Event_1.listenToCkeditor)(element).collectMetaData((payload) => {
+ payload.metaData.poll = this.#getPollData();
+ });
["handleError", "submit", "validate"].forEach((event) => {
EventHandler.add("com.woltlab.wcf.ckeditor5", event + "_" + this.wysiwygId, (...args) => this[event](...args));
});
});
}
}
+ #getPollData() {
+ const data = {
+ pollEndTime: DatePicker.getValue(this.endTimeField),
+ pollMaxVotes: parseInt(this.maxVotesField.value) || 0,
+ pollQuestion: this.questionField.value,
+ pollOptions: [],
+ };
+ if (this.isChangeableYesField.checked) {
+ data.pollIsChangeable = true;
+ }
+ if (this.resultsRequireVoteYesField.checked) {
+ data.pollResultsRequireVote = true;
+ }
+ if (this.sortByVotesYesField.checked) {
+ data.pollSortByVotes = true;
+ }
+ if (this.isPublicYesField?.checked) {
+ data.pollIsPublic = true;
+ }
+ data.pollOptions = this.getOptions();
+ return data;
+ }
/**
* Validates the poll data.
*/