/**
* Object-based user list.
*
- * @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module WoltLabSuite/Core/Ui/User/List
+ * @author Alexander Ebert
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Ui/User/List
*/
-define(['Ajax', 'Core', 'Dictionary', 'Dom/Util', 'Ui/Dialog', 'WoltLabSuite/Core/Ui/Pagination'], function (Ajax, Core, Dictionary, DomUtil, UiDialog, UiPagination) {
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
+}) : function(o, v) {
+ o["default"] = v;
+});
+var __importStar = (this && this.__importStar) || function (mod) {
+ if (mod && mod.__esModule) return mod;
+ var result = {};
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
+ __setModuleDefault(result, mod);
+ return result;
+};
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+define(["require", "exports", "../../Ajax", "../../Core", "../../Dom/Util", "../Dialog", "../Pagination"], function (require, exports, Ajax, Core, Util_1, Dialog_1, Pagination_1) {
"use strict";
+ Ajax = __importStar(Ajax);
+ Core = __importStar(Core);
+ Util_1 = __importDefault(Util_1);
+ Dialog_1 = __importDefault(Dialog_1);
+ Pagination_1 = __importDefault(Pagination_1);
/**
* @constructor
*/
- function UiUserList(options) { this.init(options); }
- UiUserList.prototype = {
+ class UiUserList {
/**
* Initializes the user list.
*
- * @param {object} options list of initialization options
+ * @param {object} options list of initialization options
*/
- init: function (options) {
- this._cache = new Dictionary();
- this._pageCount = 0;
- this._pageNo = 1;
- this._options = Core.extend({
+ constructor(options) {
+ this.cache = new Map();
+ this.pageCount = 0;
+ this.pageNo = 1;
+ this.options = Core.extend({
className: '',
dialogTitle: '',
- parameters: {}
+ parameters: {},
}, options);
- },
+ }
/**
* Opens the user list.
*/
- open: function () {
- this._pageNo = 1;
- this._showPage();
- },
+ open() {
+ this.pageNo = 1;
+ this.showPage();
+ }
/**
* Shows the current or given page.
- *
- * @param {int=} pageNo page number
*/
- _showPage: function (pageNo) {
+ showPage(pageNo) {
if (typeof pageNo === 'number') {
- this._pageNo = ~~pageNo;
+ this.pageNo = +pageNo;
}
- if (this._pageCount !== 0 && (this._pageNo < 1 || this._pageNo > this._pageCount)) {
- throw new RangeError("pageNo must be between 1 and " + this._pageCount + " (" + this._pageNo + " given).");
+ if (this.pageCount !== 0 && (this.pageNo < 1 || this.pageNo > this.pageCount)) {
+ throw new RangeError("pageNo must be between 1 and " + this.pageCount + " (" + this.pageNo + " given).");
}
- if (this._cache.has(this._pageNo)) {
- var dialog = UiDialog.open(this, this._cache.get(this._pageNo));
- if (this._pageCount > 1) {
- var element = elBySel('.jsPagination', dialog.content);
+ if (this.cache.has(this.pageNo)) {
+ const dialog = Dialog_1.default.open(this, this.cache.get(this.pageNo));
+ if (this.pageCount > 1) {
+ const element = dialog.content.querySelector('.jsPagination');
if (element !== null) {
- new UiPagination(element, {
- activePage: this._pageNo,
- maxPage: this._pageCount,
- callbackSwitch: this._showPage.bind(this)
+ new Pagination_1.default(element, {
+ activePage: this.pageNo,
+ maxPage: this.pageCount,
+ callbackSwitch: this.showPage.bind(this),
});
}
// scroll to the list start
- var container = dialog.content.parentNode;
+ const container = dialog.content.parentElement;
if (container.scrollTop > 0) {
container.scrollTop = 0;
}
}
}
else {
- this._options.parameters.pageNo = this._pageNo;
+ this.options.parameters.pageNo = this.pageNo;
Ajax.api(this, {
- parameters: this._options.parameters
+ parameters: this.options.parameters,
});
}
- },
- _ajaxSuccess: function (data) {
+ }
+ _ajaxSuccess(data) {
if (data.returnValues.pageCount !== undefined) {
- this._pageCount = ~~data.returnValues.pageCount;
+ this.pageCount = ~~data.returnValues.pageCount;
}
- this._cache.set(this._pageNo, data.returnValues.template);
- this._showPage();
- },
- _ajaxSetup: function () {
+ this.cache.set(this.pageNo, data.returnValues.template);
+ this.showPage();
+ }
+ _ajaxSetup() {
return {
data: {
actionName: 'getGroupedUserList',
- className: this._options.className,
- interfaceName: 'wcf\\data\\IGroupedUserListAction'
- }
+ className: this.options.className,
+ interfaceName: 'wcf\\data\\IGroupedUserListAction',
+ },
};
- },
- _dialogSetup: function () {
+ }
+ _dialogSetup() {
return {
- id: DomUtil.getUniqueId(),
+ id: Util_1.default.getUniqueId(),
options: {
- title: this._options.dialogTitle
+ title: this.options.dialogTitle,
},
- source: null
+ source: null,
};
}
- };
+ }
return UiUserList;
});
activePage: number;
maxPage: number;
callbackShouldSwitch?: CallbackShouldSwitch | null,
- callbackSwitch?: CallbackShouldSwitch | null,
+ callbackSwitch?: CallbackSwitch | null,
}
+++ /dev/null
-/**
- * Object-based user list.
- *
- * @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module WoltLabSuite/Core/Ui/User/List
- */
-define(['Ajax', 'Core', 'Dictionary', 'Dom/Util', 'Ui/Dialog', 'WoltLabSuite/Core/Ui/Pagination'], function(Ajax, Core, Dictionary, DomUtil, UiDialog, UiPagination) {
- "use strict";
-
- /**
- * @constructor
- */
- function UiUserList(options) { this.init(options); }
- UiUserList.prototype = {
- /**
- * Initializes the user list.
- *
- * @param {object} options list of initialization options
- */
- init: function(options) {
- this._cache = new Dictionary();
- this._pageCount = 0;
- this._pageNo = 1;
-
- this._options = Core.extend({
- className: '',
- dialogTitle: '',
- parameters: {}
- }, options);
- },
-
- /**
- * Opens the user list.
- */
- open: function() {
- this._pageNo = 1;
- this._showPage();
- },
-
- /**
- * Shows the current or given page.
- *
- * @param {int=} pageNo page number
- */
- _showPage: function(pageNo) {
- if (typeof pageNo === 'number') {
- this._pageNo = ~~pageNo;
- }
-
- if (this._pageCount !== 0 && (this._pageNo < 1 || this._pageNo > this._pageCount)) {
- throw new RangeError("pageNo must be between 1 and " + this._pageCount + " (" + this._pageNo + " given).");
- }
-
- if (this._cache.has(this._pageNo)) {
- var dialog = UiDialog.open(this, this._cache.get(this._pageNo));
-
- if (this._pageCount > 1) {
- var element = elBySel('.jsPagination', dialog.content);
- if (element !== null) {
- new UiPagination(element, {
- activePage: this._pageNo,
- maxPage: this._pageCount,
-
- callbackSwitch: this._showPage.bind(this)
- });
- }
-
- // scroll to the list start
- var container = dialog.content.parentNode;
- if (container.scrollTop > 0) {
- container.scrollTop = 0;
- }
- }
- }
- else {
- this._options.parameters.pageNo = this._pageNo;
-
- Ajax.api(this, {
- parameters: this._options.parameters
- });
- }
- },
-
- _ajaxSuccess: function(data) {
- if (data.returnValues.pageCount !== undefined) {
- this._pageCount = ~~data.returnValues.pageCount;
- }
-
- this._cache.set(this._pageNo, data.returnValues.template);
- this._showPage();
- },
-
- _ajaxSetup: function() {
- return {
- data: {
- actionName: 'getGroupedUserList',
- className: this._options.className,
- interfaceName: 'wcf\\data\\IGroupedUserListAction'
- }
- };
- },
-
- _dialogSetup: function() {
- return {
- id: DomUtil.getUniqueId(),
- options: {
- title: this._options.dialogTitle
- },
- source: null
- };
- }
- };
-
- return UiUserList;
-});
--- /dev/null
+/**
+ * Object-based user list.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Ui/User/List
+ */
+
+import * as Ajax from '../../Ajax';
+import * as Core from '../../Core';
+import DomUtil from '../../Dom/Util';
+import UiDialog from '../Dialog';
+import UiPagination from '../Pagination';
+import { CallbackObject as AjaxCallbackObject, DatabaseObjectActionResponse, RequestOptions } from '../../Ajax/Data';
+import { CallbackObject as DialogCallbackObject, DialogData, DialogSettings } from '../Dialog/Data';
+
+/**
+ * @constructor
+ */
+class UiUserList implements AjaxCallbackObject, DialogCallbackObject {
+ private readonly cache = new Map<number, string>();
+ private readonly options: AjaxRequestOptions;
+ private pageCount = 0;
+ private pageNo = 1;
+
+ /**
+ * Initializes the user list.
+ *
+ * @param {object} options list of initialization options
+ */
+ constructor(options: AjaxRequestOptions) {
+ this.options = Core.extend({
+ className: '',
+ dialogTitle: '',
+ parameters: {},
+ }, options) as AjaxRequestOptions;
+ }
+
+ /**
+ * Opens the user list.
+ */
+ open() {
+ this.pageNo = 1;
+ this.showPage();
+ }
+
+ /**
+ * Shows the current or given page.
+ */
+ private showPage(pageNo?: number): void {
+ if (typeof pageNo === 'number') {
+ this.pageNo = +pageNo;
+ }
+
+ if (this.pageCount !== 0 && (this.pageNo < 1 || this.pageNo > this.pageCount)) {
+ throw new RangeError("pageNo must be between 1 and " + this.pageCount + " (" + this.pageNo + " given).");
+ }
+
+ if (this.cache.has(this.pageNo)) {
+ const dialog = UiDialog.open(this, this.cache.get(this.pageNo)) as DialogData;
+
+ if (this.pageCount > 1) {
+ const element = dialog.content.querySelector('.jsPagination') as HTMLElement;
+ if (element !== null) {
+ new UiPagination(element, {
+ activePage: this.pageNo,
+ maxPage: this.pageCount,
+
+ callbackSwitch: this.showPage.bind(this),
+ });
+ }
+
+ // scroll to the list start
+ const container = dialog.content.parentElement!;
+ if (container.scrollTop > 0) {
+ container.scrollTop = 0;
+ }
+ }
+ } else {
+ this.options.parameters.pageNo = this.pageNo;
+
+ Ajax.api(this, {
+ parameters: this.options.parameters,
+ });
+ }
+ }
+
+ _ajaxSuccess(data: AjaxResponse): void {
+ if (data.returnValues.pageCount !== undefined) {
+ this.pageCount = ~~data.returnValues.pageCount;
+ }
+
+ this.cache.set(this.pageNo, data.returnValues.template);
+ this.showPage();
+ }
+
+ _ajaxSetup(): RequestOptions {
+ return {
+ data: {
+ actionName: 'getGroupedUserList',
+ className: this.options.className,
+ interfaceName: 'wcf\\data\\IGroupedUserListAction',
+ },
+ };
+ }
+
+ _dialogSetup(): DialogSettings {
+ return {
+ id: DomUtil.getUniqueId(),
+ options: {
+ title: this.options.dialogTitle,
+ },
+ source: null,
+ };
+ }
+}
+
+export = UiUserList
+
+interface AjaxRequestOptions {
+ className: string;
+ dialogTitle: string;
+ parameters: {
+ [key: string]: any;
+ };
+}
+
+interface AjaxResponse extends DatabaseObjectActionResponse {
+ returnValues: {
+ pageCount?: number;
+ template: string;
+ }
+}