Completed
Push — testscrut1 ( 887503...5550f6 )
by Maxence
02:18
created

$(document).ready   C

Complexity

Conditions 7
Paths 15

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 6.7272
c 0
b 0
f 0
cc 7
nc 15
nop 1
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
29
$(document).ready(function () {
30
31
	/**
32
	 * @constructs Navigation
33
	 */
34
	var Navigation = function () {
35
		this.initialize();
36
	};
37
38
	Navigation.prototype = {
39
40
		initialize: function () {
41
			var self = this;
42
			var api = OCA.Circles.api;
43
44
			var currCirclesType = '';
45
			var currentCircle = 0;
46
			var currentCircleLevel = 0;
47
			var lastSearchCircle = '';
48
			var lastSearchUser = '';
49
50
51
			$('#circles_new_type_definition div').fadeOut(0);
52
			$('#circles_new_type_' + ($('#circles_new_type option:selected').val())).fadeIn(0);
53
54
			$('#circles_new_type').hide();
55
			$('#circles_new_submit').hide();
56
			$('#circles_new_type_definition').hide();
57
58
			$('#circles_new_name').on('keyup', function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
59
				currentCircle = 0;
60
				currentCircleLevel = 0;
61
62
				$('#app-navigation.circles').hide('slide', 800);
63
				$('#circles_list div').removeClass('selected');
64
				$('#emptycontent').show(800);
65
				$('#mainui').fadeOut(800);
66
67
				if ($('#circles_new_name').val() != '') {
0 ignored issues
show
Coding Style introduced by
It is recommended to use !== to compare with .

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
68
					$('#circles_new_type').fadeIn(300);
69
					$('#circles_new_submit').fadeIn(500);
70
					$('#circles_new_type_definition').fadeIn(700);
71
				}
72
				else {
73
					$('#circles_new_type').fadeOut(700);
74
					$('#circles_new_submit').fadeOut(500);
75
					$('#circles_new_type_definition').fadeOut(300);
76
				}
77
			});
78
79
			$('#circles_new_type').on('change', function () {
80
81
				currentCircle = 0;
82
				currentCircleLevel = 0;
83
84
				$('#app-navigation.circles').hide('slide', 800);
85
				$('#circles_list div').removeClass('selected');
86
				$('#emptycontent').show(800);
87
				$('#mainui').fadeOut(800);
88
89
				$('#circles_new_type_definition div').fadeOut(300);
90
				$('#circles_new_type_' + ($('#circles_new_type option:selected').val())).fadeIn(
91
					300);
92
			});
93
94
			$('#circles_new_submit').on('click', function () {
95
				api.createCircle($('#circles_new_type').val(), $('#circles_new_name').val(),
96
					self.createCircleResult);
97
			});
98
99
			$('#circles_list div').on('click', function () {
100
				self.displayCirclesList($(this).attr('circle-type'));
101
			});
102
103
			$('#circles_search').on('input propertychange paste focus', function () {
104
				if (lastSearchCircle == $(this).val().trim())
105
					return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
106
107
				lastSearchCircle = $(this).val().trim();
108
				api.searchCircles(currCirclesType, $(this).val().trim(),
109
					self.listCirclesResult);
110
			});
111
112
			$('.icon-circles').css('background-image',
113
				'url(' + OC.imagePath('circles', 'colored') + ')');
114
115
			$('#joincircle').on('click', function () {
116
				api.joinCircle(currentCircle, self.joinCircleResult);
117
			});
118
119
			$('#leavecircle').on('click', function () {
120
				api.leaveCircle(currentCircle, self.leaveCircleResult);
121
			});
122
123
			$('#joincircle_acceptinvit').on('click', function () {
124
				api.joinCircle(currentCircle, self.joinCircleResult);
125
			});
126
127
			$('#joincircle_rejectinvit').on('click', function () {
128
				api.leaveCircle(currentCircle, self.leaveCircleResult);
129
			});
130
131
			$('#addmember').on('input propertychange paste focus', function () {
132
133
				if (lastSearchUser == $(this).val().trim())
134
					return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
135
136
				lastSearchUser = $(this).val().trim();
137
138
				$.get(OC.linkToOCS('apps/files_sharing/api/v1') + 'sharees',
139
					{
140
						format: 'json',
141
						search: $(this).val().trim(),
142
						perPage: 200,
143
						itemType: 'principals'
144
					}, self.searchMembersResult);
145
			}).blur(function () {
146
				$('#members_search_result').fadeOut(400);
147
			});
148
149
			$('#members_search_result').hide();
150
151
152
			this.createCircleResult = function (result) {
153
				var str = 'Circle';
154
				switch (result.type) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
155
					case '1':
156
						str = 'Personal circle';
157
						break;
158
					case '2':
159
						str = 'Hidden circle';
160
						break;
161
					case '4':
162
						str = 'Private circle';
163
						break;
164
					case '8':
165
						str = 'Public circle';
166
						break;
167
				}
168
169
				if (result.status == 1) {
170
					OCA.notification.onSuccess(str + " '" + result.name + "' created");
171
					self.displayCirclesList(result.circle.type);
172
					self.selectCircle(result.circle.id);
173
				}
174
				else
175
					OCA.notification.onFail(
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
176
						str + " '" + result.name + "' NOT created: " +
177
						((result.error) ? result.error : 'no error message'));
178
			};
179
180
181
			//
182
			//
183
			// Circles List
184
			this.displayCirclesList = function (type) {
185
186
				self.currCirclesType = type;
187
				self.lastSearchCircle = '';
188
				self.lastSearchUser = '';
189
190
				self.currentCircle = 0;
191
				self.currentCircleLevel = 0;
192
193
				$('#app-navigation.circles').show('slide', 800);
194
				$('#emptycontent').show(800);
195
				$('#mainui').fadeOut(800);
196
197
				$('#circles_search').val('');
198
				$('#addmember').val('');
199
200
				$('#app-navigation.circles').addClass('selected');
201
				$('#circles_list div').removeClass('selected');
202
203
				$('#circles_list').children().each(function () {
204
					if ($(this).attr('circle-type') == type.toLowerCase())
205
						$(this).addClass('selected');
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
206
				});
207
208
				$('#app-navigation.circles').children().each(function () {
209
					if ($(this).attr('id') != 'circles_search')
210
						$(this).remove();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
211
				});
212
				api.listCircles(type, self.listCirclesResult);
213
			};
214
215
216
			this.listCirclesResult = function (result) {
217
218
				if (result.status < 1) {
219
					OCA.notification.onFail(
220
						'Issue while retreiving the list of the Circles: ' +
221
						((result.error) ? result.error : 'no error message'));
222
					return;
223
				}
224
225
				$('#app-navigation.circles').children().each(function () {
226
					if ($(this).attr('id') != 'circles_search')
227
						$(this).remove();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
228
				});
229
230
				var data = result.data;
231
				for (var i = 0; i < data.length; i++) {
232
233
					//	var curr = self.getCurrentCircleTemplate(data[i].id);
234
235
					var tmpl = $('#tmpl_circle').html();
236
237
					tmpl = tmpl.replace(/%title%/, data[i].name);
238
					tmpl = tmpl.replace(/%type%/, data[i].type);
239
					tmpl = tmpl.replace(/%owner%/, data[i].owner.userid);
240
					tmpl = tmpl.replace(/%status%/, data[i].user.status);
241
					tmpl = tmpl.replace(/%level_string%/, data[i].user.level_string);
242
					tmpl = tmpl.replace(/%count%/, data[i].count);
243
					tmpl = tmpl.replace(/%creation%/, data[i].creation);
244
245
					//	if (curr == null) {
246
					$('#app-navigation.circles').append(
247
						'<div class="circle" circle-id="' + data[i].id + '">' + tmpl + '</div>');
248
					//	} else {
249
					//		$(curr).html(tmpl);
250
					//	}
251
				}
252
253
				$('#app-navigation.circles').children('.circle').on('click', function () {
254
					self.selectCircle($(this).attr('circle-id'));
255
				});
256
			};
257
258
259
			this.selectCircle = function (circleid) {
260
				self.lastSearchUser = '';
261
				$('#addmember').val('');
262
263
				api.detailsCircle(circleid, this.selectCircleResult);
264
			};
265
266
267
			this.selectCircleResult = function (result) {
268
269
				$('#mainui #memberslist .table').children('tr').each(function () {
270
					if ($(this).attr('class') != 'header')
271
						$(this).remove();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
272
				});
273
274
				if (result.status < 1) {
275
					OCA.notification.onFail(
276
						'Issue while retreiving the details of a circle: ' +
277
						((result.error) ? result.error : 'no error message'));
278
					return;
279
				}
280
281
				$('#app-navigation.circles').children('.circle').each(function () {
282
					if ($(this).attr('circle-id') == result.circle_id)
283
						$(this).addClass('selected');
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
284
					else
285
						$(this).removeClass('selected');
286
				});
287
				$('#emptycontent').hide(800);
288
				$('#mainui').fadeIn(800);
289
				self.currentCircle = result.circle_id;
290
				self.currentCircleLevel = result.details.user.level;
291
292
				if (result.details.user.level < 6)
293
					$('#addmember').hide();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
294
				else
295
					$('#addmember').show();
296
297
				$('#joincircle_acceptinvit').hide();
298
				$('#joincircle_rejectinvit').hide();
299
				$('#joincircle_request').hide();
300
				$('#joincircle_invit').hide();
301
302
				if (result.details.user.level == 9) {
303
					$('#joincircle').hide();
304
					$('#leavecircle').hide();
305
				}
306
				else if (result.details.user.level >= 1) {
307
					$('#joincircle').hide();
308
					$('#leavecircle').show();
309
				} else {
310
					if (result.details.user.status == 'Invited') {
311
						$('#joincircle_invit').show();
312
						$('#joincircle_acceptinvit').show();
313
						$('#joincircle_rejectinvit').show();
314
						$('#joincircle').hide();
315
						$('#leavecircle').hide();
316
					}
317
					else if (result.details.user.status == 'Requesting') {
318
						$('#joincircle_request').show();
319
						$('#joincircle').hide();
320
						$('#leavecircle').show();
321
					}
322
					else {
323
						$('#joincircle').show();
324
						$('#leavecircle').hide();
325
					}
326
				}
327
328
				self.displayMembers(result.details.members);
329
			};
330
331
332
			this.searchMembersResult = function (response) {
333
334
				if (response == null ||
0 ignored issues
show
Coding Style introduced by
It is recommended to use === to compare with null.

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
335
					(response.ocs.data.users == 0 && response.ocs.data.exact.users == 0))
0 ignored issues
show
Coding Style introduced by
It is recommended to use === to compare with 0.

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
336
					$('#members_search_result').fadeOut(300);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
337
338
				else {
339
					var currSearch = $('#addmember').val().trim();
340
					$('#members_search_result').children().remove();
341
342
					$.each(response.ocs.data.exact.users, function (index, value) {
343
						$('#members_search_result').append(
344
							'<div class="members_search exact" searchresult="' +
345
							value.value.shareWith + '">' + value.label + '   (' +
346
							value.value.shareWith + ')</div>');
347
					});
348
349
					$.each(response.ocs.data.users, function (index, value) {
350
						var line = value.label + '   (' + value.value.shareWith + ')';
351
						if (currSearch.length > 0) line =
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
352
							line.replace(new RegExp('(' + currSearch + ')', 'gi'), '<b>$1</b>');
353
354
						$('#members_search_result').append(
355
							'<div class="members_search" searchresult="' + value.value.shareWith +
356
							'">' + line + '</div>');
357
					});
358
359
					$('#members_search_result').children().first().css('border-top-width', '0px');
360
361
					$('.members_search').on('click', function () {
362
						api.addMember(self.currentCircle, $(this).attr('searchresult'),
363
							self.addMemberResult);
364
					});
365
					$('#members_search_result').fadeIn(300);
366
				}
367
368
			};
369
370
371
			this.addMemberResult = function (result) {
372
373
				if (result.status == 1) {
374
					OCA.notification.onSuccess(
375
						"Member '" + result.name + "' successfully added to the circle");
376
377
					self.displayMembers(result.members);
378
				}
379
				else
380
					OCA.notification.onFail(
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
381
						"Member '" + result.name + "' NOT added to the circle: " +
382
						((result.error) ? result.error : 'no error message'));
383
384
			};
385
386
387
			this.displayMembers = function (members) {
388
389
				$('#mainui #memberslist .table').children('tr').each(function () {
390
					if ($(this).attr('class') != 'header')
391
						$(this).remove();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
392
				});
393
394
				if (members == null) {
0 ignored issues
show
Coding Style introduced by
It is recommended to use === to compare with null.

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
395
					$('#mainui #memberslist .table').hide(200);
396
					return;
397
				}
398
399
				$('#mainui #memberslist .table').show(200);
400
				for (var i = 0; i < members.length; i++) {
401
402
					var tmpl = $('#tmpl_member').html();
403
404
					tmpl = tmpl.replace(/%username%/g, members[i].userid);
405
					tmpl = tmpl.replace(/%level%/g, members[i].level);
406
					tmpl = tmpl.replace(/%levelstring%/g, members[i].level_string);
407
					tmpl = tmpl.replace(/%status%/, members[i].status);
408
					tmpl = tmpl.replace(/%joined%/, members[i].joined);
409
					tmpl = tmpl.replace(/%note%/,
410
						((members[i].note) ? members[i].note : ''));
411
412
					$('#mainui #memberslist .table').append(tmpl);
413
				}
414
415
				$('#mainui #memberslist .table').children().each(function () {
416
					if ($(this).attr('member-level') == '9' || self.currentCircleLevel < 6)
417
						$(this).children('.delete').hide(0);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
418
				});
419
420
				$('#mainui #memberslist .table .delete').on('click', function () {
421
					var member = $(this).parent().attr('member-id');
422
					api.removeMember(self.currentCircle, member, self.removeMemberResult);
423
				});
424
			};
425
426
427
			this.removeMemberResult = function (result) {
428
				if (result.status == 1) {
429
430
					$('#mainui #memberslist .table').children().each(function () {
431
						if ($(this).attr('member-id') == result.name)
432
							$(this).hide(300);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
433
					});
434
435
					OCA.notification.onSuccess(
436
						"Member '" + result.name + "' successfully removed from the circle");
437
				}
438
				else
439
					OCA.notification.onFail(
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
440
						"Member '" + result.name + "' NOT removed from the circle: " +
441
						((result.error) ? result.error : 'no error message'));
442
443
			};
444
445
446
			this.joinCircleResult = function (result) {
447
				if (result.status == 1) {
448
449
					$('#mainui #memberslist .table').children().each(function () {
450
						if ($(this).attr('member-id') == result.name)
451
							$(this).hide(300);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
452
					});
453
454
					if (result.member.level == 1)
455
						OCA.notification.onSuccess(
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
456
							"You have successfully joined this circle");
457
					else
458
						OCA.notification.onSuccess(
459
							"You have requested an invitation to join this circle");
460
					self.selectCircle(result.circle_id);
461
462
				}
463
				else
464
					OCA.notification.onFail(
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
465
						"Cannot join this circle: " +
466
						((result.error) ? result.error : 'no error message'));
467
			};
468
469
			this.leaveCircleResult = function (result) {
470
				if (result.status == 1) {
471
472
					$('#mainui #memberslist .table').children().each(function () {
473
						if ($(this).attr('member-id') == result.name)
474
							$(this).hide(300);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
475
					});
476
477
					OCA.notification.onSuccess(
478
						"You have successfully left this circle");
479
480
					self.selectCircle(result.circle_id);
481
				}
482
				else
483
					OCA.notification.onFail(
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
484
						"Cannot leave this circle: " +
485
						((result.error) ? result.error : 'no error message'));
486
			};
487
488
			// getCurrentCircleTemplate: function (id) {
489
			//
490
			// 	currdiv = null;
491
			// 	$('#app-navigation.circles').children().each(function () {
492
			// 		if ($(this).attr('circle-id') == id) {
493
			// 			currdiv = $(this);
494
			// 			return false;
495
			// 		}
496
			// 	});
497
			// 	return currdiv;
498
			// }
499
		}
500
	};
501
502
503
	/**
504
	 * @constructs Notification
505
	 */
506
	var Notification = function () {
507
		this.initialize();
508
	};
509
510
	Notification.prototype = {
511
512
		initialize: function () {
513
514
			notyf = null;
0 ignored issues
show
Bug introduced by
The variable notyf seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.notyf.
Loading history...
515
516
			this.notyf = new Notyf({
0 ignored issues
show
Bug introduced by
The variable Notyf seems to be never declared. If this is a global, consider adding a /** global: Notyf */ 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...
517
				delay: 5000
518
			});
519
520
			this.onSuccess = function (text) {
521
				this.notyf.confirm(text);
522
			};
523
524
			this.onFail = function (text) {
525
				this.notyf.alert(text);
526
			}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
527
528
		}
529
530
	};
531
532
	OCA.Circles.Navigation = Navigation;
533
	OCA.Circles.navigation = new Navigation();
534
535
	OCA.Notification = Notification;
536
	OCA.notification = new Notification();
537
538
});
539
540