* The `values` argument must be empty or contain a list of strings or object, e.g.
* `['foo', 'bar']` or `[{ objectId: 1337, value: 'baz'}, {...}]`
*/
- function init(elementId, values, options) {
+ function init(elementId, values, opts) {
const element = document.getElementById(elementId);
if (element === null) {
throw new Error("Expected a valid element id, '" + elementId + "' is invalid.");
Simple_1.default.destroy(elementId);
_data.delete(elementId);
}
- options = Core.extend({
+ const options = Core.extend({
// search parameters for suggestions
ajax: {
actionName: "getSearchResultList",
callbackSetupValues: null,
// value may contain the placeholder `{$objectId}`
submitFieldName: "",
- }, options);
+ }, opts);
const form = DomTraverse.parentByTag(element, "FORM");
if (form !== null) {
if (!options.isCSV) {
/**
* Provides an item list for users and groups.
*
- * @author Alexander Ebert
- * @copyright 2001-2020 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module WoltLabSuite/Core/Ui/ItemList/User
+ * @author Alexander Ebert
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Ui/ItemList/User
*/
-define(['WoltLabSuite/Core/Ui/ItemList'], function (UiItemList) {
+define(["require", "exports", "tslib", "../ItemList"], function (require, exports, tslib_1, UiItemList) {
"use strict";
- if (!COMPILER_TARGET_DEFAULT) {
- var Fake = function () { };
- Fake.prototype = {
- init: function () { },
- getValues: function () { }
- };
- return Fake;
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.getValues = exports.init = void 0;
+ UiItemList = tslib_1.__importStar(UiItemList);
+ function syncShadow(data) {
+ const values = getValues(data.element.id);
+ const users = [];
+ const groups = [];
+ values.forEach((value) => {
+ if (value.type && value.type === "group") {
+ groups.push(value.objectId);
+ }
+ else {
+ users.push(value.value);
+ }
+ });
+ const shadowElement = data.shadow;
+ shadowElement.value = users.join(",");
+ if (!data._shadowGroups) {
+ data._shadowGroups = document.createElement("input");
+ data._shadowGroups.type = "hidden";
+ data._shadowGroups.name = `${shadowElement.name}GroupIDs`;
+ shadowElement.insertAdjacentElement("beforebegin", data._shadowGroups);
+ }
+ data._shadowGroups.value = groups.join(",");
+ return values;
}
/**
- * @exports WoltLabSuite/Core/Ui/ItemList/User
+ * Initializes user suggestion support for an element.
+ *
+ * @param {string} elementId input element id
+ * @param {object} options option list
*/
- return {
- /**
- * Initializes user suggestion support for an element.
- *
- * @param {string} elementId input element id
- * @param {object} options option list
- */
- init: function (elementId, options) {
- UiItemList.init(elementId, [], {
- ajax: {
- className: 'wcf\\data\\user\\UserAction',
- parameters: {
- data: {
- includeUserGroups: ~~options.includeUserGroups,
- restrictUserGroupIDs: (Array.isArray(options.restrictUserGroupIDs) ? options.restrictUserGroupIDs : [])
- }
- }
+ function init(elementId, options) {
+ UiItemList.init(elementId, [], {
+ ajax: {
+ className: "wcf\\data\\user\\UserAction",
+ parameters: {
+ data: {
+ includeUserGroups: options.includeUserGroups ? ~~options.includeUserGroups : 0,
+ restrictUserGroupIDs: Array.isArray(options.restrictUserGroupIDs) ? options.restrictUserGroupIDs : [],
+ },
},
- callbackChange: (typeof options.callbackChange === 'function' ? options.callbackChange : null),
- callbackSyncShadow: options.csvPerType ? this._syncShadow.bind(this) : null,
- callbackSetupValues: (typeof options.callbackSetupValues === 'function' ? options.callbackSetupValues : null),
- excludedSearchValues: (Array.isArray(options.excludedSearchValues) ? options.excludedSearchValues : []),
- isCSV: true,
- maxItems: ~~options.maxItems || -1,
- restricted: true
- });
- },
- /**
- * @see WoltLabSuite/Core/Ui/ItemList::getValues()
- */
- getValues: function (elementId) {
- return UiItemList.getValues(elementId);
- },
- _syncShadow: function (data) {
- var values = this.getValues(data.element.id);
- var users = [], groups = [];
- values.forEach(function (value) {
- if (value.type && value.type === 'group')
- groups.push(value.objectId);
- else
- users.push(value.value);
- });
- data.shadow.value = users.join(',');
- if (!data._shadowGroups) {
- data._shadowGroups = elCreate('input');
- data._shadowGroups.type = 'hidden';
- data._shadowGroups.name = data.shadow.name + 'GroupIDs';
- data.shadow.parentNode.insertBefore(data._shadowGroups, data.shadow);
- }
- data._shadowGroups.value = groups.join(',');
- return values;
- }
- };
+ },
+ callbackChange: typeof options.callbackChange === "function" ? options.callbackChange : null,
+ callbackSyncShadow: options.csvPerType ? syncShadow : null,
+ callbackSetupValues: typeof options.callbackSetupValues === "function" ? options.callbackSetupValues : null,
+ excludedSearchValues: Array.isArray(options.excludedSearchValues) ? options.excludedSearchValues : [],
+ isCSV: true,
+ maxItems: options.maxItems ? ~~options.maxItems : -1,
+ restricted: true,
+ });
+ }
+ exports.init = init;
+ /**
+ * @see WoltLabSuite/Core/Ui/ItemList::getValues()
+ */
+ function getValues(elementId) {
+ return UiItemList.getValues(elementId);
+ }
+ exports.getValues = getValues;
});
* The `values` argument must be empty or contain a list of strings or object, e.g.
* `['foo', 'bar']` or `[{ objectId: 1337, value: 'baz'}, {...}]`
*/
-export function init(elementId: string, values: ItemDataOrPlainValue[], options: ItemListOptions): void {
+export function init(elementId: string, values: ItemDataOrPlainValue[], opts: Partial<ItemListOptions>): void {
const element = document.getElementById(elementId) as ItemListInputElement;
if (element === null) {
throw new Error("Expected a valid element id, '" + elementId + "' is invalid.");
_data.delete(elementId);
}
- options = Core.extend(
+ const options = Core.extend(
{
// search parameters for suggestions
ajax: {
// value may contain the placeholder `{$objectId}`
submitFieldName: "",
},
- options
+ opts
) as ItemListOptions;
const form = DomTraverse.parentByTag(element, "FORM") as HTMLFormElement;
const data = createUI(element, options);
const suggestion = new UiSuggestion(elementId, {
- ajax: options.ajax,
+ ajax: options.ajax as DatabaseObjectActionPayload,
callbackSelect: addItem,
excludedSearchValues: options.excludedSearchValues,
});
type ItemListInputElement = HTMLInputElement | HTMLTextAreaElement;
-interface ItemData {
+export interface ItemData {
objectId: number;
value: string;
type?: string;
type ItemDataOrPlainValue = ItemData | PlainValue;
-interface ItemListOptions {
+export type CallbackChange = (elementId: string, values: ItemData[]) => void;
+
+export type CallbackSetupValues = () => ItemDataOrPlainValue[];
+
+export type CallbackSubmit = (form: HTMLFormElement, values: ItemData[]) => void;
+
+export type CallbackSyncShadow = (data: ElementData) => ItemData[];
+
+export interface ItemListOptions {
// search parameters for suggestions
- ajax: DatabaseObjectActionPayload;
+ ajax: {
+ actionName?: string;
+ className: string;
+ parameters?: object;
+ };
// list of excluded string values, e.g. `['ignore', 'these strings', 'when', 'searching']`
excludedSearchValues: string[];
isCSV: boolean;
// will be invoked whenever the items change, receives the element id first and list of values second
- callbackChange?: (elementId: string, values: ItemData[]) => void;
+ callbackChange: CallbackChange | null;
// callback once the form is about to be submitted
- callbackSubmit?: (form: HTMLFormElement, values: ItemData[]) => void;
+ callbackSubmit: CallbackSubmit | null;
// Callback for the custom shadow synchronization.
- callbackSyncShadow?: (data: ElementData) => ItemData[];
+ callbackSyncShadow: CallbackSyncShadow | null;
// Callback to set values during the setup.
- callbackSetupValues?: () => ItemDataOrPlainValue[];
+ callbackSetupValues: CallbackSetupValues | null;
// value may contain the placeholder `{$objectId}`
submitFieldName: string;
}
-interface ElementData {
+export interface ElementData {
dropdownMenu: HTMLElement | null;
element: ItemListInputElement;
limitReached: HTMLSpanElement;
+++ /dev/null
-/**
- * Provides an item list for users and groups.
- *
- * @author Alexander Ebert
- * @copyright 2001-2020 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module WoltLabSuite/Core/Ui/ItemList/User
- */
-define(['WoltLabSuite/Core/Ui/ItemList'], function(UiItemList) {
- "use strict";
-
- if (!COMPILER_TARGET_DEFAULT) {
- var Fake = function() {};
- Fake.prototype = {
- init: function() {},
- getValues: function() {}
- };
- return Fake;
- }
-
- /**
- * @exports WoltLabSuite/Core/Ui/ItemList/User
- */
- return {
- /**
- * Initializes user suggestion support for an element.
- *
- * @param {string} elementId input element id
- * @param {object} options option list
- */
- init: function(elementId, options) {
- UiItemList.init(elementId, [], {
- ajax: {
- className: 'wcf\\data\\user\\UserAction',
- parameters: {
- data: {
- includeUserGroups: ~~options.includeUserGroups,
- restrictUserGroupIDs: (Array.isArray(options.restrictUserGroupIDs) ? options.restrictUserGroupIDs : [])
- }
- }
- },
- callbackChange: (typeof options.callbackChange === 'function' ? options.callbackChange : null),
- callbackSyncShadow: options.csvPerType ? this._syncShadow.bind(this) : null,
- callbackSetupValues: (typeof options.callbackSetupValues === 'function' ? options.callbackSetupValues : null),
- excludedSearchValues: (Array.isArray(options.excludedSearchValues) ? options.excludedSearchValues : []),
- isCSV: true,
- maxItems: ~~options.maxItems || -1,
- restricted: true
- });
- },
-
- /**
- * @see WoltLabSuite/Core/Ui/ItemList::getValues()
- */
- getValues: function(elementId) {
- return UiItemList.getValues(elementId);
- },
-
- _syncShadow: function(data) {
- var values = this.getValues(data.element.id);
- var users = [], groups = [];
-
- values.forEach(function(value) {
- if (value.type && value.type === 'group') groups.push(value.objectId);
- else users.push(value.value);
- });
-
- data.shadow.value = users.join(',');
- if (!data._shadowGroups) {
- data._shadowGroups = elCreate('input');
- data._shadowGroups.type = 'hidden';
- data._shadowGroups.name = data.shadow.name + 'GroupIDs';
- data.shadow.parentNode.insertBefore(data._shadowGroups, data.shadow);
- }
- data._shadowGroups.value = groups.join(',');
-
- return values;
- }
- };
-});
--- /dev/null
+/**
+ * Provides an item list for users and groups.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Ui/ItemList/User
+ */
+
+import { CallbackChange, CallbackSetupValues, CallbackSyncShadow, ElementData, ItemData } from "../ItemList";
+import * as UiItemList from "../ItemList";
+
+interface ItemListUserOptions {
+ callbackChange?: CallbackChange;
+ callbackSetupValues?: CallbackSetupValues;
+ csvPerType?: boolean;
+ excludedSearchValues?: string[];
+ includeUserGroups?: boolean;
+ maxItems?: number;
+ restrictUserGroupIDs?: number[];
+}
+
+interface UserElementData extends ElementData {
+ _shadowGroups?: HTMLInputElement;
+}
+
+function syncShadow(data: UserElementData): ReturnType<CallbackSyncShadow> {
+ const values = getValues(data.element.id);
+
+ const users: string[] = [];
+ const groups: number[] = [];
+ values.forEach((value) => {
+ if (value.type && value.type === "group") {
+ groups.push(value.objectId);
+ } else {
+ users.push(value.value);
+ }
+ });
+
+ const shadowElement = data.shadow!;
+ shadowElement.value = users.join(",");
+ if (!data._shadowGroups) {
+ data._shadowGroups = document.createElement("input");
+ data._shadowGroups.type = "hidden";
+ data._shadowGroups.name = `${shadowElement.name}GroupIDs`;
+ shadowElement.insertAdjacentElement("beforebegin", data._shadowGroups);
+ }
+ data._shadowGroups.value = groups.join(",");
+
+ return values;
+}
+
+/**
+ * Initializes user suggestion support for an element.
+ *
+ * @param {string} elementId input element id
+ * @param {object} options option list
+ */
+export function init(elementId: string, options: ItemListUserOptions): void {
+ UiItemList.init(elementId, [], {
+ ajax: {
+ className: "wcf\\data\\user\\UserAction",
+ parameters: {
+ data: {
+ includeUserGroups: options.includeUserGroups ? ~~options.includeUserGroups : 0,
+ restrictUserGroupIDs: Array.isArray(options.restrictUserGroupIDs) ? options.restrictUserGroupIDs : [],
+ },
+ },
+ },
+ callbackChange: typeof options.callbackChange === "function" ? options.callbackChange : null,
+ callbackSyncShadow: options.csvPerType ? syncShadow : null,
+ callbackSetupValues: typeof options.callbackSetupValues === "function" ? options.callbackSetupValues : null,
+ excludedSearchValues: Array.isArray(options.excludedSearchValues) ? options.excludedSearchValues : [],
+ isCSV: true,
+ maxItems: options.maxItems ? ~~options.maxItems : -1,
+ restricted: true,
+ });
+}
+
+/**
+ * @see WoltLabSuite/Core/Ui/ItemList::getValues()
+ */
+export function getValues(elementId: string): ItemData[] {
+ return UiItemList.getValues(elementId);
+}