Completed
Push — js-scrutinizing ( fe8d2d...ccc639 )
by Maxence
02:15
created

js/navigation.actions.js   A

Complexity

Total Complexity 29
Complexity/F 2.42

Size

Lines of Code 171
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 171
rs 10
wmc 29
mnd 1
bc 21
fnc 12
bpm 1.75
cpm 2.4166
noi 17

10 Functions

Rating   Name   Duplication   Size   Complexity  
A actions.addMemberResult 0 13 3
B actions.getStringTypeFromType 0 14 5
A actions.searchMembersResult 0 19 4
A actions.onEventNewCircle 0 10 1
A actions.searchMembersRequest 0 16 2
A actions.displayMembersInteraction 0 21 4
A actions.removeMemberResult 0 16 3
A actions.onEventNewCircleName 0 4 1
A actions.onEventNewCircleType 0 6 1
A actions.createCircleResult 0 14 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
31
32
var actions = {
33
34
35
		createCircleResult: function (result) {
36
			var str = this.getStringTypeFromType(result.type);
37
38
			if (result.status == 1) {
39
				OCA.notification.onSuccess(str + " '" + result.name + "' created");
40
				nav.displayCirclesList(result.circle.type);
0 ignored issues
show
Bug introduced by
The variable nav seems to be never declared. If this is a global, consider adding a /** global: nav */ 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...
41
				nav.selectCircle(result.circle.id);
42
				return;
43
			}
44
45
			OCA.notification.onFail(
46
				str + " '" + result.name + "' NOT created: " +
47
				((result.error) ? result.error : 'no error message'));
48
		},
49
50
51
		displayMembersInteraction: function (details) {
52
			if (details.user.level < 6) {
53
				navdiv.addMember.hide();
0 ignored issues
show
Bug introduced by
The variable navdiv seems to be never declared. If this is a global, consider adding a /** global: navdiv */ 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...
54
			} else {
55
				navdiv.addMember.show();
56
			}
57
58
			this.displayNonMemberInteraction(details);
59
60
			if (details.user.level == 9) {
61
				navdiv.joinCircle.hide();
62
				navdiv.leaveCircle.hide();
63
				return;
64
			}
65
66
			if (details.user.level >= 1) {
67
				navdiv.joinCircle.hide();
68
				navdiv.leaveCircle.show();
69
			}
70
71
		},
72
73
74
		/**
75
		 *
76
		 * @param search
77
		 */
78
		searchMembersRequest: function (search) {
79
80
			if (curr.searchUser == search) {
0 ignored issues
show
Bug introduced by
The variable curr seems to be never declared. If this is a global, consider adding a /** global: curr */ 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...
81
				return;
82
			}
83
84
			curr.searchUser = search;
85
86
			$.get(OC.linkToOCS('apps/files_sharing/api/v1', 1) + 'sharees',
87
				{
88
					format: 'json',
89
					search: search,
90
					perPage: 200,
91
					itemType: 'principals'
92
				}, actions.searchMembersResult);
93
		},
94
95
96
		searchMembersResult: function (response) {
97
98
			if (response === null ||
99
				(response.ocs.data.users === 0 && response.ocs.data.exact.users === 0)) {
100
				navdiv.membersSearchResult.fadeOut(300);
0 ignored issues
show
Bug introduced by
The variable navdiv seems to be never declared. If this is a global, consider adding a /** global: navdiv */ 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...
101
				return;
102
			}
103
104
			navdiv.membersSearchResult.children().remove();
105
106
			navdiv.fillMembersSearch(response.ocs.data.exact.users, response.ocs.data.users);
107
108
			$('.members_search').on('click', function () {
109
				api.addMember(curr.circle, $(this).attr('searchresult'),
0 ignored issues
show
Bug introduced by
The variable api seems to be never declared. If this is a global, consider adding a /** global: api */ 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...
Bug introduced by
The variable curr seems to be never declared. If this is a global, consider adding a /** global: curr */ 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...
110
					actions.addMemberResult);
111
			});
112
			navdiv.membersSearchResult.fadeIn(300);
0 ignored issues
show
Bug introduced by
The variable navdiv seems to be never declared. If this is a global, consider adding a /** global: navdiv */ 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...
113
114
		},
115
116
117
		addMemberResult: function (result) {
118
119
			if (result.status == 1) {
120
				OCA.notification.onSuccess(
121
					"Member '" + result.name + "' successfully added to the circle");
122
123
				navdiv.displayMembers(result.members);
0 ignored issues
show
Bug introduced by
The variable navdiv seems to be never declared. If this is a global, consider adding a /** global: navdiv */ 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...
124
				return;
125
			}
126
			OCA.notification.onFail(
127
				"Member '" + result.name + "' NOT added to the circle: " +
128
				((result.error) ? result.error : 'no error message'));
129
		},
130
131
132
		getStringTypeFromType: function (type) {
133
			switch (type) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
134
				case '1':
135
					return 'Personal circle';
136
				case '2':
137
					return 'Hidden circle';
138
				case '4':
139
					return 'Private circle';
140
				case '8':
141
					return 'Public circle';
142
			}
143
144
			return 'Circle';
145
		},
