Completed
Push — tests ( 8a2ad8...855120 )
by Maxence
02:33
created

elements.initExperienceMemberDetails   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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.circlesDetails = $('#circle_details');
69
		elements.emptyContent = $('#emptycontent');
70
		elements.mainUI = $('#mainui');
71
		elements.mainUIMembers = $('#memberslist_table');
72
		elements.membersSearchResult = $('#members_search_result');
73
		elements.memberDetails = $('#memberdetails');
74
		elements.memberRequest = $('#member_request');
75
76
		elements.joinCircleInteraction = $('#sjoincircle_interact');
77
		elements.joinCircleAccept = $('#joincircle_acceptinvit');
78
		elements.joinCircleReject = $('#joincircle_rejectinvit');
79
		elements.joinCircleRequest = $('#joincircle_request');
80
		elements.joinCircleInvite = $('#joincircle_invit');
81
		elements.joinCircle = $('#joincircle');
82
		elements.leaveCircle = $('#leavecircle');
83
		elements.rightPanel = $('#rightpanel');
84
		elements.addMember = $('#addmember');
85
		elements.remMember = $('#remmember');
86
	},
87
88
89
	initTweaks: function () {
90
		$.fn.emptyTable = function () {
91
			this.children('tr').each(function () {
92
				if ($(this).attr('class') != 'header') {
93
					$(this).remove();
94
				}
95
			});
96
		};
97
	},
98
99
100
	initUI: function () {
101
		elements.newTypeDefinition.children('div').fadeOut(0);
102
		$('#circles_new_type_' + elements.newType.children('option:selected').val()).fadeIn(
103
			0);
104
105
		elements.newType.hide();
106
		elements.newSubmit.hide();
107
		elements.newTypeDefinition.hide();
108
109
		$('.icon-circles').css('background-image',
110
			'url(' + OC.imagePath('circles', 'colored') + ')');
111
112
		var theme = $('#body-user').find('#header').css('background-color');
113
		elements.circlesList.css('background-color', theme);
114
		elements.circlesDetails.css('background-color', theme);
115
		elements.rightPanel.css('background-color', theme);
116
117
		elements.membersSearchResult.hide();
118
	},
119
120
121
	/**
122
	 *
123
	 */
124
	initExperienceCirclesList: function () {
125
126
		elements.circlesList.children('div').on('click', function () {
127
			nav.displayCirclesList($(this).attr('circle-type'));
128
		});
129
130
		this.circlesSearch.on('input propertychange paste focus', function () {
131
			var search = $(this).val().trim();
132
			if (curr.searchCircle == search) {
133
				return;
134
			}
135
136
			curr.searchCircle = search;
137
			api.searchCircles(curr.circlesType, search, actions.listCirclesResult);
138
		});
139
	},
140
141
142
	initExperienceMemberDetails: function () {
143
		elements.memberRequest.hide();
144
		elements.remMember.on('click', function () {
145
			api.removeMember(curr.circle, curr.member, actions.removeMemberResult);
146
		});
147
148
		$('#joincircle_acceptrequest').on('click', function () {
149
			api.addMember(curr.circle, curr.member, actions.addMemberResult);
150
		});
151
		$('#joincircle_rejectrequest').on('click', function () {
152
			api.removeMember(curr.circle, curr.member, actions.removeMemberResult);
153
		});
154
155
	},
156
157
158
	/**
159
	 *
160
	 */
161
	initAnimationNewCircle: function () {
162
163
		elements.newName.on('keyup', function () {
164
			actions.onEventNewCircleName();
165
		});
166
167
		elements.newType.on('change', function () {
168
			actions.onEventNewCircleType();
169
		});
170
171
		elements.newSubmit.on('click', function () {
172
			api.createCircle(elements.newType.val(), elements.newName.val(),
173
				actions.createCircleResult);
174
		});
175
176
	},
177
178
179
	fillMembersSearch: function (exact, partial) {
180
		this.fillExactMembersSearch(exact);
181
		this.fillPartialMembersSearch(partial);
182
		elements.membersSearchResult.children().first().css('border-top-width', '0px');
183
	},
184
185
	fillExactMembersSearch: function (exact) {
186
187
		$.each(exact, function (index, value) {
188
			elements.membersSearchResult.append(
189
				'<div class="members_search exact" searchresult="' +
190
				value.value.shareWith + '">' + value.label + '   (' +
191
				value.value.shareWith + ')</div>');
192
		});
193
194
	},
195
196
	fillPartialMembersSearch: function (partial) {
197
		$.each(partial, function (index, value) {
198
			var currSearch = elements.addMember.val().trim();
199
			var line = value.label + '   (' + value.value.shareWith + ')';
200
			if (currSearch.length > 0) {
201
				line =
202
					line.replace(new RegExp('(' + currSearch + ')', 'gi'),
203
						'<b>$1</b>');
204
			}
205
206
			elements.membersSearchResult.append(
207
				'<div class="members_search" searchresult="' +
208
				value.value.shareWith +
209
				'">' + line + '</div>');
210
		});
211
212
	},
213
214
215
	resetCirclesList: function () {
216
217
		elements.navigation.addClass('selected');
218
		elements.navigation.children().each(function () {
219
			if ($(this).attr('id') != 'circles_search') {
220
				$(this).remove();
221
			}
222
		});
223
	},
224
225
226
	removeMemberslistEntry: function (membername) {
227
		this.mainUIMembers.children("[member-id='" + membername + "']").each(
228
			function () {
229
				$(this).hide(300);
230
			});
231
	},
232
233
234
	generateTmplCircle: function (entry) {
235
		var tmpl = $('#tmpl_circle').html();
236
237
		tmpl = tmpl.replace(/%title%/g, entry.name);
238
		tmpl = tmpl.replace(/%type%/g, entry.type);
239
		tmpl = tmpl.replace(/%owner%/g, entry.owner.user_id);
240
		tmpl = tmpl.replace(/%status%/g, entry.user.status);
241
		tmpl = tmpl.replace(/%level_string%/g, entry.user.level_string);
242
		tmpl = tmpl.replace(/%count%/g, entry.count);
243
		tmpl = tmpl.replace(/%creation%/g, entry.creation);
244
245
		return tmpl;
246
	},
247
248
249
	generateTmplMember: function (entry) {
250
		var tmpl = $('#tmpl_member').html();
251
252
		tmpl = tmpl.replace(/%username%/g, entry.user_id);
253
		tmpl = tmpl.replace(/%level%/g, entry.level);
254
		tmpl = tmpl.replace(/%levelstring%/g, entry.level_string);
255
		tmpl = tmpl.replace(/%status%/g, entry.status);
256
		tmpl = tmpl.replace(/%joined%/g, entry.joined);
257
		tmpl = tmpl.replace(/%note%/g, entry.note);
258
259
		return tmpl;
260
	}
261
262
263
};