Completed
Pull Request — master (#105)
by Maxence
02:19
created

js/circles.app.results.members.js   A

Complexity

Total Complexity 28
Complexity/F 2.8

Size

Lines of Code 162
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 28
c 4
b 0
f 1
dl 0
loc 162
rs 10
cc 0
nc 1
mnd 2
bc 23
fnc 10
bpm 2.3
cpm 2.8
noi 2

7 Functions

Rating   Name   Duplication   Size   Complexity  
B resultMembers.searchMembersResult 0 39 3
A resultMembers.inviteGroupMembersResult 0 16 3
A resultMembers.inviteMemberResult 0 15 3
A resultMembers.addGroupMembersResult 0 21 4
A resultMembers.removeMemberResult 0 19 3
A resultMembers.addMemberResult 0 20 4
A resultMembers.levelMemberResult 0 16 3
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: actions */
31
/** global: nav */
32
/** global: elements */
33
/** global: curr */
34
/** global: api */
35
36
37
var resultMembers = {
38
39
40
	searchMembersResult: function (response) {
41
42
		elements.membersSearchResult.children().remove();
43
44
		if (response === null) {
45
			elements.membersSearchResult.fadeOut(0);
46
			return;
47
		}
48
49
		elements.fillMembersSearch('users', response.ocs.data.exact.users, response.ocs.data.users);
50
		elements.fillMembersSearch('groups', response.ocs.data.exact.groups,
51
			response.ocs.data.groups);
52
53
		if (elements.membersSearchResult.children().length === 0) {
54
			elements.membersSearchResult.fadeOut(0);
55
			return;
56
		}
57
58
		$('.members_search').on('click', function () {
59
			curr.searchUserSelected = $(this).attr('searchresult');
60
			if ($(this).attr('source') === 'groups') {
61
62
				OC.dialogs.confirm(
63
					t('circles',
64
						'This operation will add/invite all members of the group to the circle'),
65
					t('circles', 'Please confirm'),
66
					function (e) {
67
						if (e === true) {
68
							api.addGroupMembers(curr.circle, curr.searchUserSelected,
69
								resultMembers.addGroupMembersResult);
70
						}
71
					});
72
			} else {
73
				api.addMember(curr.circle, curr.searchUserSelected,
74
					resultMembers.addMemberResult);
75
			}
76
		});
77
		elements.membersSearchResult.fadeIn(300);
78
	},
79
80
81
	addMemberResult: function (result) {
82
83
		if (curr.circleDetails.type === define.typePrivate) {
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
84
			resultMembers.inviteMemberResult(result);
85
			return;
86
		}
87
88
		if (result.status === 1) {
89
			OCA.notification.onSuccess(
90
				t('circles', "The member '{name}' was added to the circle",
91
					{name: result.name}));
92
93
			nav.displayMembers(result.members);
94
			return;
95
		}
96
		OCA.notification.onFail(
97
			t('circles', "The member '{name}' could not be added to the circle",
98
				{name: result.name}) +
99
			': ' + ((result.error) ? result.error : t('circles', 'no error message')));
100
	},
101
102
103
	inviteMemberResult: function (result) {
104
105
		if (result.status === 1) {
106
			OCA.notification.onSuccess(
107
				t('circles', "The member '{name}' was invited to the circle",
108
					{name: result.name}));
109
110
			nav.displayMembers(result.members);
111
			return;
112
		}
113
		OCA.notification.onFail(
114
			t('circles', "The member '{name}' could not be invited to the circle",
115
				{name: result.name}) +
116
			': ' + ((result.error) ? result.error : t('circles', 'no error message')));
117
	},
118
119
120
	addGroupMembersResult: function (result) {
121
122
		if (curr.circleDetails.type === define.typePrivate) {
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
123
			resultMembers.inviteGroupMembersResult(result);
124
			return;
125
		}
126
127
		if (result.status === 1) {
128
			OCA.notification.onSuccess(
129
				t('circles', "Members of the group '{name}' were added to the circle",
130
					{name: result.name}));
131
132
			nav.displayMembers(result.members);
133
			return;
134
		}
135
		OCA.notification.onFail(
136
			t('circles', "Members of the group '{name}' could not be added to the circle",
137
				{name: result.name}) +
138
			': ' +
139
			((result.error) ? result.error : t('circles', 'no error message')));
140
	},
141
142
143
	inviteGroupMembersResult: function (result) {
144
145
		if (result.status === 1) {
146
			OCA.notification.onSuccess(
147
				t('circles', "Members of the group '{name}' were invited to the circle",
148
					{name: result.name}));
149
150
			nav.displayMembers(result.members);
151
			return;
152
		}
153
		OCA.notification.onFail(
154
			t('circles', "Members of the group '{name}' could not be invited to the circle",
155
				{name: result.name}) +
156
			': ' +
157
			((result.error) ? result.error : t('circles', 'no error message')));
158
	},
159
160
161
	removeMemberResult: function (result) {
162
		if (result.status === 1) {
163
164
			elements.mainUIMembersTable.children("[member-id='" + result.name + "']").each(
165
				function () {
166
					$(this).hide(300);
167
				});
168
			OCA.notification.onSuccess(
169
				t('circles', "The member '{name}' was removed from the circle",
170
					{name: result.name}));
171
			return;
172
		}
173
174
		OCA.notification.onFail(
175
			t('circles', "The member '{name}' could not be removed from the circle",
176
				{name: result.name}) +
177
			': ' +
178
			((result.error) ? result.error : t('circles', 'no error message')));
179
	},
180
181
	levelMemberResult: function (result) {
182
		if (result.status === 1) {
183
			OCA.notification.onSuccess(
184
				t('circles', "Member '{name}' updated",
185
					{name: result.name}));
186
187
			nav.displayMembers(result.members);
188
			return;
189
		}
190
191
		nav.displayMembers('');
192
		OCA.notification.onFail(
193
			t('circles', "The member '{name}' could not be updated", {name: result.name}) +
194
			': ' +
195
			((result.error) ? result.error : t('circles', 'no error message')));
196
	}
197
198
};
199