Passed
Push — dartcafe-patch-1 ( f494f9...656c1d )
by René
02:22
created

create_edit.js ➔ deselectItem   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 24
rs 8.6845
1
var g_chosen_datetimes = [];
2
var g_chosen_texts = [];
3
var g_chosen_groups = [];
4
var g_chosen_users = [];
5
var chosen_type = 'event';
6
var access_type = '';
7
var isAnonymous;
8
var hideNames;
9
10
function selectItem(cell) {
11
	cell.removeClass('icon-close');
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
12
	cell.addClass('icon-checkmark');
13
	cell.removeClass('date-text-not-selected');
14
	cell.addClass('date-text-selected');
15
	if (cell.attr('class').indexOf('is-text') > -1) {
16
		var id = cell.attr('id');
17
		g_chosen_texts.push(id.substring(id.indexOf('_') + 1));
18
	} else {
19
		var dateId = cell.parent().attr('id'); //timestamp of date
20
		var timeId = cell.attr('id');
21
		g_chosen_datetimes.push(parseInt(dateId) + parseInt(timeId));
22
	}
23
}
24
25
function deselectItem(cell) {
26
	var id;
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
27
	var index;
28
	var dateId;
29
	var timeId;
30
	cell.removeClass('icon-checkmark');
31
	cell.addClass('icon-close');
32
	cell.removeClass('date-text-selected');
33
	cell.addClass('date-text-not-selected');
34
	if (cell.attr('class').indexOf('is-text') > -1) {
35
		id = cell.attr('id');
36
		index = g_chosen_texts.indexOf(id.substring(id.indexOf('_') + 1));
37
		if (index > -1) {
38
			g_chosen_texts.splice(index, 1);
39
		}
40
	} else {
41
		dateId = cell.parent().attr('id'); //timestamp of date
42
		timeId = cell.attr('id');
43
		index = g_chosen_datetimes.indexOf(parseInt(dateId) + parseInt(timeId));
44
		if (index > -1) {
45
			g_chosen_datetimes.splice(index, 1);
46
		}
47
	}
48
}
49
50
function insertText(text, set) {
51
	if (typeof set === 'undefined') {
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
52
		set = false;
53
	}
54
	var table = document.getElementById('selected-texts-table');
55
	var tr = table.insertRow(-1);
56
	var td = tr.insertCell(-1);
57
	td.innerHTML = text;
58
	td.className = 'text-row';
59
	td = tr.insertCell(-1);
60
	if (set) {
61
		td.className = 'icon-checkmark is-text date-text-selected';
62
	} else {
63
		td.className = 'icon-close is-text date-text-not-selected';
64
	}
65
	td.id = 'text_' + text;
66
}
67
68
function addRowToList(ts, text, timeTs) {
69
	if (typeof timeTs === 'undefined') {
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
70
		timeTs = -1;
71
	}
72
	var table = document.getElementById('selected-dates-table');
73
	var rows = table.rows;
74
	var td, tr, tdId;
75
	var i, j;
76
	var curr;
77
	if (rows.length == 0) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
78
		tr = table.insertRow(-1); //start new header
79
		tr.insertCell(-1);
80
		tr = table.insertRow(-1); //append new row
81
		tr.id = ts;
82
		tr.className = 'toggleable-row';
83
		td = tr.insertCell(-1);
84
		td.className = 'date-row';
85
		td.innerHTML = text;
86
		return;
87
	}
88
	for ( i=1; i<rows.length; i++) {
89
		curr = rows[i];
90
		if (curr.id == ts) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
91
			for (j=1; j<curr.cells.length; j++) {
92
				td = curr.cells[j];
93
				 tdId = curr.cells[j].id;
94
				if ( timeTs == tdId) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
95
					td.className = 'icon-checkmark date-text-selected';
96
				}
97
			}
98
			return; //already in table, cancel
99
		} else if (curr.id > ts) {
100
			tr = table.insertRow(i); //insert row at current index
101
			tr.id = ts;
102
			tr.className = 'toggleable-row';
103
			td = tr.insertCell(-1);
104
			td.className = 'date-row';
105
			td.innerHTML = text;
106
			for (j=1; j<rows[0].cells.length; j++) {
107
				tdId = rows[0].cells[j].id;
108
				td = tr.insertCell(-1);
109
				if (timeTs == tdId) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
110
					td.className = 'icon-checkmark date-text-selected';
111
				}  else { 
112
					td.className = 'icon-close date-text-not-selected';
113
				}
114
				td.id = tdId;
115
				td.innerHTML = '';
116
			}
