Completed
Push — master ( cd2326...65f97e )
by Maxence
03:06
created

elements.initExperienceCircleButtons   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
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: resultCircles */
33
/** global: curr */
34
/** global: api */
35
/** global: define */
36
37
var elements = {
38
39
	newTypeDefinition: null,
40
	newType: null,
41
	newSubmit: null,
42
	newName: null,
43
	navigation: null,
44
	circlesList: null,
45
	circlesSearch: null,
46
	circlesFilters: null,
47
	circlesDetails: null,
48
	emptyContent: null,
49
	mainUI: null,
50
	mainUIMembersTable: null,
51
	membersSearchResult: null,
52
	memberDetails: null,
53
	memberRequest: null,
54
55
	joinCircleInteraction: null,
56
	joinCircleAccept: null,
57
	joinCircleReject: null,
58
	joinCircleRequest: null,
59
	joinCircleInvite: null,
60
	joinCircle: null,
61
	leaveCircle: null,
62
	destroyCircle: null,
63
64
	rightPanel: null,
65
	addMember: null,
66
	remMember: null,
67
	linkCircle: null,
68
69
	buttonCircleActions: null,
70
	buttonCircleActionReturn: null,
71
	buttonCircleSettings: null,
72
	buttonAddMember: null,
73
	buttonLinkCircle: null,
74
75
76
	initElements: function () {
77
78
		elements.newTypeDefinition = $('#circles_new_type_definition');
79
		elements.newType = $('#circles_new_type');
80
		elements.newSubmit = $('#circles_new_submit');
81
		elements.newName = $('#circles_new_name');
82
		elements.navigation = $('#app-navigation.circles');
83
		elements.circlesList = $('#circles_list');
84
		elements.circlesSearch = $('#circles_search');
85
		elements.circlesFilters = $('#circles_filters');
86
		elements.circlesDetails = $('#circle_details');
87
		elements.emptyContent = $('#emptycontent');
88
		elements.mainUI = $('#mainui');
89
90
		elements.mainUIMembers = $('#memberslist');
91
		elements.mainUIMembersTable = $('#memberslist_table');
92
		elements.membersSearchResult = $('#members_search_result');
93
		elements.memberDetails = $('#memberdetails');
94
		elements.memberRequest = $('#member_request');
95
96
		elements.joinCircleInteraction = $('#sjoincircle_interact');
97
		elements.joinCircleAccept = $('#joincircle_acceptinvit');
98
		elements.joinCircleReject = $('#joincircle_rejectinvit');
99
		elements.joinCircleRequest = $('#joincircle_request');
100
		elements.joinCircleInvite = $('#joincircle_invit');
101
		elements.joinCircle = $('#joincircle');
102
		elements.leaveCircle = $('#leavecircle');
103
		elements.destroyCircle = $('#circle-actions-delete');
104
105
		elements.settingsPanel = $('#settings-panel');
106
		elements.rightPanel = $('#rightpanel');
107
		elements.addMember = $('#addmember');
108
		elements.remMember = $('#remmember');
109
		elements.linkCircle = $('#linkcircle');
110
111
		elements.buttonCircleActions = $('#circle-actions-buttons');
112
		elements.buttonCircleActionReturn = $('#circle-actions-return');
113
		elements.buttonCircleSettings = $('#circle-actions-settings');
114
		elements.buttonAddMember = $('#circle-actions-add');
115
		elements.buttonLinkCircle = $('#circle-actions-link');
116
		elements.buttonJoinCircle = $('#circle-actions-join');
117
	},
118
119
120
	initTweaks: function () {
121
		$.fn.emptyTable = function () {
122
			this.children('tr').each(function () {
123
				if ($(this).attr('class') !== 'header') {
124
					$(this).remove();
125
				}
126
			});
127
		};
128
	},
129
130
131
	initUI: function () {
132
		elements.newTypeDefinition.children('div').fadeOut(0);
133
		$('#circles_new_type_' + elements.newType.children('option:selected').val()).fadeIn(
134
			0);
135
136
		elements.newType.hide();
137
		elements.newSubmit.hide();
138
		elements.newTypeDefinition.hide();
139
140
		$('.icon-circles').css('background-image',
141
			'url(' + OC.imagePath('circles', 'colored') + ')');
142
143
		var theme = $('#body-user').find('#header').css('background-color');
144
		elements.circlesList.css('background-color', theme);
145
		elements.circlesDetails.css('background-color', theme);
146
		elements.rightPanel.css('background-color', theme);
147
148
		elements.membersSearchResult.hide();
149
	},
150
151
152
	/**
153
	 *
154
	 */
155
	initExperienceCirclesList: function () {
156
157
		elements.circlesList.children('div').on('click', function () {
158
			nav.displayCirclesList($(this).attr('circle-type'));
159
		});
160
161
		this.initExperienceCirclesListFromSearch();
162
		this.initExperienceCirclesListFromFilter();
163
	},
164
165
166
	initExperienceCirclesListFromSearch: function () {
167
168
		this.circlesSearch.on('input property paste focus', function () {
169
			var search = $(this).val().trim();
170
			if (curr.searchCircle === search) {
171
				return;
172
			}
173
174
			curr.searchCircle = search;
175
			api.listCircles(curr.circlesType, curr.searchCircle, curr.searchFilter,
176
				resultCircles.listCirclesResult);
177
		});
178
	},
179
180
181
	initExperienceCirclesListFromFilter: function () {
182
183
		this.circlesFilters.on('input property paste focus', function () {
184
			var searchFilter = $(this).val();
185
			if (curr.searchFilter === searchFilter) {
186
				return;
187
			}
188
189
			curr.searchFilter = searchFilter;
190
			api.listCircles(curr.circlesType, curr.searchCircle, curr.searchFilter,
191
				resultCircles.listCirclesResult);
192
		});
193
194
	},
195
196
197
	/**
198
	 *
199
	 */
200
	initExperienceCircleButtons: function () {
201
202
		elements.buttonCircleActionReturn.hide();
203
		elements.buttonCircleActionReturn.on('click', function () {
204
			nav.circlesActionReturn();
205
		});
206
207
		elements.buttonAddMember.on('click', function () {
208
			nav.displaySettings(false);
209
			nav.displayCircleButtons(false);
210
			nav.displayAddMemberInput(true);
211
			nav.displayLinkCircleInput(false);
212
			nav.displayJoinCircleButton(false);
213
		});
214
215
		elements.buttonLinkCircle.on('click', function () {
216
			nav.displaySettings(false);
217
			nav.displayCircleButtons(false);
218
			nav.displayAddMemberInput(false);
219
			nav.displayLinkCircleInput(true);
220
			nav.displayJoinCircleButton(false);
221
		});
222
223
		elements.buttonCircleSettings.on('click', function () {
224
			nav.displaySettings(true);
225
			nav.displayCircleButtons(false);
226
			nav.displayAddMemberInput(false);
227
			nav.displayLinkCircleInput(false);
228
			nav.displayJoinCircleButton(false);
229
		});
230
231
		elements.buttonJoinCircle.on('click', function () {
232
			nav.joinCircleAction();
233
		});
234
235
236
	},
237
238
239
	/**
240
	 *
241
	 */
242
	initAnimationNewCircle: function () {
243
244
		elements.newName.on('keyup', function () {
245
			actions.onEventNewCircleName();
246
		});
247
248
		elements.newType.on('change', function () {
249
			actions.onEventNewCircleType();
250
		});
251
252
		elements.newSubmit.on('click', function () {
253
			api.createCircle(elements.newType.val(), elements.newName.val(),
254
				resultCircles.createCircleResult);
255
		});
256
257
	},
258
259
260
	emptyCircleCreation: function () {
261
		elements.newName.val('');
262
		elements.newType.val('');
263
	},
264
265
	fillMembersSearch: function (exact, partial) {
266
		this.fillExactMembersSearch(exact);
267
		this.fillPartialMembersSearch(partial);
268
		elements.membersSearchResult.children().first().css('border-top-width', '0px');
269
	},
270
271
272
	fillExactMembersSearch: function (exact) {
273
		$.each(exact, function (index, value) {
274
			elements.membersSearchResult.append(
275
				'<div class="members_search exact" searchresult="' +
276
				escapeHTML(value.value.shareWith) + '">' + escapeHTML(value.label) + '   (' +
277
				escapeHTML(value.value.shareWith) + ')</div>');
278
		});
279
280
	},
281
282
283
	fillPartialMembersSearch: function (partial) {
284
		$.each(partial, function (index, value) {
285
			var currSearch = elements.addMember.val().trim();
286
			var line = escapeHTML(value.label) + '   (' + escapeHTML(value.value.shareWith) + ')';
287
			if (currSearch.length > 0) {
288
				line = line.replace(new RegExp('(' + currSearch + ')', 'gi'), '<b>$1</b>');
289
			}
290
291
			elements.membersSearchResult.append(
292
				'<div class="members_search" searchresult="' + escapeHTML(value.value.shareWith) +
293
				'">' + line +
294
				'</div>');
295
		});
296
297
	},
298
299
300
	resetCirclesList: function () {
301
302
		elements.navigation.addClass('selected');
303
		elements.navigation.children().each(function () {
304
			if ($(this).attr('id') !== 'circles_search' &&
305
				$(this).attr('id') !== 'circles_filters') {
306
				$(this).remove();
307
			}
308
		});
309
	},
310
311
312
	removeMemberslistEntry: function (membername) {
313
		this.mainUIMembersTable.children("[member-id='" + escapeHTML(membername) + "']").each(
314
			function () {
315
				$(this).hide(300);
316
			});
317
	},
318
319
320
	generateTmplCircle: function (entry) {
321
		var tmpl = $('#tmpl_circle').html();
322
323
		tmpl = tmpl.replace(/%title%/g, escapeHTML(entry.name));
324
		tmpl = tmpl.replace(/%type%/g, t('circles', escapeHTML(entry.type)));
325
		tmpl = tmpl.replace(/%owner%/g, escapeHTML(entry.owner.user_id));
326
		tmpl = tmpl.replace(/%status%/g, t('circles', escapeHTML(entry.user.status)));
327
		tmpl = tmpl.replace(/%level_string%/g, t('circles', escapeHTML(entry.user.level_string)));
328
		tmpl = tmpl.replace(/%creation%/g, escapeHTML(entry.creation));
329
330
		return tmpl;
331
	},
332
333
334
	generateTmplMember: function (entry) {
335
		var tmpl = $('#tmpl_member').html();
336
337
		tmpl = tmpl.replace(/%username%/g, escapeHTML(entry.user_id));
338
		tmpl = tmpl.replace(/%level%/g, escapeHTML(entry.level));
339
		tmpl = tmpl.replace(/%status%/g, escapeHTML(entry.status));
340
		tmpl = tmpl.replace(/%joined%/g, escapeHTML(entry.joined));
341
342
		return tmpl;
343
	}
344
345
346
};