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

js/circles.app.elements.js   A

Complexity

Total Complexity 27
Complexity/F 1.17

Size

Lines of Code 201
Function Count 23

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 201
rs 10
wmc 27
mnd 1
bc 27
fnc 23
bpm 1.1739
cpm 1.1739
noi 2

12 Functions

Rating   Name   Duplication   Size   Complexity  
A elements.initExperienceCirclesList 0 16 1
A elements.fillPartialMembersSearch 0 17 1
A elements.initElements 0 22 1
A elements.removeMemberslistEntry 0 6 1
A elements.fillMembersSearch 0 5 1
A elements.resetCirclesList 0 9 1
A elements.initUI 0 14 1
A elements.generateTmplMember 0 12 1
A elements.fillExactMembersSearch 0 10 1
A elements.generateTmplCircle 0 13 1
A elements.initTweaks 0 9 1
A elements.initAnimationNewCircle 0 16 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
/** global: Notyf */
29
30
/** global: nav */
31
/** global: actions */
32
/** global: curr */
33
/** global: api */
34
35
36
var elements = {
37
38
	newTypeDefinition: null,
39
	newType: null,
40
	newSubmit: null,
41
	newName: null,
42
	navigation: null,
43
	circlesList: null,
44
	circlesSearch: null,
45
	emptyContent: null,
46
	mainUI: null,
47
	mainUIMembers: null,
48
	membersSearchResult: null,
49
50
	joinCircleAccept: null,
51
	joinCircleReject: null,
52
	joinCircleRequest: null,
53
	joinCircleInvite: null,
54
	joinCircle: null,
55
	leaveCircle: null,
56
	addMember: null,
57
58
59
	initElements: function () {
60
61
		elements.newTypeDefinition = $('#circles_new_type_definition');
62
		elements.newType = $('#circles_new_type');
63
		elements.newSubmit = $('#circles_new_submit');
64
		elements.newName = $('#circles_new_name');
65
		elements.navigation = $('#app-navigation.circles');
66
		elements.circlesList = $('#circles_list');
67
		elements.circlesSearch = $('#circles_search');
68
		elements.emptyContent = $('#emptycontent');
69
		elements.mainUI = $('#mainui');
70
		elements.mainUIMembers = $('#memberslist_table');
71
		elements.membersSearchResult = $('#members_search_result');
72
73
		elements.joinCircleAccept = $('#joincircle_acceptinvit');
74
		elements.joinCircleReject = $('#joincircle_rejectinvit');
75
		elements.joinCircleRequest = $('#joincircle_request');
76
		elements.joinCircleInvite = $('#joincircle_invit');
77
		elements.joinCircle = $('#joincircle');
78
		elements.leaveCircle = $('#leavecircle');
79
		elements.addMember = $('#addmember');
80
	},
81
82
83
	initTweaks: function () {
84
		$.fn.emptyTable = function () {
85
			this.children('tr').each(function () {
86
				if ($(this).attr('class') != 'header') {
87
					$(this).remove();
88
				}
89
			});
90
		};
91
	},
92
93
94
	initUI: function () {
95
		elements.newTypeDefinition.children('div').fadeOut(0);
96
		$('#circles_new_type_' + elements.newType.children('option:selected').val()).fadeIn(
97
			0);
98
99
		elements.newType.hide();
100
		elements.newSubmit.hide();
101
		elements.newTypeDefinition.hide();
102
103
		$('.icon-circles').css('background-image',
104
			'url(' + OC.imagePath('circles', 'colored') + ')');
105
106
		elements.membersSearchResult.hide();
107
	},
108
109
110
	/**
111
	 *
112
	 */
113
	initExperienceCirclesList: function () {
114
115
		elements.circlesList.children('div').on('click', function () {
116
			nav.displayCirclesList($(this).attr('circle-type'));
117
		});
118
119
		this.circlesSearch.on('input propertychange paste focus', function () {
120
			var search = $(this).val().trim();
121
			if (curr.searchCircle == search) {
122
				return;
123
			}
124
125
			curr.searchCircle = search;
126
			api.searchCircles(curr.circlesType, search, actions.listCirclesResult);
127
		});
128
	},
129
130
	/**
131
	 *
132
	 */
133
	initAnimationNewCircle: function () {
134
135
		elements.newName.on('keyup', function () {
136
			actions.onEventNewCircleName();
137
		});
138
139
		elements.newType.on('change', function () {
140
			actions.onEventNewCircleType();
141
		});
142
143
		elements.newSubmit.on('click', function () {
144
			api.createCircle(elements.newType.val(), elements.newName.val(),
145
				actions.createCircleResult);
146
		});
147
148
	}
0 ignored issues
show
Bug introduced by
There seems to be a bad line break before ,.
Loading history...
149
	,
0 ignored issues
show
introduced by
Comma warnings can be turned off with 'laxcomma'.
Loading history...
150
151
152
	fillMembersSearch: function (exact, partial) {
153
		this.fillExactMembersSearch(exact);
154
		this.fillPartialMembersSearch(partial);
155
		elements.membersSearchResult.children().first().css('border-top-width', '0px');
156
	},
157
158
	fillExactMembersSearch: function (exact) {
159
160
		$.each(exact, function (index, value) {
161
			elements.membersSearchResult.append(
162
				'<div class="members_search exact" searchresult="' +
163
				value.value.shareWith + '">' + value.label + '   (' +
164
				value.value.shareWith + ')</div>');
165
		});
166
167
	},
168
169
	fillPartialMembersSearch: function (partial) {
170
		$.each(partial, function (index, value) {
171
			var currSearch = $('#addmember').val().trim();
172
			var line = value.label + '   (' + value.value.shareWith + ')';
173
			if (currSearch.length > 0) {
174
				line =
175
					line.replace(new RegExp('(' + currSearch + ')', 'gi'),
176
						'<b>$1</b>');
177
			}
178
179
			elements.membersSearchResult.append(
180
				'<div class="members_search" searchresult="' +
181
				value.value.shareWith +
182
				'">' + line + '</div>');
183
		});
184
185
	},
186
187
188
	resetCirclesList: function () {
189
190
		elements.navigation.addClass('selected');
191
		elements.navigation.children().each(function () {
192
			if ($(this).attr('id') != 'circles_search') {
193
				$(this).remove();
194
			}
195
		});
196
	},
197
198
199
	removeMemberslistEntry: function (membername) {
200
		this.mainUIMembers.children("[member-id='" + membername + "']").each(
201
			function () {
202
				$(this).hide(300);
203
			});
204
	},
205
206
207
	generateTmplCircle: function (entry) {
208
		var tmpl = $('#tmpl_circle').html();
209
210
		tmpl = tmpl.replace(/%title%/, entry.name);
211
		tmpl = tmpl.replace(/%type%/, entry.type);
212
		tmpl = tmpl.replace(/%owner%/, entry.owner.user_id);
213
		tmpl = tmpl.replace(/%status%/, entry.user.status);
214
		tmpl = tmpl.replace(/%level_string%/, entry.user.level_string);
215
		tmpl = tmpl.replace(/%count%/, entry.count);
216
		tmpl = tmpl.replace(/%creation%/, entry.creation);
217
218
		return tmpl;
219
	},
220
221
222
	generateTmplMember: function (entry) {
223
		var tmpl = $('#tmpl_member').html();
224
225
		tmpl = tmpl.replace(/%username%/g, entry.user_id);
226
		tmpl = tmpl.replace(/%level%/g, entry.level);
227
		tmpl = tmpl.replace(/%levelstring%/g, entry.level_string);
228
		tmpl = tmpl.replace(/%status%/, entry.status);
229
		tmpl = tmpl.replace(/%joined%/, entry.joined);
230
		tmpl = tmpl.replace(/%note%/, entry.note);
231
232
		return tmpl;
233
	},
234
235
236
};