117
			return;
118
		}
119
	}
120
	tr = table.insertRow(-1); //highest value, append new row
121
	tr.id = ts;
122
	tr.className = 'toggleable-row';
123
	td = tr.insertCell(-1);
124
	td.className = 'date-row';
125
	td.innerHTML = text;
126
	for (j=1; j<rows[0].cells.length; j++) {
127
		tdId = rows[0].cells[j].id;
128
		td = tr.insertCell(-1);
129
		if (timeTs == tdId) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
130
			td.className = 'icon-checkmark date-text-selected';
131
		} else {
132
			td.className = 'icon-close date-text-not-selected';
133
		}
134
		td.id = tdId;
135
		td.innerHTML = '';
136
	}
137
}
138
139
function addColToList(ts, text, dateTs) {
140
	if (typeof dateTs === 'undefined') {
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
141
		dateTs = -1;
142
	}
143
	var table = document.getElementById('selected-dates-table');
144
	var rows = table.rows;
145
	var tr, row, td, cells, tmpRow;
146
	var i, curr;
147
	var index = -1;
148
	if (rows.length == 0) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
149
		tr = table.insertRow(-1);
150
		tr.insertCell(-1);
151
	}
152
	rows = table.rows;
153
	tmpRow = rows[0];
154
	for (i=0; i<tmpRow.cells.length; i++) {
155
		curr = tmpRow.cells[i];
156
		if (curr.id == ts) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
157
			return; //already in table, cancel
158
		} else if (curr.id > ts) {
159
			index = i;
160
			break;
161
		}
162
	}
163
164
	for (i=0; i<rows.length; i++) {
165
		row = rows[i];
166
		cells = row.cells;
167
		td = row.insertCell(index);
168
		//only display time in header row
169
		if (i==0) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
170
			td.innerHTML = text;
171
			td.className = 'date-col';
172
		} else {
173
			td.innerHTML = '';
174
			if (row.id == dateTs) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
175
				td.className = 'icon-checkmark date-text-selected';
176
			} else { 
177
				td.className = 'icon-close date-text-not-selected';
178
			}
179
		}
180
		td.id = ts;
181
	}
