2 * User editing capabilities for the user list.
4 * @author Alexander Ebert
5 * @copyright 2001-2019 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/Acp/Ui/User/Editor
10 define(['Ajax', 'Core', 'EventHandler', 'Language', 'Ui/Notification', 'Ui/SimpleDropdown', 'WoltLabSuite/Core/Acp/Ui/User/Content/Remove/Handler'], function(Ajax
, Core
, EventHandler
, Language
, UiNotification
, UiSimpleDropdown
, RemoveContentHandler
) {
14 * @exports WoltLabSuite/Core/Acp/Ui/User/Editor
18 * Initializes the edit dropdown for each user.
21 elBySelAll('.jsUserRow', undefined, this._initUser
.bind(this));
23 EventHandler
.add('com.woltlab.wcf.acp.user', 'refresh', this._refreshUsers
.bind(this));
27 * Initializes the edit dropdown for a user.
29 * @param {Element} userRow
32 _initUser: function (userRow
) {
33 var userId
= ~~elData(userRow
, 'object-id');
34 var dropdownMenu
= UiSimpleDropdown
.getDropdownMenu('userListDropdown' + userId
);
35 var legacyButtonContainer
= elBySel('.jsLegacyButtons', userRow
);
37 if (dropdownMenu
.childElementCount
=== 0 && legacyButtonContainer
.childElementCount
=== 0) {
38 elBySel('.dropdownToggle', userRow
).classList
.add('disabled');
42 UiSimpleDropdown
.registerCallback('userListDropdown' + userId
, (function (identifier
, action
) {
43 if (action
=== 'open') {
44 this._rebuild(userId
, dropdownMenu
, legacyButtonContainer
);
48 var editLink
= elBySel('.jsEditLink', dropdownMenu
);
49 if (editLink
!== null) {
50 elBySel('.dropdownToggle', userRow
).addEventListener('dblclick', function (event
) {
51 event
.preventDefault();
57 var sendNewPassword
= elBySel('.jsSendNewPassword', dropdownMenu
);
58 if (sendNewPassword
!== null) {
59 sendNewPassword
.addEventListener(WCF_CLICK_EVENT
, function (event
) {
60 event
.preventDefault();
62 // emulate clipboard selection
63 EventHandler
.fire('com.woltlab.wcf.clipboard', 'com.woltlab.wcf.user', {
65 actionName
: 'com.woltlab.wcf.user.sendNewPassword',
67 confirmMessage
: Language
.get('wcf.acp.user.action.sendNewPassword.confirmMessage'),
72 actionName
: 'com.woltlab.wcf.user.sendNewPassword',
79 var deleteContent
= elBySel('.jsDeleteContent', dropdownMenu
);
80 if (deleteContent
!== null) {
81 new RemoveContentHandler(deleteContent
, userId
);
84 var toggleConfirmEmail
= elBySel('.jsConfirmEmailToggle', dropdownMenu
);
85 if (toggleConfirmEmail
!== null) {
86 toggleConfirmEmail
.addEventListener(WCF_CLICK_EVENT
, function (event
) {
87 event
.preventDefault();
90 _ajaxSetup: function () {
93 actionName
: (elDataBool(userRow
, 'email-confirmed') ? 'un' : '') + 'confirmEmail',
94 className
: 'wcf\\data\\user\\UserAction',
99 }, null, function (data
) {
100 elBySelAll('.jsUserRow', undefined, function(userRow
) {
101 var userId
= parseInt(elData(userRow
, 'object-id'));
102 if (data
.objectIDs
.indexOf(userId
) !== -1) {
103 var confirmEmailButton
= elBySel('.jsConfirmEmailToggle', UiSimpleDropdown
.getDropdownMenu('userListDropdown' + userId
));
105 switch (data
.actionName
) {
107 elData(userRow
, 'email-confirmed', 'true');
108 confirmEmailButton
.textContent
= elData(confirmEmailButton
, 'unconfirm-email-message');
111 case 'unconfirmEmail':
112 elData(userRow
, 'email-confirmed', 'false');
113 confirmEmailButton
.textContent
= elData(confirmEmailButton
, 'confirm-email-message');
117 throw new Error("Unreachable");
122 UiNotification
.show();
129 * Rebuilds the dropdown by adding wrapper links for legacy buttons,
130 * that will eventually receive the click event.
132 * @param {int} userId
133 * @param {Element} dropdownMenu
134 * @param {Element} legacyButtonContainer
137 _rebuild: function (userId
, dropdownMenu
, legacyButtonContainer
) {
138 elBySelAll('.jsLegacyItem', dropdownMenu
, elRemove
);
141 var button
, item
, link
;
143 var deleteButton
= null;
144 for (var i
= 0, length
= legacyButtonContainer
.childElementCount
; i
< length
; i
++) {
145 button
= legacyButtonContainer
.children
[i
];
146 if (button
.classList
.contains('jsDeleteButton')) {
147 deleteButton
= button
;
151 item
= elCreate('li');
152 item
.className
= 'jsLegacyItem';
153 item
.innerHTML
= '<a href="#"></a>';
155 link
= item
.children
[0];
156 link
.textContent
= elData(button
, 'tooltip') || button
.title
;
158 link
.addEventListener(WCF_CLICK_EVENT
, function (event
) {
159 event
.preventDefault();
161 // forward click onto original button
162 if (button
.nodeName
=== 'A') button
.click();
163 else Core
.triggerEvent(button
, WCF_CLICK_EVENT
);
170 while (items
.length
) {
171 dropdownMenu
.insertBefore(items
.pop(), dropdownMenu
.firstElementChild
);
174 if (deleteButton
!== null) {
175 elBySel('.jsDispatchDelete', dropdownMenu
).addEventListener(WCF_CLICK_EVENT
, function (event
) {
176 event
.preventDefault();
178 Core
.triggerEvent(deleteButton
, WCF_CLICK_EVENT
);
182 // check if there are visible items before each divider
183 for (i
= 0, length
= dropdownMenu
.childElementCount
; i
< length
; i
++) {
184 elShow(dropdownMenu
.children
[i
]);
188 for (i
= 0, length
= dropdownMenu
.childElementCount
; i
< length
; i
++) {
189 item
= dropdownMenu
.children
[i
];
190 if (item
.classList
.contains('dropdownDivider')) {
191 if (!hasItem
) elHide(item
);
199 _refreshUsers: function (data
) {
200 elBySelAll('.jsUserRow', undefined, function(userRow
) {
201 var userId
= parseInt(elData(userRow
, 'object-id'));
202 if (data
.userIds
.indexOf(userId
) !== -1) {
203 var userStatusIcons
= elBySel('.userStatusIcons', userRow
);
205 var banned
= elDataBool(userRow
, 'banned');
206 var iconBanned
= elBySel('.jsUserStatusBanned', userRow
);
207 if (banned
&& iconBanned
=== null) {
208 iconBanned
= elCreate('span');
209 iconBanned
.className
= 'icon icon16 fa-lock jsUserStatusBanned jsTooltip';
210 iconBanned
.title
= Language
.get('wcf.user.status.banned');
211 userStatusIcons
.insertBefore(iconBanned
, null);
213 else if (!banned
&& iconBanned
!== null) {
214 elRemove(iconBanned
);
217 var isDisabled
= elDataBool(userRow
, 'enabled') === false;
218 var iconIsDisabled
= elBySel('.jsUserStatusIsDisabled', userRow
);
219 if (isDisabled
&& iconIsDisabled
=== null) {
220 iconIsDisabled
= elCreate('span');
221 iconIsDisabled
.className
= 'icon icon16 fa-power-off jsUserStatusIsDisabled jsTooltip';
222 iconIsDisabled
.title
= Language
.get('wcf.user.status.isDisabled');
223 userStatusIcons
.appendChild(iconIsDisabled
);
225 else if (!isDisabled
&& iconIsDisabled
!== null) {
226 elRemove(iconIsDisabled
);