Remove automatically set static DBO properties
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / js / WoltLab / Conversation / Ui / Participant / Add.js
1 /**
2 * Adds participants to an existing conversation.
3 *
4 * @author Alexander Ebert
5 * @copyright 2001-2016 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLab/Conversation/Ui/Participant/Add
8 */
9 define(['Ajax', 'Language', 'Ui/Dialog', 'Ui/Notification', 'WoltLab/WCF/Ui/ItemList/User'], function(Ajax, Language, UiDialog, UiNotification, UiItemListUser) {
10 "use strict";
11
12 /**
13 * @constructor
14 * @param {int} conversationId conversation id
15 */
16 function UiParticipantAdd(conversationId) { this.init(conversationId); }
17 UiParticipantAdd.prototype = {
18 /**
19 * Manages the form to add one or more participants to an existing conversation.
20 *
21 * @param {int} conversationId conversation id
22 */
23 init: function(conversationId) {
24 this._conversationId = conversationId;
25
26 Ajax.api(this, {
27 actionName: 'getAddParticipantsForm'
28 });
29 },
30
31 _ajaxSetup: function() {
32 return {
33 data: {
34 className: 'wcf\\data\\conversation\\ConversationAction',
35 objectIDs: [ this._conversationId ]
36 }
37 };
38 },
39
40 /**
41 * Handles successful Ajax requests.
42 *
43 * @param {Object} data response data
44 */
45 _ajaxSuccess: function(data) {
46 switch (data.actionName) {
47 case 'addParticipants':
48 this._handleResponse(data);
49 break;
50
51 case 'getAddParticipantsForm':
52 this._render(data);
53 break;
54 }
55 },
56
57 /**
58 * Shows the success message and closes the dialog overlay.
59 *
60 * @param {Object} data response data
61 */
62 _handleResponse: function(data) {
63 //noinspection JSUnresolvedVariable
64 if (data.returnValues.count) {
65 //noinspection JSUnresolvedVariable
66 UiNotification.show(data.returnValues.successMessage);
67 }
68
69 UiDialog.close(this);
70 },
71
72 /**
73 * Renders the dialog to add participants.
74 *
75 * @param {object} data response data
76 */
77 _render: function(data) {
78 //noinspection JSUnresolvedVariable
79 UiDialog.open(this, data.returnValues.template);
80
81 var buttonSubmit = document.getElementById('addParticipants');
82 buttonSubmit.disabled = true;
83
84 //noinspection JSUnresolvedVariable
85 UiItemListUser.init('participantsInput', {
86 callbackChange: function(elementId, values) { buttonSubmit.disabled = (values.length === 0); },
87 excludedSearchValues: data.returnValues.excludedSearchValues,
88 maxItems: data.returnValues.maxItems
89 });
90
91 buttonSubmit.addEventListener('click', this._submit.bind(this));
92 },
93
94 /**
95 * Sends a request to add participants.
96 */
97 _submit: function() {
98 var values = UiItemListUser.getValues('participantsInput'), participants = [];
99 for (var i = 0, length = values.length; i < length; i++) {
100 participants.push(values[i].value);
101 }
102
103 Ajax.api(this, {
104 actionName: 'addParticipants',
105 parameters: {
106 participants: participants
107 }
108 });
109 },
110
111 _dialogSetup: function() {
112 return {
113 id: 'conversationAddParticipants',
114 options: {
115 title: Language.get('wcf.conversation.edit.addParticipants')
116 },
117 source: null
118 };
119 }
120 };
121
122 return UiParticipantAdd;
123 });