* @since 5.5
*/
-import { DialogCallbackSetup } from "../../../../../Ui/Dialog/Data";
-import * as Language from "../../../../../Language";
import * as Ajax from "../../../../../Ajax";
-import UiDialog from "../../../../../Ui/Dialog";
+import BanDialog from "./Dialog/Ban";
export class BanHandler {
private userIDs: number[];
}
public ban(callback: () => void): void {
- // Save the callback for later usage.
- // We cannot easily give the callback to the dialog.
- this.banCallback = callback;
-
- UiDialog.open(this);
+ BanDialog.open(this.userIDs, callback);
}
public unban(callback: () => void): void {
_ajaxSuccess: callback,
});
}
-
- private banSubmit(reason: string, userBanExpires: string): void {
- Ajax.api({
- _ajaxSetup: () => {
- return {
- data: {
- actionName: "ban",
- className: "wcf\\data\\user\\UserAction",
- objectIDs: this.userIDs,
- parameters: {
- banReason: reason,
- banExpires: userBanExpires,
- },
- },
- };
- },
- _ajaxSuccess: this.banCallback,
- });
- }
-
- _dialogSetup(): ReturnType<DialogCallbackSetup> {
- return {
- id: "userBanHandler",
- options: {
- onSetup: (content: HTMLElement): void => {
- const submit = content.querySelector(".formSubmitButton")! as HTMLElement;
- const neverExpires = content.querySelector("#userBanNeverExpires")! as HTMLInputElement;
- const userBanExpiresSettings = content.querySelector("#userBanExpiresSettings")! as HTMLElement;
-
- submit.addEventListener("click", (event) => {
- event.preventDefault();
-
- const reason = content.querySelector("#userBanReason")! as HTMLInputElement;
- const neverExpires = content.querySelector("#userBanNeverExpires")! as HTMLInputElement;
- const userBanExpires = content.querySelector("#userBanExpiresDatePicker")! as HTMLInputElement;
-
- this.banSubmit(reason.value, neverExpires.checked ? "" : userBanExpires.value);
-
- UiDialog.close(this);
-
- reason.value = "";
- neverExpires.checked = true;
- // @TODO empty userBanExpires
- userBanExpiresSettings.style.setProperty("display", "none", "");
- });
-
- neverExpires.addEventListener("change", (event) => {
- const checkbox = event.currentTarget as HTMLInputElement;
- if (checkbox.checked) {
- userBanExpiresSettings.style.setProperty("display", "none", "");
- } else {
- userBanExpiresSettings.style.removeProperty("display");
- }
- });
- },
- title: Language.get("wcf.acp.user.ban.sure"),
- },
- source: `<div class="section">
- <dl>
- <dt><label for="userBanReason">${Language.get("wcf.acp.user.banReason")}</label></dt>
- <dd>
- <textarea id="userBanReason" cols="40" rows="3" class=""></textarea>
- <small>${Language.get("wcf.acp.user.banReason.description")}</small>
- </dd>
- </dl>
- <dl>
- <dt></dt>
- <dd>
- <label for="userBanNeverExpires">
- <input type="checkbox" name="userBanNeverExpires" id="userBanNeverExpires" checked="">
- ${Language.get("wcf.acp.user.ban.neverExpires")}
- </label>
- </dd>
- </dl>
- <dl id="userBanExpiresSettings" style="display: none;">
- <dt>
- <label for="userBanExpires">${Language.get("wcf.acp.user.ban.expires")}</label>
- </dt>
- <dd>
- <div class="inputAddon">
- <input type="date"
- name="userBanExpires"
- id="userBanExpires"
- class="medium"
- min="${new Date(window.TIME_NOW * 1000).toISOString()}"
- data-ignore-timezone="true"
- />
- </div>
- <small>${Language.get("wcf.acp.user.ban.expires.description")}</small>
- </dd>
- </dl>
- </div>
- <div class="formSubmit dialogFormSubmit">
- <button class="buttonPrimary formSubmitButton" accesskey="s">${Language.get(
- "wcf.global.button.submit",
- )}</button>
- </div>`,
- };
- }
}
export default BanHandler;
--- /dev/null
+/**
+ * @author Joshua Ruesweg
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog
+ * @since 5.5
+ */
+
+import UiDialog from "../../../../../../Ui/Dialog";
+import { DialogCallbackSetup } from "../../../../../../Ui/Dialog/Data";
+import * as Language from "../../../../../../Language";
+import * as Ajax from "../../../../../../Ajax";
+import DatePicker from "../../../../../../Date/Picker";
+
+export class BanDialog {
+ private static instance: BanDialog;
+
+ private banCallback: () => void;
+ private userIDs: number[];
+ private submitElement: HTMLElement;
+ private neverExpiresCheckbox: HTMLInputElement;
+ private reasonInput: HTMLInputElement;
+ private userBanExpiresSettingsElement: HTMLElement;
+ private dialogContent: HTMLElement;
+ public static open(userIDs: number[], callback: () => void): void {
+ if (!BanDialog.instance) {
+ BanDialog.instance = new BanDialog();
+ }
+
+ BanDialog.instance.setCallback(callback);
+ BanDialog.instance.setUserIDs(userIDs);
+ BanDialog.instance.openDialog();
+ }
+
+ private openDialog(): void {
+ UiDialog.open(this);
+ }
+
+ private setCallback(callback: () => void): void {
+ this.banCallback = callback;
+ }
+
+ private setUserIDs(userIDs: number[]) {
+ this.userIDs = userIDs;
+ }
+
+ private banSubmit(reason: string, expires: string): void {
+ Ajax.apiOnce({
+ data: {
+ actionName: "ban",
+ className: "wcf\\data\\user\\UserAction",
+ objectIDs: this.userIDs,
+ parameters: {
+ banReason: reason,
+ banExpires: expires,
+ },
+ },
+ success: this.banCallback,
+ });
+ }
+
+ private cleanupDialog(): void {
+ this.reasonInput.value = "";
+ this.neverExpiresCheckbox.checked = true;
+ DatePicker.clear("userBanExpires");
+ this.userBanExpiresSettingsElement.style.setProperty("display", "none", "");
+ }
+
+ _dialogSetup(): ReturnType<DialogCallbackSetup> {
+ return {
+ id: "userBanHandler",
+ options: {
+ onSetup: (content: HTMLElement): void => {
+ this.dialogContent = content;
+ this.submitElement = content.querySelector(".formSubmitButton")! as HTMLElement;
+ this.reasonInput = content.querySelector("#userBanReason")! as HTMLInputElement;
+ this.neverExpiresCheckbox = content.querySelector("#userBanNeverExpires")! as HTMLInputElement;
+ this.userBanExpiresSettingsElement = content.querySelector("#userBanExpiresSettings")! as HTMLElement;
+
+ this.submitElement.addEventListener("click", (event) => {
+ event.preventDefault();
+
+ const expires = this.neverExpiresCheckbox.checked ? "" : DatePicker.getValue("userBanExpires");
+ this.banSubmit(this.reasonInput.value, expires);
+
+ UiDialog.close(this);
+
+ this.cleanupDialog();
+ });
+
+ this.neverExpiresCheckbox.addEventListener("change", (event) => {
+ const checkbox = event.currentTarget as HTMLInputElement;
+ if (checkbox.checked) {
+ this.userBanExpiresSettingsElement.style.setProperty("display", "none", "");
+ } else {
+ this.userBanExpiresSettingsElement.style.removeProperty("display");
+ }
+ });
+ },
+ title: Language.get("wcf.acp.user.ban.sure"),
+ },
+ source: `<div class="section">
+ <dl>
+ <dt><label for="userBanReason">${Language.get("wcf.acp.user.banReason")}</label></dt>
+ <dd>
+ <textarea id="userBanReason" cols="40" rows="3" class=""></textarea>
+ <small>${Language.get("wcf.acp.user.banReason.description")}</small>
+ </dd>
+ </dl>
+ <dl>
+ <dt></dt>
+ <dd>
+ <label for="userBanNeverExpires">
+ <input type="checkbox" name="userBanNeverExpires" id="userBanNeverExpires" checked="">
+ ${Language.get("wcf.acp.user.ban.neverExpires")}
+ </label>
+ </dd>
+ </dl>
+ <dl id="userBanExpiresSettings" style="display: none;">
+ <dt>
+ <label for="userBanExpires">${Language.get("wcf.acp.user.ban.expires")}</label>
+ </dt>
+ <dd>
+ <div class="inputAddon">
+ <input type="date"
+ name="userBanExpires"
+ id="userBanExpires"
+ class="medium"
+ min="${new Date(window.TIME_NOW * 1000).toISOString()}"
+ data-ignore-timezone="true"
+ />
+ </div>
+ <small>${Language.get("wcf.acp.user.ban.expires.description")}</small>
+ </dd>
+ </dl>
+ </div>
+ <div class="formSubmit dialogFormSubmit">
+ <button class="buttonPrimary formSubmitButton" accesskey="s">${Language.get(
+ "wcf.global.button.submit",
+ )}</button>
+ </div>`,
+ };
+ }
+}
+
+export default BanDialog;
* @module WoltLabSuite/Core/Acp/Ui/User/Action/Handler
* @since 5.5
*/
-define(["require", "exports", "tslib", "../../../../../Language", "../../../../../Ajax", "../../../../../Ui/Dialog"], function (require, exports, tslib_1, Language, Ajax, Dialog_1) {
+define(["require", "exports", "tslib", "../../../../../Ajax", "./Dialog/Ban"], function (require, exports, tslib_1, Ajax, Ban_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BanHandler = void 0;
- Language = tslib_1.__importStar(Language);
Ajax = tslib_1.__importStar(Ajax);
- Dialog_1 = tslib_1.__importDefault(Dialog_1);
+ Ban_1 = tslib_1.__importDefault(Ban_1);
class BanHandler {
constructor(userIDs) {
this.userIDs = userIDs;
}
ban(callback) {
- // Save the callback for later usage.
- // We cannot easily give the callback to the dialog.
- this.banCallback = callback;
- Dialog_1.default.open(this);
+ Ban_1.default.open(this.userIDs, callback);
}
unban(callback) {
Ajax.api({
_ajaxSuccess: callback,
});
}
- banSubmit(reason, userBanExpires) {
- Ajax.api({
- _ajaxSetup: () => {
- return {
- data: {
- actionName: "ban",
- className: "wcf\\data\\user\\UserAction",
- objectIDs: this.userIDs,
- parameters: {
- banReason: reason,
- banExpires: userBanExpires,
- },
- },
- };
- },
- _ajaxSuccess: this.banCallback,
- });
- }
- _dialogSetup() {
- return {
- id: "userBanHandler",
- options: {
- onSetup: (content) => {
- const submit = content.querySelector(".formSubmitButton");
- const neverExpires = content.querySelector("#userBanNeverExpires");
- const userBanExpiresSettings = content.querySelector("#userBanExpiresSettings");
- submit.addEventListener("click", (event) => {
- event.preventDefault();
- const reason = content.querySelector("#userBanReason");
- const neverExpires = content.querySelector("#userBanNeverExpires");
- const userBanExpires = content.querySelector("#userBanExpiresDatePicker");
- this.banSubmit(reason.value, neverExpires.checked ? "" : userBanExpires.value);
- Dialog_1.default.close(this);
- reason.value = "";
- neverExpires.checked = true;
- // @TODO empty userBanExpires
- userBanExpiresSettings.style.setProperty("display", "none", "");
- });
- neverExpires.addEventListener("change", (event) => {
- const checkbox = event.currentTarget;
- if (checkbox.checked) {
- userBanExpiresSettings.style.setProperty("display", "none", "");
- }
- else {
- userBanExpiresSettings.style.removeProperty("display");
- }
- });
- },
- title: Language.get("wcf.acp.user.ban.sure"),
- },
- source: `<div class="section">
- <dl>
- <dt><label for="userBanReason">${Language.get("wcf.acp.user.banReason")}</label></dt>
- <dd>
- <textarea id="userBanReason" cols="40" rows="3" class=""></textarea>
- <small>${Language.get("wcf.acp.user.banReason.description")}</small>
- </dd>
- </dl>
- <dl>
- <dt></dt>
- <dd>
- <label for="userBanNeverExpires">
- <input type="checkbox" name="userBanNeverExpires" id="userBanNeverExpires" checked="">
- ${Language.get("wcf.acp.user.ban.neverExpires")}
- </label>
- </dd>
- </dl>
- <dl id="userBanExpiresSettings" style="display: none;">
- <dt>
- <label for="userBanExpires">${Language.get("wcf.acp.user.ban.expires")}</label>
- </dt>
- <dd>
- <div class="inputAddon">
- <input type="date"
- name="userBanExpires"
- id="userBanExpires"
- class="medium"
- min="${new Date(window.TIME_NOW * 1000).toISOString()}"
- data-ignore-timezone="true"
- />
- </div>
- <small>${Language.get("wcf.acp.user.ban.expires.description")}</small>
- </dd>
- </dl>
- </div>
- <div class="formSubmit dialogFormSubmit">
- <button class="buttonPrimary formSubmitButton" accesskey="s">${Language.get("wcf.global.button.submit")}</button>
- </div>`,
- };
- }
}
exports.BanHandler = BanHandler;
exports.default = BanHandler;
--- /dev/null
+/**
+ * @author Joshua Ruesweg
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Acp/Ui/User/Action/Handler/Dialog
+ * @since 5.5
+ */
+define(["require", "exports", "tslib", "../../../../../../Ui/Dialog", "../../../../../../Language", "../../../../../../Ajax", "../../../../../../Date/Picker"], function (require, exports, tslib_1, Dialog_1, Language, Ajax, Picker_1) {
+ "use strict";
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.BanDialog = void 0;
+ Dialog_1 = tslib_1.__importDefault(Dialog_1);
+ Language = tslib_1.__importStar(Language);
+ Ajax = tslib_1.__importStar(Ajax);
+ Picker_1 = tslib_1.__importDefault(Picker_1);
+ class BanDialog {
+ static open(userIDs, callback) {
+ if (!BanDialog.instance) {
+ BanDialog.instance = new BanDialog();
+ }
+ BanDialog.instance.setCallback(callback);
+ BanDialog.instance.setUserIDs(userIDs);
+ BanDialog.instance.openDialog();
+ }
+ openDialog() {
+ Dialog_1.default.open(this);
+ }
+ setCallback(callback) {
+ this.banCallback = callback;
+ }
+ setUserIDs(userIDs) {
+ this.userIDs = userIDs;
+ }
+ banSubmit(reason, expires) {
+ Ajax.apiOnce({
+ data: {
+ actionName: "ban",
+ className: "wcf\\data\\user\\UserAction",
+ objectIDs: this.userIDs,
+ parameters: {
+ banReason: reason,
+ banExpires: expires,
+ },
+ },
+ success: this.banCallback,
+ });
+ }
+ cleanupDialog() {
+ this.reasonInput.value = "";
+ this.neverExpiresCheckbox.checked = true;
+ Picker_1.default.clear("userBanExpires");
+ this.userBanExpiresSettingsElement.style.setProperty("display", "none", "");
+ }
+ _dialogSetup() {
+ return {
+ id: "userBanHandler",
+ options: {
+ onSetup: (content) => {
+ this.dialogContent = content;
+ this.submitElement = content.querySelector(".formSubmitButton");
+ this.reasonInput = content.querySelector("#userBanReason");
+ this.neverExpiresCheckbox = content.querySelector("#userBanNeverExpires");
+ this.userBanExpiresSettingsElement = content.querySelector("#userBanExpiresSettings");
+ this.submitElement.addEventListener("click", (event) => {
+ event.preventDefault();
+ const expires = this.neverExpiresCheckbox.checked ? "" : Picker_1.default.getValue("userBanExpires");
+ this.banSubmit(this.reasonInput.value, expires);
+ Dialog_1.default.close(this);
+ this.cleanupDialog();
+ });
+ this.neverExpiresCheckbox.addEventListener("change", (event) => {
+ const checkbox = event.currentTarget;
+ if (checkbox.checked) {
+ this.userBanExpiresSettingsElement.style.setProperty("display", "none", "");
+ }
+ else {
+ this.userBanExpiresSettingsElement.style.removeProperty("display");
+ }
+ });
+ },
+ title: Language.get("wcf.acp.user.ban.sure"),
+ },
+ source: `<div class="section">
+ <dl>
+ <dt><label for="userBanReason">${Language.get("wcf.acp.user.banReason")}</label></dt>
+ <dd>
+ <textarea id="userBanReason" cols="40" rows="3" class=""></textarea>
+ <small>${Language.get("wcf.acp.user.banReason.description")}</small>
+ </dd>
+ </dl>
+ <dl>
+ <dt></dt>
+ <dd>
+ <label for="userBanNeverExpires">
+ <input type="checkbox" name="userBanNeverExpires" id="userBanNeverExpires" checked="">
+ ${Language.get("wcf.acp.user.ban.neverExpires")}
+ </label>
+ </dd>
+ </dl>
+ <dl id="userBanExpiresSettings" style="display: none;">
+ <dt>
+ <label for="userBanExpires">${Language.get("wcf.acp.user.ban.expires")}</label>
+ </dt>
+ <dd>
+ <div class="inputAddon">
+ <input type="date"
+ name="userBanExpires"
+ id="userBanExpires"
+ class="medium"
+ min="${new Date(window.TIME_NOW * 1000).toISOString()}"
+ data-ignore-timezone="true"
+ />
+ </div>
+ <small>${Language.get("wcf.acp.user.ban.expires.description")}</small>
+ </dd>
+ </dl>
+ </div>
+ <div class="formSubmit dialogFormSubmit">
+ <button class="buttonPrimary formSubmitButton" accesskey="s">${Language.get("wcf.global.button.submit")}</button>
+ </div>`,
+ };
+ }
+ }
+ exports.BanDialog = BanDialog;
+ exports.default = BanDialog;
+});