// ajax
className: elData(button, 'class-name'),
- loopCount: -1,
- parameters: { },
// callbacks
callbackAbort: null,
- callbackFailure: null,
- callbackSuccess: function() {
+ callbackSuccess: () => {
{if $convertEncoding}
var span = button.nextElementSibling;
if (span && span.nodeName === 'SPAN') elRemove(span);
/**
* Worker manager with support for custom callbacks and loop counts.
*
- * @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module WoltLabSuite/Core/Acp/Ui/Worker
+ * @author Alexander Ebert
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Acp/Ui/Worker
*/
-define(['Ajax', 'Core', 'Language', 'Ui/Dialog'], function (Ajax, Core, Language, UiDialog) {
+define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Language", "../../Ui/Dialog"], function (require, exports, tslib_1, Ajax, Core, Language, Dialog_1) {
"use strict";
- /**
- * Creates a new worker instance.
- *
- * @param {Object} options configuration options
- * @constructor
- */
- function AcpUiWorker(options) { this.init(options); }
- AcpUiWorker.prototype = {
+ Ajax = tslib_1.__importStar(Ajax);
+ Core = tslib_1.__importStar(Core);
+ Language = tslib_1.__importStar(Language);
+ Dialog_1 = tslib_1.__importDefault(Dialog_1);
+ class AcpUiWorker {
/**
* Creates a new worker instance.
- *
- * @param {Object} options configuration options
*/
- init: function (options) {
- this._aborted = false;
- this._options = Core.extend({
+ constructor(options) {
+ this.aborted = false;
+ this.options = Core.extend({
// dialog
- dialogId: '',
- dialogTitle: '',
+ dialogId: "",
+ dialogTitle: "",
// ajax
- className: '',
+ className: "",
loopCount: -1,
parameters: {},
// callbacks
callbackAbort: null,
- callbackFailure: null,
- callbackSuccess: null
+ callbackSuccess: null,
}, options);
- this._options.dialogId += 'Worker';
+ this.options.dialogId += "Worker";
// update title
- if (UiDialog.getDialog(this._options.dialogId) !== undefined) {
- UiDialog.setTitle(this._options.dialogId, this._options.dialogTitle);
+ if (Dialog_1.default.getDialog(this.options.dialogId) !== undefined) {
+ Dialog_1.default.setTitle(this.options.dialogId, this.options.dialogTitle);
}
- this._request = Ajax.api(this);
- },
- _ajaxSuccess: function (data) {
- if (this._aborted)
+ this.request = Ajax.api(this);
+ }
+ _ajaxSuccess(data) {
+ if (this.aborted) {
return;
- if (typeof data.template === 'string') {
- UiDialog.open(this, data.template);
}
- var content = UiDialog.getDialog(this).content;
+ if (typeof data.template === "string") {
+ Dialog_1.default.open(this, data.template);
+ }
+ const content = Dialog_1.default.getDialog(this).content;
// update progress
- var progress = elBySel('progress', content);
+ const progress = content.querySelector("progress");
progress.value = data.progress;
- progress.nextElementSibling.textContent = data.progress + '%';
+ progress.nextElementSibling.textContent = `${data.progress}%`;
// worker is still busy
if (data.progress < 100) {
Ajax.api(this, {
loopCount: data.loopCount,
- parameters: data.parameters
+ parameters: data.parameters,
});
}
else {
- var spinner = elBySel('.fa-spinner', content);
- spinner.classList.remove('fa-spinner');
- spinner.classList.add('fa-check');
- spinner.classList.add('green');
- var formSubmit = elCreate('div');
- formSubmit.className = 'formSubmit';
- formSubmit.innerHTML = '<button class="buttonPrimary">' + Language.get('wcf.global.button.next') + '</button>';
+ const spinner = content.querySelector(".fa-spinner");
+ spinner.classList.remove("fa-spinner");
+ spinner.classList.add("fa-check", "green");
+ const formSubmit = document.createElement("div");
+ formSubmit.className = "formSubmit";
+ formSubmit.innerHTML = '<button class="buttonPrimary">' + Language.get("wcf.global.button.next") + "</button>";
content.appendChild(formSubmit);
- UiDialog.rebuild(this);
- var button = formSubmit.children[0];
- button.addEventListener('click', (function (event) {
+ Dialog_1.default.rebuild(this);
+ const button = formSubmit.children[0];
+ button.addEventListener("click", (event) => {
event.preventDefault();
- if (typeof this._options.callbackSuccess === 'function') {
- this._options.callbackSuccess(data);
- UiDialog.close(this);
+ if (typeof this.options.callbackSuccess === "function") {
+ this.options.callbackSuccess(data);
+ Dialog_1.default.close(this);
}
else {
- window.location = data.proceedURL;
+ window.location.href = data.proceedURL;
}
- }).bind(this));
+ });
button.focus();
}
- },
- _ajaxFailure: function () {
- var dialog = UiDialog.getDialog(this);
+ }
+ _ajaxFailure() {
+ const dialog = Dialog_1.default.getDialog(this);
if (dialog !== undefined) {
- var spinner = elBySel('.fa-spinner', dialog.content);
- spinner.classList.remove('fa-spinner');
- spinner.classList.add('fa-times');
- spinner.classList.add('red');
+ const spinner = dialog.content.querySelector(".fa-spinner");
+ spinner.classList.remove("fa-spinner");
+ spinner.classList.add("fa-times", "red");
}
- },
- _ajaxSetup: function () {
+ return true;
+ }
+ _ajaxSetup() {
return {
data: {
- className: this._options.className,
- loopCount: this._options.loopCount,
- parameters: this._options.parameters
+ className: this.options.className,
+ loopCount: this.options.loopCount,
+ parameters: this.options.parameters,
},
silent: true,
- url: 'index.php?worker-proxy/&t=' + SECURITY_TOKEN
+ url: "index.php?worker-proxy/&t=" + window.SECURITY_TOKEN,
};
- },
- _dialogSetup: function () {
+ }
+ _dialogSetup() {
return {
- id: this._options.dialogId,
- onClose: (function () {
- this._aborted = true;
- this._request.abortPrevious();
- if (typeof this._options.callbackAbort === 'function') {
- this._options.callbackAbort();
- }
- else {
- window.location.reload();
- }
- }).bind(this),
+ id: this.options.dialogId,
options: {
backdropCloseOnClick: false,
- title: this._options.dialogTitle
+ onClose: () => {
+ this.aborted = true;
+ this.request.abortPrevious();
+ if (typeof this.options.callbackAbort === "function") {
+ this.options.callbackAbort();
+ }
+ else {
+ window.location.reload();
+ }
+ },
+ title: this.options.dialogTitle,
},
- source: null
+ source: null,
};
}
- };
+ }
+ Core.enableLegacyInheritance(AcpUiWorker);
return AcpUiWorker;
});
/**
* Rebuilds dialog identified by given id.
*/
- rebuild(id) {
- id = this._getDialogId(id);
+ rebuild(elementId) {
+ const id = this._getDialogId(elementId);
const data = _dialogs.get(id);
if (data === undefined) {
throw new Error("Expected a valid dialog id, '" + id + "' does not match any active dialog.");
+++ /dev/null
-/**
- * Worker manager with support for custom callbacks and loop counts.
- *
- * @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module WoltLabSuite/Core/Acp/Ui/Worker
- */
-define(['Ajax', 'Core', 'Language', 'Ui/Dialog'], function(Ajax, Core, Language, UiDialog) {
- "use strict";
-
- /**
- * Creates a new worker instance.
- *
- * @param {Object} options configuration options
- * @constructor
- */
- function AcpUiWorker(options) { this.init(options); }
- AcpUiWorker.prototype = {
- /**
- * Creates a new worker instance.
- *
- * @param {Object} options configuration options
- */
- init: function (options) {
- this._aborted = false;
- this._options = Core.extend({
- // dialog
- dialogId: '',
- dialogTitle: '',
-
- // ajax
- className: '',
- loopCount: -1,
- parameters: {},
-
- // callbacks
- callbackAbort: null,
- callbackFailure: null,
- callbackSuccess: null
- }, options);
- this._options.dialogId += 'Worker';
-
- // update title
- if (UiDialog.getDialog(this._options.dialogId) !== undefined) {
- UiDialog.setTitle(this._options.dialogId, this._options.dialogTitle);
- }
-
- this._request = Ajax.api(this);
- },
-
- _ajaxSuccess: function (data) {
- if (this._aborted) return;
-
- if (typeof data.template === 'string') {
- UiDialog.open(this, data.template);
- }
-
- var content = UiDialog.getDialog(this).content;
-
- // update progress
- var progress = elBySel('progress', content);
- progress.value = data.progress;
- progress.nextElementSibling.textContent = data.progress + '%';
-
- // worker is still busy
- if (data.progress < 100) {
- Ajax.api(this, {
- loopCount: data.loopCount,
- parameters: data.parameters
- });
- }
- else {
- var spinner = elBySel('.fa-spinner', content);
- spinner.classList.remove('fa-spinner');
- spinner.classList.add('fa-check');
- spinner.classList.add('green');
-
- var formSubmit = elCreate('div');
- formSubmit.className = 'formSubmit';
- formSubmit.innerHTML = '<button class="buttonPrimary">' + Language.get('wcf.global.button.next') + '</button>';
-
- content.appendChild(formSubmit);
- UiDialog.rebuild(this);
-
- var button = formSubmit.children[0];
- button.addEventListener('click', (function(event) {
- event.preventDefault();
-
- if (typeof this._options.callbackSuccess === 'function') {
- this._options.callbackSuccess(data);
-
- UiDialog.close(this);
- }
- else {
- window.location = data.proceedURL;
- }
- }).bind(this));
- button.focus();
- }
- },
-
- _ajaxFailure: function () {
- var dialog = UiDialog.getDialog(this);
- if (dialog !== undefined) {
- var spinner = elBySel('.fa-spinner', dialog.content);
- spinner.classList.remove('fa-spinner');
- spinner.classList.add('fa-times');
- spinner.classList.add('red');
- }
- },
-
- _ajaxSetup: function () {
- return {
- data: {
- className: this._options.className,
- loopCount: this._options.loopCount,
- parameters: this._options.parameters
- },
- silent: true,
- url: 'index.php?worker-proxy/&t=' + SECURITY_TOKEN
- };
- },
-
- _dialogSetup: function () {
- return {
- id: this._options.dialogId,
- onClose: (function () {
- this._aborted = true;
- this._request.abortPrevious();
-
- if (typeof this._options.callbackAbort === 'function') {
- this._options.callbackAbort();
- }
- else {
- window.location.reload();
- }
- }).bind(this),
- options: {
- backdropCloseOnClick: false,
- title: this._options.dialogTitle
- },
- source: null
- }
- }
- };
-
- return AcpUiWorker;
-});
--- /dev/null
+/**
+ * Worker manager with support for custom callbacks and loop counts.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Acp/Ui/Worker
+ */
+
+import * as Ajax from "../../Ajax";
+import * as Core from "../../Core";
+import * as Language from "../../Language";
+import UiDialog from "../../Ui/Dialog";
+import { AjaxCallbackObject, AjaxCallbackSetup } from "../../Ajax/Data";
+import { DialogCallbackObject, DialogCallbackSetup } from "../../Ui/Dialog/Data";
+import AjaxRequest from "../../Ajax/Request";
+
+interface AjaxResponse {
+ loopCount: number;
+ parameters: ArbitraryObject;
+ proceedURL: string;
+ progress: number;
+ template?: string;
+}
+
+type CallbackAbort = () => void;
+type CallbackSuccess = (data: AjaxResponse) => void;
+
+interface WorkerOptions {
+ // dialog
+ dialogId: string;
+ dialogTitle: string;
+
+ // ajax
+ className: string;
+ loopCount: number;
+ parameters: ArbitraryObject;
+
+ // callbacks
+ callbackAbort: CallbackAbort | null;
+ callbackSuccess: CallbackSuccess | null;
+}
+
+class AcpUiWorker implements AjaxCallbackObject, DialogCallbackObject {
+ private aborted = false;
+ private readonly options: WorkerOptions;
+ private readonly request: AjaxRequest;
+
+ /**
+ * Creates a new worker instance.
+ */
+ constructor(options: Partial<WorkerOptions>) {
+ this.options = Core.extend(
+ {
+ // dialog
+ dialogId: "",
+ dialogTitle: "",
+
+ // ajax
+ className: "",
+ loopCount: -1,
+ parameters: {},
+
+ // callbacks
+ callbackAbort: null,
+ callbackSuccess: null,
+ },
+ options,
+ ) as WorkerOptions;
+ this.options.dialogId += "Worker";
+
+ // update title
+ if (UiDialog.getDialog(this.options.dialogId) !== undefined) {
+ UiDialog.setTitle(this.options.dialogId, this.options.dialogTitle);
+ }
+
+ this.request = Ajax.api(this);
+ }
+
+ _ajaxSuccess(data: AjaxResponse): void {
+ if (this.aborted) {
+ return;
+ }
+
+ if (typeof data.template === "string") {
+ UiDialog.open(this, data.template);
+ }
+
+ const content = UiDialog.getDialog(this)!.content;
+
+ // update progress
+ const progress = content.querySelector("progress")!;
+ progress.value = data.progress;
+ progress.nextElementSibling!.textContent = `${data.progress}%`;
+
+ // worker is still busy
+ if (data.progress < 100) {
+ Ajax.api(this, {
+ loopCount: data.loopCount,
+ parameters: data.parameters,
+ });
+ } else {
+ const spinner = content.querySelector(".fa-spinner") as HTMLSpanElement;
+ spinner.classList.remove("fa-spinner");
+ spinner.classList.add("fa-check", "green");
+
+ const formSubmit = document.createElement("div");
+ formSubmit.className = "formSubmit";
+ formSubmit.innerHTML = '<button class="buttonPrimary">' + Language.get("wcf.global.button.next") + "</button>";
+
+ content.appendChild(formSubmit);
+ UiDialog.rebuild(this);
+
+ const button = formSubmit.children[0] as HTMLButtonElement;
+ button.addEventListener("click", (event) => {
+ event.preventDefault();
+
+ if (typeof this.options.callbackSuccess === "function") {
+ this.options.callbackSuccess(data);
+
+ UiDialog.close(this);
+ } else {
+ window.location.href = data.proceedURL;
+ }
+ });
+ button.focus();
+ }
+ }
+
+ _ajaxFailure(): boolean {
+ const dialog = UiDialog.getDialog(this);
+ if (dialog !== undefined) {
+ const spinner = dialog.content.querySelector(".fa-spinner") as HTMLSpanElement;
+ spinner.classList.remove("fa-spinner");
+ spinner.classList.add("fa-times", "red");
+ }
+
+ return true;
+ }
+
+ _ajaxSetup(): ReturnType<AjaxCallbackSetup> {
+ return {
+ data: {
+ className: this.options.className,
+ loopCount: this.options.loopCount,
+ parameters: this.options.parameters,
+ },
+ silent: true,
+ url: "index.php?worker-proxy/&t=" + window.SECURITY_TOKEN,
+ };
+ }
+
+ _dialogSetup(): ReturnType<DialogCallbackSetup> {
+ return {
+ id: this.options.dialogId,
+ options: {
+ backdropCloseOnClick: false,
+ onClose: () => {
+ this.aborted = true;
+ this.request.abortPrevious();
+
+ if (typeof this.options.callbackAbort === "function") {
+ this.options.callbackAbort();
+ } else {
+ window.location.reload();
+ }
+ },
+ title: this.options.dialogTitle,
+ },
+ source: null,
+ };
+ }
+}
+
+Core.enableLegacyInheritance(AcpUiWorker);
+
+export = AcpUiWorker;
/**
* Rebuilds dialog identified by given id.
*/
- rebuild(id: string): void {
- id = this._getDialogId(id);
+ rebuild(elementId: ElementIdOrCallbackObject): void {
+ const id = this._getDialogId(elementId);
const data = _dialogs.get(id);
if (data === undefined) {