From a5f67c311d452f633a8513b1cc640e23ea300580 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Wed, 17 Jan 2024 11:51:02 +0100 Subject: [PATCH] Fix poll editor - Remove unused variables - Changes the element-ID to what was defined in template `__messageFormPollInline` --- ts/WoltLabSuite/Core/Ui/Poll/Editor.ts | 41 +++++++---------- .../js/WoltLabSuite/Core/Ui/Poll/Editor.js | 44 +++++++------------ 2 files changed, 32 insertions(+), 53 deletions(-) diff --git a/ts/WoltLabSuite/Core/Ui/Poll/Editor.ts b/ts/WoltLabSuite/Core/Ui/Poll/Editor.ts index 993b88b569..c59dcf7f56 100644 --- a/ts/WoltLabSuite/Core/Ui/Poll/Editor.ts +++ b/ts/WoltLabSuite/Core/Ui/Poll/Editor.ts @@ -57,10 +57,8 @@ type PollData = { class UiPollEditor { private readonly container: HTMLElement; private readonly endTimeField: HTMLInputElement; - private readonly isChangeableNoField: HTMLInputElement | null; private readonly isChangeableYesField: HTMLInputElement; - private readonly isPublicNoField: HTMLInputElement | null; - private readonly isPublicYesField: HTMLInputElement; + private readonly isPublicField: HTMLInputElement; private readonly maxVotesField: HTMLInputElement; private optionCount: number; private readonly options: UiPollEditorOptions; @@ -68,8 +66,7 @@ class UiPollEditor { private readonly questionField: HTMLInputElement; private readonly resultsRequireVoteNoField: HTMLInputElement | null; private readonly resultsRequireVoteYesField: HTMLInputElement; - private readonly sortByVotesNoField: HTMLInputElement | null; - private readonly sortByVotesYesField: HTMLInputElement; + private readonly sortByVotesField: HTMLInputElement; private readonly wysiwygId: string; constructor(containerId: string, pollOptions: PollOption[], wysiwygId: string, options: UiPollEditorOptions) { @@ -84,7 +81,7 @@ class UiPollEditor { throw new Error("Unknown wysiwyg field with id '" + wysiwygId + "'."); } - this.questionField = document.getElementById(this.wysiwygId + "pollQuestion") as HTMLInputElement; + this.questionField = document.getElementById(this.wysiwygId + "Poll_question") as HTMLInputElement; const optionList = this.container.querySelector(".sortableList"); if (optionList === null) { @@ -92,20 +89,17 @@ class UiPollEditor { } this.optionList = optionList as HTMLOListElement; - this.endTimeField = document.getElementById(this.wysiwygId + "pollEndTime") as HTMLInputElement; - this.maxVotesField = document.getElementById(this.wysiwygId + "pollMaxVotes") as HTMLInputElement; - this.isChangeableYesField = document.getElementById(this.wysiwygId + "pollIsChangeable") as HTMLInputElement; - this.isChangeableNoField = document.getElementById(this.wysiwygId + "pollIsChangeable_no") as HTMLInputElement; - this.isPublicYesField = document.getElementById(this.wysiwygId + "pollIsPublic") as HTMLInputElement; - this.isPublicNoField = document.getElementById(this.wysiwygId + "PollIsPublic_no") as HTMLInputElement; + this.endTimeField = document.getElementById(this.wysiwygId + "Poll_endTime") as HTMLInputElement; + this.maxVotesField = document.getElementById(this.wysiwygId + "Poll_maxVotes") as HTMLInputElement; + this.isChangeableYesField = document.getElementById(this.wysiwygId + "Poll_isChangeable") as HTMLInputElement; + this.isPublicField = document.getElementById(this.wysiwygId + "Poll_isPublic") as HTMLInputElement; this.resultsRequireVoteYesField = document.getElementById( - this.wysiwygId + "pollResultsRequireVote", + this.wysiwygId + "Poll_resultsRequireVote", ) as HTMLInputElement; this.resultsRequireVoteNoField = document.getElementById( - this.wysiwygId + "pollResultsRequireVote_no", + this.wysiwygId + "Poll_resultsRequireVote_no", ) as HTMLInputElement; - this.sortByVotesYesField = document.getElementById(this.wysiwygId + "pollSortByVotes") as HTMLInputElement; - this.sortByVotesNoField = document.getElementById(this.wysiwygId + "pollSortByVotes_no") as HTMLInputElement; + this.sortByVotesField = document.getElementById(this.wysiwygId + "Poll_sortByVotes") as HTMLInputElement; this.optionCount = 0; @@ -305,13 +299,10 @@ class UiPollEditor { this.maxVotesField.value = "1"; this.isChangeableYesField.checked = false; - if (this.isChangeableNoField) this.isChangeableNoField.checked = true; - this.isPublicYesField.checked = false; - if (this.isPublicNoField) this.isPublicNoField.checked = true; + this.isPublicField.checked = false; this.resultsRequireVoteYesField.checked = false; if (this.resultsRequireVoteNoField) this.resultsRequireVoteNoField.checked = true; - this.sortByVotesYesField.checked = false; - if (this.sortByVotesNoField) this.sortByVotesNoField.checked = true; + this.sortByVotesField.checked = false; EventHandler.fire("com.woltlab.wcf.poll.editor", "reset", { pollEditor: this, @@ -356,11 +347,11 @@ class UiPollEditor { data.pollResultsRequireVote = true; } - if (this.sortByVotesYesField.checked) { + if (this.sortByVotesField.checked) { data.pollSortByVotes = true; } - if (this.isPublicYesField?.checked) { + if (this.isPublicField?.checked) { data.pollIsPublic = true; } @@ -414,9 +405,9 @@ class UiPollEditor { [this.endTimeField.id]: this.endTimeField.value, [this.maxVotesField.id]: this.maxVotesField.value, [this.isChangeableYesField.id]: !!this.isChangeableYesField.checked, - [this.isPublicYesField.id]: !!this.isPublicYesField.checked, + [this.isPublicField.id]: !!this.isPublicField.checked, [this.resultsRequireVoteYesField.id]: !!this.resultsRequireVoteYesField.checked, - [this.sortByVotesYesField.id]: !!this.sortByVotesYesField.checked, + [this.sortByVotesField.id]: !!this.sortByVotesField.checked, }; } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Poll/Editor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Poll/Editor.js index 56a4f8d6a3..0b11bff28c 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Poll/Editor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Poll/Editor.js @@ -16,10 +16,8 @@ define(["require", "exports", "tslib", "../../Core", "../../Language", "../Sorta class UiPollEditor { container; endTimeField; - isChangeableNoField; isChangeableYesField; - isPublicNoField; - isPublicYesField; + isPublicField; maxVotesField; optionCount; options; @@ -27,8 +25,7 @@ define(["require", "exports", "tslib", "../../Core", "../../Language", "../Sorta questionField; resultsRequireVoteNoField; resultsRequireVoteYesField; - sortByVotesNoField; - sortByVotesYesField; + sortByVotesField; wysiwygId; constructor(containerId, pollOptions, wysiwygId, options) { const container = document.getElementById(containerId); @@ -40,22 +37,19 @@ define(["require", "exports", "tslib", "../../Core", "../../Language", "../Sorta if (wysiwygId !== "" && document.getElementById(wysiwygId) === null) { throw new Error("Unknown wysiwyg field with id '" + wysiwygId + "'."); } - this.questionField = document.getElementById(this.wysiwygId + "pollQuestion"); + this.questionField = document.getElementById(this.wysiwygId + "Poll_question"); const optionList = this.container.querySelector(".sortableList"); if (optionList === null) { throw new Error("Cannot find poll options list for container with id '" + containerId + "'."); } this.optionList = optionList; - this.endTimeField = document.getElementById(this.wysiwygId + "pollEndTime"); - this.maxVotesField = document.getElementById(this.wysiwygId + "pollMaxVotes"); - this.isChangeableYesField = document.getElementById(this.wysiwygId + "pollIsChangeable"); - this.isChangeableNoField = document.getElementById(this.wysiwygId + "pollIsChangeable_no"); - this.isPublicYesField = document.getElementById(this.wysiwygId + "pollIsPublic"); - this.isPublicNoField = document.getElementById(this.wysiwygId + "PollIsPublic_no"); - this.resultsRequireVoteYesField = document.getElementById(this.wysiwygId + "pollResultsRequireVote"); - this.resultsRequireVoteNoField = document.getElementById(this.wysiwygId + "pollResultsRequireVote_no"); - this.sortByVotesYesField = document.getElementById(this.wysiwygId + "pollSortByVotes"); - this.sortByVotesNoField = document.getElementById(this.wysiwygId + "pollSortByVotes_no"); + this.endTimeField = document.getElementById(this.wysiwygId + "Poll_endTime"); + this.maxVotesField = document.getElementById(this.wysiwygId + "Poll_maxVotes"); + this.isChangeableYesField = document.getElementById(this.wysiwygId + "Poll_isChangeable"); + this.isPublicField = document.getElementById(this.wysiwygId + "Poll_isPublic"); + this.resultsRequireVoteYesField = document.getElementById(this.wysiwygId + "Poll_resultsRequireVote"); + this.resultsRequireVoteNoField = document.getElementById(this.wysiwygId + "Poll_resultsRequireVote_no"); + this.sortByVotesField = document.getElementById(this.wysiwygId + "Poll_sortByVotes"); this.optionCount = 0; this.options = Core.extend({ isAjax: false, @@ -219,17 +213,11 @@ define(["require", "exports", "tslib", "../../Core", "../../Language", "../Sorta DatePicker.clear(this.endTimeField); this.maxVotesField.value = "1"; this.isChangeableYesField.checked = false; - if (this.isChangeableNoField) - this.isChangeableNoField.checked = true; - this.isPublicYesField.checked = false; - if (this.isPublicNoField) - this.isPublicNoField.checked = true; + this.isPublicField.checked = false; this.resultsRequireVoteYesField.checked = false; if (this.resultsRequireVoteNoField) this.resultsRequireVoteNoField.checked = true; - this.sortByVotesYesField.checked = false; - if (this.sortByVotesNoField) - this.sortByVotesNoField.checked = true; + this.sortByVotesField.checked = false; EventHandler.fire("com.woltlab.wcf.poll.editor", "reset", { pollEditor: this, }); @@ -268,10 +256,10 @@ define(["require", "exports", "tslib", "../../Core", "../../Language", "../Sorta if (this.resultsRequireVoteYesField.checked) { data.pollResultsRequireVote = true; } - if (this.sortByVotesYesField.checked) { + if (this.sortByVotesField.checked) { data.pollSortByVotes = true; } - if (this.isPublicYesField?.checked) { + if (this.isPublicField?.checked) { data.pollIsPublic = true; } data.pollOptions = this.getOptions(); @@ -320,9 +308,9 @@ define(["require", "exports", "tslib", "../../Core", "../../Language", "../Sorta [this.endTimeField.id]: this.endTimeField.value, [this.maxVotesField.id]: this.maxVotesField.value, [this.isChangeableYesField.id]: !!this.isChangeableYesField.checked, - [this.isPublicYesField.id]: !!this.isPublicYesField.checked, + [this.isPublicField.id]: !!this.isPublicField.checked, [this.resultsRequireVoteYesField.id]: !!this.resultsRequireVoteYesField.checked, - [this.sortByVotesYesField.id]: !!this.sortByVotesYesField.checked, + [this.sortByVotesField.id]: !!this.sortByVotesField.checked, }; } /** -- 2.20.1