Completed
Push — federated-circles ( 983050...ca77de )
by Maxence
02:51
created

elements.emptyCircleCreation   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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