182
}
183
184
function debounce(f, wait, immediate) {
185
	var timeout;
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
186
	return function() {
187
		var context = this;
188
		var args = arguments;
189
		var later = function() {
190
			timeout = null;
191
			if (!immediate) {
192
				f.apply(context, args);
193
			}
194
		};
195
		var callNow = immediate && !timeout;
196
		clearTimeout(timeout);
0 ignored issues
show
Bug introduced by
The variable timeout seems to not be initialized for all possible execution paths. Are you sure clearTimeout handles undefined variables?
Loading history...
197
		timeout = setTimeout(later, wait);
198
		if (callNow) {
199
			f.apply(context, args);
200
		}
201
	}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
202
}
203
204
$(document).ready(function () {
205
	// enable / disable date picker
206
	$('#id_expire_set').click(function(){
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
207
		$('#id_expire_date').prop("disabled", !this.checked);
208
		if (this.checked) {
209
		   $("#id_expire_date").focus();
210
		}
211
	});
212
213
	var anonOptions = document.getElementById('anonOptions');
214
	$('#hideNames').click(function() {
215
		hideNames = this.checked;
216
	});
217
218
	$('#isAnonymous').click(function() {
219
		isAnonymous = this.checked;
220
		if (isAnonymous) {
221
			anonOptions.style.display = 'inline';
222
		} else {
223
			anonOptions.style.display = 'none';
224
		}
225
	});
226
227
	var privateRadio = document.getElementById('private');
228
	var hiddenRadio = document.getElementById('hidden');
229
	var publicRadio = document.getElementById('public');
230
	var selectRadio = document.getElementById('select');
231
	if (privateRadio.checked) {
232
		access_type = 'registered';
233
	} else if (hiddenRadio.checked) {
234
		access_type = 'hidden';
235
	} else if (publicRadio.checked) {
236
		access_type = 'public';
237
	} else if (selectRadio.checked) {
238
		access_type = 'select';
239
	}
240
241
	isAnonymous = document.getElementById('isAnonymous').checked;
242
	hideNames = anonOptions.checked;
243
244
	var accessValues = document.getElementById('accessValues');
245
	if (accessValues.value.length > 0) {
246
		var list = document.getElementById('selected-search-list-id');
247
		var accessValueArr = accessValues.value.split(';');
248
		for (var i=0; i<accessValueArr.length; i++) {
249
			var val = accessValueArr[i];
250
			if (val == '') {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
251
				continue;
252
			}
253
			var li = document.createElement('li');
254
			li.id = val;
255
			li.className = 'cl_item cl_access_item selected';
256
			var index = val.indexOf('group_');
257
			if (index == 0) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
258
				g_chosen_groups.push(val);
259
				li.className += ' is-group';
260
				li.appendChild(document.createTextNode(val.substring(6) + " (group)"));
261
				list.appendChild(li);
262
			} else {
263
				index = val.indexOf('user_');
264
				if (index == 0) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
265
					g_chosen_users.push(val);
266
					li.className = 'cl_item cl_access_item selected';
267
					var username = val.substring(5);
268
					$.post(OC.generateUrl('/apps/polls/get/displayname'), {username: username}, function(data) {
0 ignored issues
show
Bug introduced by
It is generally not recommended to make functions within a loop.

While making functions in a loop will not lead to any runtime error, the code might not behave as you expect as the variables in the scope are not imported by value, but by reference. Let’s take a look at an example:

var funcs = [];
for (var i=0; i<10; i++) {
    funcs.push(function() {
        alert(i);
    });
}

funcs[0](); // alert(10);
funcs[1](); // alert(10);
/// ...
funcs[9](); // alert(10);

If you would instead like to bind the function inside the loop to the value of the variable during that specific iteration, you can create the function from another function:

var createFunc = function(i) {
    return function() {
        alert(i);
    };
};

var funcs = [];
for (var i=0; i<10; i++) {
    funcs.push(createFunc(i));
}

funcs[0](); // alert(0)
funcs[1](); // alert(1)
// ...
funcs[9](); // alert(9)
Loading history...
269
						li.appendChild(document.createTextNode(username + " (" + data + ")"));
0 ignored issues
show
Bug introduced by
The variable username is changed as part of the for loop for example by val.substring(5) on line 267. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
Bug introduced by
The variable li is changed as part of the for loop for example by document.createElement("li") on line 253. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
270
						list.appendChild(li);
271
					});
272
				}
273
			}
274
		}
275
	}
276
277
	var chosenDates = document.getElementById('chosenDates').value;
278
	var chosen = '';
279
	if (chosenDates.length > 0) {
280
		chosen = JSON.parse(chosenDates);
281
	}
282
	var text = document.getElementById('text');
283
	var event = document.getElementById('event');
284
	if (event.checked) {
285
		chosen_type = event.value;
286
		if (chosenDates.length > 0) {
287
			g_chosen_datetimes = chosen;
288
		}
289
		for (var i=0; i<chosen.length; i++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 248. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Bug introduced by
It seems like i was already defined.
Loading history...
290
			var date = new Date(chosen[i]*1000);
291
			var year = date.getFullYear();
292
			var month = date.getMonth();
293
			var day = date.getDate();
294
			var newDate = new Date(year, month, day).getTime(); //save timestamp without time of day
295
			month = '0' + (month+1); //month is 0-11, so +1
296
			day = '0' + day;
297
			var dateStr = day.substr(-2) + '.' + month.substr(-2) + '.' + year;
298
			var hours = date.getHours();
299
			var minutes = date.getMinutes();
300
			var ms = (hours * 60 * 60 * 1000) + (minutes * 60 * 1000); //time of day in milliseconds
301
			hours = '0' + hours;
302
			minutes = '0' + minutes;
303
			var timeStr = hours.substr(-2) + ':' + minutes.substr(-2);
304
			addRowToList(newDate/1000, dateStr, ms/1000);
305
			addColToList(ms/1000, timeStr, newDate/1000);
306
		}
307
	} else {
308
		chosen_type = text.value;
309
		if (chosenDates.length > 0) {
310
			g_chosen_texts = chosen;
311
		}
312
		for (var i=0; i<chosen.length; i++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 248. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Bug introduced by
It seems like i was already defined.
Loading history...
313
			insertText(chosen[i], true);
314
		}
315
	}
