Completed
Push — js-scrutinizing ( b30283...91fb03 )
by Maxence
02:14
created

js/circles.app.navigation.js   A

Complexity

Total Complexity 22
Complexity/F 1.83

Size

Lines of Code 139
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 139
rs 10
wmc 22
mnd 1
bc 24
fnc 12
bpm 2
cpm 1.8333
noi 2

9 Functions

Rating   Name   Duplication   Size   Complexity  
A nav.displayMembersInteraction 0 20 4
A nav.displayRequestingMemberInteraction 0 5 1
A nav.displayCirclesList 0 20 1
A nav.displayMembersAsModerator 0 13 2
A nav.displayNonMemberInteraction 0 19 3
A nav.displayMembers 0 15 3
A nav.displayInvitedMemberInteraction 0 7 1
A nav.resetCirclesTypeSelection 0 8 1
A nav.displayOptionsNewCircle 0 12 2
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: nav */
31
/** global: elements */
32
/** global: curr */
33
/** global: api */
34
35
36
var nav = {
37
38
	displayCirclesList: function (type) {
39
40
		curr.circlesType = type;
41
		curr.searchCircle = '';
42
		curr.searchUser = '';
43
44
		curr.circle = 0;
45
		curr.circleLevel = 0;
46
47
		elements.navigation.show('slide', 800);
48
		elements.emptyContent.show(800);
49
		elements.mainUI.fadeOut(800);
50
51
		elements.circlesSearch.val('');
52
		elements.addMember.val('');
53
54
		this.resetCirclesTypeSelection(type);
55
		elements.resetCirclesList();
56
		api.listCircles(type, actions.listCirclesResult);
0 ignored issues
show
Bug introduced by
The variable actions seems to be never declared. If this is a global, consider adding a /** global: actions */ 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...
57
	},
58
59
60
	resetCirclesTypeSelection: function (type) {
61
		elements.circlesList.children('div').removeClass('selected');
62
		elements.circlesList.children().each(function () {
63
			if ($(this).attr('circle-type') == type.toLowerCase()) {
64
				$(this).addClass('selected');
65
			}
66
		});
67
	},
68
69
	/**
70
	 *
71
	 * @param display
72
	 */
73
	displayOptionsNewCircle: function (display) {
74
		if (display) {
75
			elements.newType.fadeIn(300);
76
			elements.newSubmit.fadeIn(500);
77
			elements.newTypeDefinition.fadeIn(700);
78
		}
79
		else {
80
			elements.newType.fadeOut(700);
81
			elements.newSubmit.fadeOut(500);
82
			elements.newTypeDefinition.fadeOut(300);
83
		}
84
	},
85
86
87
	displayMembers: function (members) {
88
89
		elements.mainUIMembers.emptyTable();
90
		if (members === null) {
91
			elements.mainUIMembers.hide(200);
92
			return;
93
		}
94
95
		elements.mainUIMembers.show(200);
96
		for (var i = 0; i < members.length; i++) {
97
			elements.mainUIMembers.append(elements.generateTmplMember(members[i]));
98
		}
99
100
		this.displayMembersAsModerator();
101
	},
102
103
104
	displayMembersAsModerator: function () {
105
		if (curr.circleLevel >= 6) {
106
107
			elements.mainUIMembers.children("[member-level!='9']").each(function () {
108
				$(this).children('.delete').show(0);
109
110
				var member = $(this).attr('member-id');
111
				$(this).children('.delete').on('click', function () {
112
					api.removeMember(curr.circle, member, actions.removeMemberResult);
0 ignored issues
show
Bug introduced by
The variable actions seems to be never declared. If this is a global, consider adding a /** global: actions */ 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
118
119
	displayMembersInteraction: function (details) {
120
		if (details.user.level < 6) {
121
			elements.addMember.hide();
122
		} else {
123
			elements.addMember.show();
124
		}
125
126
		this.displayNonMemberInteraction(details);
127
128
		if (details.user.level == 9) {
129
			elements.joinCircle.hide();
130
			elements.leaveCircle.hide();
131
			return;
132
		}
133
134
		if (details.user.level >= 1) {
135
			elements.joinCircle.hide();
136
			elements.leaveCircle.show();
137
		}
138
	},
139
140
	displayNonMemberInteraction: function (details) {
141
		elements.joinCircleAccept.hide();
142
		elements.joinCircleReject.hide();
143
		elements.joinCircleRequest.hide();
144
		elements.joinCircleInvite.hide();
145
146
		if (details.user.status == 'Invited') {
147
			this.displayInvitedMemberInteraction();
148
			return;
149
		}
150
151
		if (details.user.status == 'Requesting') {
152
			this.displayRequestingMemberInteraction();
153
			return;
154
		}
155
156
		elements.joinCircle.show();
157
		elements.leaveCircle.hide();
158
	},
159
160
	displayInvitedMemberInteraction: function () {
161
		elements.joinCircleInvite.show();
162
		elements.joinCircleAccept.show();
163
		elements.joinCircleReject.show();
164
		elements.joinCircle.hide();
165
		elements.leaveCircle.hide();
166
	},
167
168
	displayRequestingMemberInteraction: function () {
169
		elements.joinCircleRequest.show();
170
		elements.joinCircle.hide();
171
		elements.leaveCircle.show();
172
	}
173
174
};
175
176