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
) {
14 * @param {int} conversationId conversation id
16 function UiParticipantAdd(conversationId
) { this.init(conversationId
); }
17 UiParticipantAdd
.prototype = {
19 * Manages the form to add one or more participants to an existing conversation.
21 * @param {int} conversationId conversation id
23 init: function(conversationId
) {
24 this._conversationId
= conversationId
;
27 actionName
: 'getAddParticipantsForm'
31 _ajaxSetup: function() {
34 className
: 'wcf\\data\\conversation\\ConversationAction',
35 objectIDs
: [ this._conversationId
]
41 * Handles successful Ajax requests.
43 * @param {Object} data response data
45 _ajaxSuccess: function(data
) {
46 switch (data
.actionName
) {
47 case 'addParticipants':
48 this._handleResponse(data
);
51 case 'getAddParticipantsForm':
58 * Shows the success message and closes the dialog overlay.
60 * @param {Object} data response data
62 _handleResponse: function(data
) {
63 //noinspection JSUnresolvedVariable
64 if (data
.returnValues
.errorMessage
) {
65 var innerError
= elCreate('small');
66 innerError
.className
= 'innerError';
67 //noinspection JSUnresolvedVariable
68 innerError
.textContent
= data
.returnValues
.errorMessage
;
70 var itemList
= elById('participantsInput').closest('.inputItemList');
71 itemList
.parentNode
.insertBefore(innerError
, itemList
.nextSibling
);
73 var oldError
= innerError
.nextElementSibling
;
74 if (oldError
&& oldError
.classList
.contains('innerError')) {
81 //noinspection JSUnresolvedVariable
82 if (data
.returnValues
.count
) {
83 //noinspection JSUnresolvedVariable
84 UiNotification
.show(data
.returnValues
.successMessage
, window
.location
.reload
.bind(window
.location
));
91 * Renders the dialog to add participants.
93 * @param {object} data response data
95 _render: function(data
) {
96 //noinspection JSUnresolvedVariable
97 UiDialog
.open(this, data
.returnValues
.template
);
99 var buttonSubmit
= elById('addParticipants');
100 buttonSubmit
.disabled
= true;
102 //noinspection JSUnresolvedVariable
103 UiItemListUser
.init('participantsInput', {
104 callbackChange: function(elementId
, values
) { buttonSubmit
.disabled
= (values
.length
=== 0); },
105 excludedSearchValues
: data
.returnValues
.excludedSearchValues
,
106 maxItems
: data
.returnValues
.maxItems
,
107 includeUserGroups
: data
.returnValues
.canAddGroupParticipants
&& data
.returnValues
.restrictUserGroupIDs
.length
> 0,
108 restrictUserGroupIDs
: data
.returnValues
.restrictUserGroupIDs
,
112 buttonSubmit
.addEventListener('click', this._submit
.bind(this));
116 * Sends a request to add participants.
118 _submit: function() {
119 var values
= UiItemListUser
.getValues('participantsInput'), participants
= [], participantsGroupIDs
= [];
120 for (var i
= 0, length
= values
.length
; i
< length
; i
++) {
121 if (values
[i
].type
=== 'group') participantsGroupIDs
.push(values
[i
].objectId
);
122 else participants
.push(values
[i
].value
);
126 participants
: participants
,
127 participantsGroupIDs
: participantsGroupIDs
130 var visibility
= elBySel('input[name="messageVisibility"]:checked, input[name="messageVisibility"][type="hidden"]', UiDialog
.getDialog(this).content
);
131 if (visibility
) parameters
.visibility
= visibility
.value
;
134 actionName
: 'addParticipants',
135 parameters
: parameters
139 _dialogSetup: function() {
141 id
: 'conversationAddParticipants',
143 title
: Language
.get('wcf.conversation.edit.addParticipants')
150 return UiParticipantAdd
;