316
317
	var expirepicker = jQuery('#id_expire_date').datetimepicker({
0 ignored issues
show
Unused Code introduced by
The variable expirepicker seems to be never used. Consider removing it.
Loading history...
318
		inline: false,
319
		onSelectDate: function(date) {
320
			var year = date.getFullYear();
321
			var month = date.getMonth();
322
			var day = date.getDate();
323
			var newDate = new Date(year, month, day).getTime()/1000;
324
			document.getElementById('expireTs').value = newDate;
325
		},
326
		timepicker: false,
327
		format: 'd.m.Y'
328
	});
329
330
	var datepicker = jQuery('#datetimepicker').datetimepicker({
0 ignored issues
show
Unused Code introduced by
The variable datepicker seems to be never used. Consider removing it.
Loading history...
331
		inline:true,
332
		step: 15,
333
		todayButton: true,
334
		onSelectDate: function(date) {
335
			var year = date.getFullYear();
336
			var month = date.getMonth();
337
			var day = date.getDate();
338
			var newDate = new Date(year, month, day).getTime(); //save timestamp without time of day
339
			month = '0' + (month+1); //month is 0-11, so +1
340
			day = '0' + day;
341
			var dateStr = day.substr(-2) + '.' + month.substr(-2) + '.' + year;
342
			addRowToList(newDate/1000, dateStr);
343
		},
344
		onSelectTime: function(date) {
345
			var hours = date.getHours();
346
			var minutes = date.getMinutes();
347
			var ms = (hours * 60 * 60 * 1000) + (minutes * 60 * 1000); //time of day in milliseconds
348
			hours = '0' + hours;
349
			minutes = '0' + minutes;
350
			var timeStr = hours.substr(-2) + ':' + minutes.substr(-2);
351
			addColToList(ms/1000, timeStr);
352
		}
353
	});
354
355
	$(document).on('click', '.date-row', function() {
356
		var tr = $(this).parent();
357
		var dateId = parseInt(tr.attr('id'));
358
		var index = tr.index();
359
		var cells = tr[0].cells; //convert jQuery object to DOM
360
		for (var i=1; i<cells.length; i++) {
361
			var cell = cells[i];
362
			var delIndex = g_chosen_datetimes.indexOf(dateId + parseInt(cell.id));
363
			if (delIndex > -1) {
364
				g_chosen_datetimes.splice(delIndex, 1);
365
			}
366
		}
367
		var table = document.getElementById('selected-dates-table');
368
		table.deleteRow(index);
369
	});
370
371
	$(document).on('click', '.date-col', function() {
372
		var cellIndex = $(this).index();
373
		var timeId = parseInt($(this).attr('id'));
374
		var table = document.getElementById('selected-dates-table');
375
		var rows = table.rows;
376
		rows[0].deleteCell(cellIndex);
377
		for (var i=1; i<rows.length; i++) {
378
			var row = rows[i];
379
			var delIndex = g_chosen_datetimes.indexOf(parseInt(row.id) + timeId);
380
			if (delIndex > -1) {
381
				g_chosen_datetimes.splice(delIndex, 1);
382
			}
383
			row.deleteCell(cellIndex);
384
		}
385
	});
386
387
	$(document).on('click', '.text-row', function() {
388
		var tr = $(this).parent();
389
		var rowIndex = tr.index();
390
		var name = $(this).html();
391
		var delIndex = g_chosen_texts.indexOf(name);
392
		if (delIndex > -1) {
393
			g_chosen_texts.splice(delIndex, 1);
394
		}
395
		var table = document.getElementById('selected-texts-table');
396
		table.deleteRow(rowIndex);
397
	});
398
399
	$(document).on('click', '.icon-close', function() {
400
		selectItem($(this));
401
	});
402
403
	$(document).on('click', '.icon-checkmark', function() {
404
		deselectItem($(this));
405
	});
406
407
	$(document).on('click', '#text-submit', function() {
408
		var text = document.getElementById('text-title');
409
		if (text.value.length == 0) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
410
			alert('Please enter a text!');
411
			return false;
412
		}
413
		insertText(text.value);
414
		text.value = '';
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
415
	});