146
147
148
		removeMemberResult: function (result) {
149
			if (result.status == 1) {
150
151
				navdiv.mainUIMembers.children("[member-id='" + result.name + "']").each(
0 ignored issues
show
Bug introduced by
The variable navdiv seems to be never declared. If this is a global, consider adding a /** global: navdiv */ 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...
152
					function () {
153
						$(this).hide(300);
154
					});
155
				OCA.notification.onSuccess(
156
					"Member '" + result.name + "' successfully removed from the circle");
157
				return;
158
			}
159
160
			OCA.notification.onFail(
161
				"Member '" + result.name + "' NOT removed from the circle: " +
162
				((result.error) ? result.error : 'no error message'));
163
		},
164
165
166
		/**
167
		 *
168
		 */
169
		onEventNewCircle: function () {
170
171
			curr.circle = 0;
0 ignored issues
show
Bug introduced by
The variable curr seems to be never declared. If this is a global, consider adding a /** global: curr */ 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...
172
			curr.circleLevel = 0;
173
174
			navdiv.navigation.hide('slide', 800);
0 ignored issues
show
Bug introduced by
The variable navdiv seems to be never declared. If this is a global, consider adding a /** global: navdiv */ 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...
175
			navdiv.circlesList.children('div').removeClass('selected');
176
			navdiv.emptyContent.show(800);
177
			navdiv.mainUI.fadeOut(800);
178
		}
0 ignored issues
show
Bug introduced by
There seems to be a bad line break before ,.
Loading history...
179
		,
0 ignored issues
show
introduced by
Comma warnings can be turned off with 'laxcomma'.
Loading history...
180
181
		/**
182
		 *
183
		 */
184
		onEventNewCircleName: function () {
185
			this.onEventNewCircle();
186
			this.displayOptionsNewCircle((navdiv.newName.val() !== ''));
0 ignored issues
show
Bug introduced by
The variable navdiv seems to be never declared. If this is a global, consider adding a /** global: navdiv */ 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...
187
		}
0 ignored issues
show
Bug introduced by
There seems to be a bad line break before ,.
Loading history...
188
		,
189
190
		/**
191
		 *
192
		 */
193
		onEventNewCircleType: function () {
194
			this.onEventNewCircle();
195
			navdiv.newTypeDefinition.children('div').fadeOut(300);
0 ignored issues
show
Bug introduced by
The variable navdiv seems to be never declared. If this is a global, consider adding a /** global: navdiv */ 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...
196
			$('#circles_new_type_' + navdiv.newType.children('option:selected').val()).fadeIn(
197
				300);
198
		}
199
200
201
	}
202
	;
203
204
// $(document).ready(function () {
205
// (function () {
206
//
207
//
208
// Navigation.prototype.displayMembersInteraction
209
// 	= function (details) {
210
// 	if (details.user.level < 6) {
211
// 		divAddMember.hide();
212
// 	} else {
213
// 		divAddMember.show();
214
// 	}
215
//
216
// 	this.displayNonMemberInteraction(details);
217
//
218
// 	if (details.user.level == 9) {
219
// 		divJoinCircle.hide();
220
// 		divLeaveCircle.hide();
221
// 		return;
222
// 	}
223
//
224
// 	if (details.user.level >= 1) {
225
// 		divJoinCircle.hide();
226
// 		divLeaveCircle.show();
227
// 	}
228
// }
229
230
231
// });
232
233
// (function () {
234
//
235
// 	var Actions = function () {
236
// 		this.initialize();
237
// 	};
238
//
239
// 	Actions.prototype = {
240
//
241
//
242
// 		initialize: function () {
243
//
244
//
245
//
246
//
247
// 			/**
248
// 			 *
249
// 			 */
250
//
251
//
252
//
253
//
254
//
255
//
256
//
257
// 	}
258
//
259
// 	OCA.Circles.Actions = Actions;
260
// 	OCA.Circles.actions = new Actions();
261
//
262
// })
263
// ();
264
//
265