2 * Adds participants to an existing conversation.
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/Conversation/Ui/Participant/Add
9 define(['Ajax', 'Language', 'Ui/Dialog', 'Ui/Notification', 'WoltLabSuite/Core/Ui/ItemList/User'], function (Ajax
, Language
, UiDialog
, UiNotification
, UiItemListUser
) {
13 * @param {int} conversationId conversation id
15 function UiParticipantAdd(conversationId
) { this.init(conversationId
); }
16 UiParticipantAdd
.prototype = {
18 * Manages the form to add one or more participants to an existing conversation.
20 * @param {int} conversationId conversation id
22 init: function (conversationId
) {
23 this._conversationId
= conversationId
;
25 actionName
: 'getAddParticipantsForm'
28 _ajaxSetup: function () {
31 className
: 'wcf\\data\\conversation\\ConversationAction',
32 objectIDs
: [this._conversationId
]
37 * Handles successful Ajax requests.
39 * @param {Object} data response data
41 _ajaxSuccess: function (data
) {
42 switch (data
.actionName
) {
43 case 'addParticipants':
44 this._handleResponse(data
);
46 case 'getAddParticipantsForm':
52 * Shows the success message and closes the dialog overlay.
54 * @param {Object} data response data
56 _handleResponse: function (data
) {
57 //noinspection JSUnresolvedVariable
58 if (data
.returnValues
.errorMessage
) {
59 var innerError
= elCreate('small');
60 innerError
.className
= 'innerError';
61 //noinspection JSUnresolvedVariable
62 innerError
.textContent
= data
.returnValues
.errorMessage
;
63 var itemList
= elById('participantsInput').closest('.inputItemList');
64 itemList
.parentNode
.insertBefore(innerError
, itemList
.nextSibling
);
65 var oldError
= innerError
.nextElementSibling
;
66 if (oldError
&& oldError
.classList
.contains('innerError')) {
71 //noinspection JSUnresolvedVariable
72 if (data
.returnValues
.count
) {
73 //noinspection JSUnresolvedVariable
74 UiNotification
.show(data
.returnValues
.successMessage
, window
.location
.reload
.bind(window
.location
));
79 * Renders the dialog to add participants.
81 * @param {object} data response data
83 _render: function (data
) {
84 //noinspection JSUnresolvedVariable
85 UiDialog
.open(this, data
.returnValues
.template
);
86 var buttonSubmit
= elById('addParticipants');
87 buttonSubmit
.disabled
= true;
88 //noinspection JSUnresolvedVariable
89 UiItemListUser
.init('participantsInput', {
90 callbackChange: function (elementId
, values
) { buttonSubmit
.disabled
= (values
.length
=== 0); },
91 excludedSearchValues
: data
.returnValues
.excludedSearchValues
,
92 maxItems
: data
.returnValues
.maxItems
,
93 includeUserGroups
: data
.returnValues
.canAddGroupParticipants
&& data
.returnValues
.restrictUserGroupIDs
.length
> 0,
94 restrictUserGroupIDs
: data
.returnValues
.restrictUserGroupIDs
,
97 buttonSubmit
.addEventListener('click', this._submit
.bind(this));
100 * Sends a request to add participants.
102 _submit: function () {
103 var values
= UiItemListUser
.getValues('participantsInput'), participants
= [], participantsGroupIDs
= [];
104 for (var i
= 0, length
= values
.length
; i
< length
; i
++) {
105 if (values
[i
].type
=== 'group')
106 participantsGroupIDs
.push(values
[i
].objectId
);
108 participants
.push(values
[i
].value
);
111 participants
: participants
,
112 participantsGroupIDs
: participantsGroupIDs
114 var visibility
= elBySel('input[name="messageVisibility"]:checked, input[name="messageVisibility"][type="hidden"]', UiDialog
.getDialog(this).content
);
116 parameters
.visibility
= visibility
.value
;
118 actionName
: 'addParticipants',
119 parameters
: parameters
122 _dialogSetup: function () {
124 id
: 'conversationAddParticipants',
126 title
: Language
.get('wcf.conversation.edit.addParticipants')
132 return UiParticipantAdd
;