416
417
	$(document).on('click', '.cl_item', function() {
418
		var index;
419
		var list = document.getElementById('selected-search-list-id');
420
		var isGroup = $(this).hasClass('is-group');
421
		if ($(this).hasClass('selected')) {
422
			if (isGroup) {
423
				index = g_chosen_groups.indexOf(this.id);
424
			}
425
			else { 
426
				index = g_chosen_users.indexOf(this.id);
427
			}
428
			if (index > -1) {
429
				if (isGroup) {
430
					g_chosen_groups.splice(index, 1);
431
				}
432
				else {
433
					g_chosen_users.splice(index, 1);
434
				}
435
				$(this).remove();
436
			}
437
		} else {
438
			if (!isGroup) {
439
				var text = this.id.replace('user_', '');
440
				g_chosen_users.push(this.id);
441
			} else {
442
				g_chosen_groups.push(this.id);
443
			}
444
			document.getElementById('user-group-search-box').value = '';
445
			var li = document.createElement('li');
446
			li.id = this.id;
447
			li.className = 'cl_item cl_access_item selected' + (isGroup ? ' is-group' : '');
448
			if (!isGroup) {
449
				$.post(OC.generateUrl('/apps/polls/get/displayname'), {username: text}, function(data) {
0 ignored issues
show
Bug introduced by
The variable text seems to not be initialized for all possible execution paths.
Loading history...
Bug introduced by
The variable text seems to be used out of scope.

This error can usually be fixed by declaring the variable in the scope where it is used:

function someFunction() {
    (function() {
        var i = 0;
    })();

    // i is not defined.
    alert(i);
}

// This can be fixed by moving the var statement to the outer scope.

function someFunction() {
    var i;
    (function() {
        i = 1;
    })();

    alert(i);
};
Loading history...
450
					li.appendChild(document.createTextNode(text + " (" + data + ")"));
0 ignored issues
show
Bug introduced by
The variable text seems to not be initialized for all possible execution paths.
Loading history...
451
					list.appendChild(li);
452
				});
453
			} else {
454
				li.appendChild(document.createTextNode($(this).html()));
455
				list.appendChild(li);
456
			}
457
			$(this).remove();
458
		}
459
	});
460
461
	$('.toggleable-row').hover(
462
		function() {
463
			var td = this.insertCell(-1);
464
			td.className = 'toggle-all selected-all';
465
		}, function() {
466
			$(this).find('td:last-child').remove();
467
		}
468
	);
469
470
	$(document).on('click', '.toggle-all', function() {
471
		var children;
472
		var i;
473
		if ($(this).attr('class').indexOf('selected-all') > -1) {
474
			children = $(this).parent().children('.icon-checkmark');
475
			for (i=0; i<children.length; i++) {
476
				deselectItem($(children[i]));
477
			}
478
			$(this).removeClass('selected-all');
479
			$(this).addClass('selected-none');
480
		} else {
481
			children = $(this).parent().children('.icon-close');
482
			for (i=0; i<children.length; i++) {
483
				selectItem($(children[i]));
484
			}
485
			$(this).removeClass('selected-none');
486
			$(this).addClass('selected-all');
487
		}
488
	});
489
490
	$('input[type=radio][name=pollType]').change(function() {
491
		if (this.value == 'event') {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
492
			chosen_type = 'event';
493
			document.getElementById('text-select-container').style.display = 'none';
494
			document.getElementById('date-select-container').style.display = 'inline';
495
		} else {
496
			chosen_type = 'text';
497
			document.getElementById('text-select-container').style.display = 'inline';
498
			document.getElementById('date-select-container').style.display = 'none';
499
		}
500
	});
501
502
	$('input[type=radio][name=accessType]').click(function() {
503
		access_type = this.value;
504
		if (access_type == 'select') {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
505
			$("#access_rights").show();
506
			$("#selected_access").show();
507
		} else {
508
			$("#access_rights").hide();
509
			$("#selected_access").hide();
510
		}
511
	});
512
513
	$('input[type=checkbox][name=check_expire]').change(function() {
514
		if (!$(this).is(':checked')) {
515
			document.getElementById('expireTs').value = '';
516
		}
517
	});
518
519
	$('#user-group-search-box').on('input', debounce(function() {
520
		var ul = document.getElementById('live-search-list-id');
521
		while(ul.firstChild) {
522
			ul.removeChild(ul.firstChild);
523
		}
524
		var val = $(this).val();
525
		if (val.length < 3) {
526
			return;
527
		}
528
		var formData = {
529
			searchTerm: val,
530
			groups: JSON.stringify(g_chosen_groups),
531
			users: JSON.stringify(g_chosen_users);
0 ignored issues
show
Bug introduced by
Expected '}' to match '{' from line 528 and instead saw ';'.
Loading history...
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
532
		}
533
		$.post(OC.generateUrl('/apps/polls/search'), formData, function(data) {
0 ignored issues
show
Bug introduced by
) was expected, but instead $ was given.
Loading history...
534
			for (var i=0; i<data.length; i++) {
535
				var ug = data[i];
536
				var li = document.createElement('li');
537
				li.className = 'cl_item cl_access_item';
538
				if (ug.isGroup) {
539
					li.id = 'group_' + ug.gid;
540
					li.className += ' is-group';
541
					li.appendChild(document.createTextNode(ug.gid + " (group)"));
542
					ul.appendChild(li);
543
				} else {
544
					li.id = 'user_' + ug.uid;
545
					li.appendChild(document.createTextNode(ug.uid + " (" + ug.displayName + ")"));
546
					var span = document.createElement('span');
547
					span.id = 'sec_name';
548
					span.appendChild(document.createTextNode(ug.uid));
549
					li.appendChild(span);
550
					ul.appendChild(li);
551
				}
552
			}
553
		});
0 ignored issues
show
Bug introduced by
) was expected, but instead ; was given.
Loading history...
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
554
	}, 250));
0 ignored issues
show
introduced by
Missing semicolon.
Loading history...
Bug introduced by
Expected an identifier and instead saw ')'.
Loading history...
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
555
556
	$('.live-search-list-user li').each(function(){
557
	$(this).attr('data-search-term', $(this).text().toLowerCase());
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
558
	});
559
560
	$('.live-search-box-user').on('keyup', function(){
561
	var searchTerm = $(this).val().toLowerCase();
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
562
		$('.live-search-list-user li').each(function(){
563
			if ($(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0  || searchTerm.length < 1) {
564
				$(this).show();
565
			} else {
566
				$(this).hide();
567
			}
568
		});
569
	});
570
571
	$('.live-search-list-group li').each(function(){
572
		$(this).attr('data-search-term', $(this).text().toLowerCase());
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
573
	});
574
 
575
	$('.live-search-box-group').on('keyup', function(){
576
	var searchTerm = $(this).val().toLowerCase();
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
577
		$('.live-search-list-group li').each(function(){
578
			if ($(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 || searchTerm.length < 1) {
579
				$(this).show();
580
			} else {
581
				$(this).hide();
582
			}
583
		});
584
	}); 
585
586
	var form = document.finish_poll;
587
	var submit_finish_poll = document.getElementById('submit_finish_poll');
588
	if (submit_finish_poll != null) {
0 ignored issues
show
Bug introduced by
!== was expected, but instead != was given.
Loading history...
589
		submit_finish_poll.onclick = function() {
590
			if (g_chosen_datetimes.length === 0 && g_chosen_texts.length == 0) {
0 ignored issues
show
Coding Style introduced by
This function should enable strict mode with use strict.

Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.

Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.

We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.

Loading history...
Bug introduced by
=== was expected, but instead == was given.
Loading history...
591
				alert(t('polls', 'Nothing selected!\nClick on cells to turn them green.'));
592
				return false;
593
			}
594
			if (chosen_type == 'event') {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
595
				form.elements.chosenDates.value = JSON.stringify(g_chosen_datetimes);
596
			}
597
			else {
598
				form.elements['chosenDates'].value = JSON.stringify(g_chosen_texts);
0 ignored issues
show
Coding Style introduced by
['chosenDates'] could be written in dot notation.

You can rewrite this statement in dot notation:

var obj = { };
obj['foo'] = 'bar'; // Bad
obj.foo = 'bar'; // Good
Loading history...
599
			}
600
			var title = document.getElementById('pollTitle');
601
			if (title == null || title.value.length == 0) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
602
				alert(t('polls', 'You must enter at least a title for the new poll.'));
603
				return false;
604
			}
605
606
			if (access_type == 'select') {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
607
				if (g_chosen_groups.length == 0 && g_chosen_users == 0) {
0 ignored issues
show
Bug introduced by
=== was expected, but instead == was given.
Loading history...
608
					alert(t('polls', 'Please select at least one user or group!'));
609
					return false;
610
				}
611
				form.elements.accessValues.value = JSON.stringify({
612
					groups: g_chosen_groups,
613
					users: g_chosen_users
614
				});
615
			}
616
			form.elements.isAnonymous.value = isAnonymous;
617
			form.elements.hideNames.value = hideNames;
618
			form.submit();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
619
		};
620
	}
0 ignored issues
show
introduced by
Unrecoverable syntax error. (99% scanned).
Loading history...
621
});
622
623