var g_chosen_datetimes = []; var g_chosen_texts = []; var g_chosen_groups = []; var g_chosen_users = []; var chosen_type = 'event'; var access_type = ''; var isAnonymous; var hideNames; function selectItem(cell) { cell.removeClass('icon-close'); cell.addClass('icon-checkmark'); cell.removeClass('date-text-not-selected'); cell.addClass('date-text-selected'); if (cell.attr('class').indexOf('is-text') > -1) { var id = cell.attr('id'); g_chosen_texts.push(id.substring(id.indexOf('_') + 1)); } else { var dateId = cell.parent().attr('id'); //timestamp of date var timeId = cell.attr('id'); g_chosen_datetimes.push(parseInt(dateId) + parseInt(timeId)); } } function deselectItem(cell) { var id; var index; var dateId; var timeId; cell.removeClass('icon-checkmark'); cell.addClass('icon-close'); cell.removeClass('date-text-selected'); cell.addClass('date-text-not-selected'); if (cell.attr('class').indexOf('is-text') > -1) { id = cell.attr('id'); index = g_chosen_texts.indexOf(id.substring(id.indexOf('_') + 1)); if (index > -1) { g_chosen_texts.splice(index, 1); } } else { dateId = cell.parent().attr('id'); //timestamp of date timeId = cell.attr('id'); index = g_chosen_datetimes.indexOf(parseInt(dateId) + parseInt(timeId)); if (index > -1) { g_chosen_datetimes.splice(index, 1); } } } function insertText(text, set) { if (typeof set === 'undefined') { set = false; } var table = document.getElementById('selected-texts-table'); var tr = table.insertRow(-1); var td = tr.insertCell(-1); td.innerHTML = text; td.className = 'text-row'; td = tr.insertCell(-1); if (set) { td.className = 'icon-checkmark is-text date-text-selected'; } else { td.className = 'icon-close is-text date-text-not-selected'; } td.id = 'text_' + text; } function addRowToList(ts, text, timeTs) { if (typeof timeTs === 'undefined') { timeTs = -1; } var table = document.getElementById('selected-dates-table'); var rows = table.rows; var td, tr, tdId; var i, j; var curr; if (rows.length === 0) { tr = table.insertRow(-1); //start new header tr.insertCell(-1); tr = table.insertRow(-1); //append new row tr.id = ts; tr.className = 'toggleable-row'; td = tr.insertCell(-1); td.className = 'date-row'; td.innerHTML = text; return; } for ( i=1; i ts) { tr = table.insertRow(i); //insert row at current index tr.id = ts; tr.className = 'toggleable-row'; td = tr.insertCell(-1); td.className = 'date-row'; td.innerHTML = text; for (j=1; j ts) { index = i; break; } } for (i=0; i 0) { var list = document.getElementById('selected-search-list-id'); var accessValueArr = accessValues.value.split(';'); for (i=0; i 0) { chosen = JSON.parse(chosenDates); } var text = document.getElementById('text'); var event = document.getElementById('event'); if (event.checked) { chosen_type = event.value; if (chosenDates.length > 0) { g_chosen_datetimes = chosen; } for (i=0; i 0) { g_chosen_texts = chosen; } for (i=0; i -1) { g_chosen_datetimes.splice(delIndex, 1); } } var table = document.getElementById('selected-dates-table'); table.deleteRow(index); }); $(document).on('click', '.date-col', function() { var cellIndex = $(this).index(); var timeId = parseInt($(this).attr('id')); var table = document.getElementById('selected-dates-table'); var rows = table.rows; rows[0].deleteCell(cellIndex); for (var i=1; i -1) { g_chosen_datetimes.splice(delIndex, 1); } row.deleteCell(cellIndex); } }); $(document).on('click', '.text-row', function() { var tr = $(this).parent(); var rowIndex = tr.index(); var name = $(this).html(); var delIndex = g_chosen_texts.indexOf(name); if (delIndex > -1) { g_chosen_texts.splice(delIndex, 1); } var table = document.getElementById('selected-texts-table'); table.deleteRow(rowIndex); }); $(document).on('click', '.icon-close', function() { selectItem($(this)); }); $(document).on('click', '.icon-checkmark', function() { deselectItem($(this)); }); $(document).on('click', '#text-submit', function() { var text = document.getElementById('text-title'); if (text.value.length === 0) { alert('Please enter a text!'); return false; } insertText(text.value); text.value = ''; }); $(document).on('click', '.cl_item', function() { var index; var list = document.getElementById('selected-search-list-id'); var isGroup = $(this).hasClass('is-group'); if ($(this).hasClass('selected')) { if (isGroup) { index = g_chosen_groups.indexOf(this.id); } else { index = g_chosen_users.indexOf(this.id); } if (index > -1) { if (isGroup) { g_chosen_groups.splice(index, 1); } else { g_chosen_users.splice(index, 1); } $(this).remove(); } } else { if (!isGroup) { var text = this.id.replace('user_', ''); g_chosen_users.push(this.id); } else { g_chosen_groups.push(this.id); } document.getElementById('user-group-search-box').value = ''; var li = document.createElement('li'); li.id = this.id; li.className = 'cl_item cl_access_item selected' + (isGroup ? ' is-group' : ''); if (!isGroup) { $.post(OC.generateUrl('/apps/polls/get/displayname'), {username: text}, function(data) { li.appendChild(document.createTextNode(text + " (" + data + ")")); list.appendChild(li); }); } else { li.appendChild(document.createTextNode($(this).html())); list.appendChild(li); } $(this).remove(); } }); $('.toggleable-row').hover( function() { var td = this.insertCell(-1); td.className = 'toggle-all selected-all'; }, function() { $(this).find('td:last-child').remove(); } ); $(document).on('click', '.toggle-all', function() { var children; var i; if ($(this).attr('class').indexOf('selected-all') > -1) { children = $(this).parent().children('.icon-checkmark'); for (i=0; i 0 || searchTerm.length < 1 ) { $(this).show(); } else { $(this).hide(); } }); }); $('.live-search-list-group li').each(function(){ $(this).attr('data-search-term', $(this).text().toLowerCase()); }); $('.live-search-box-group').on('keyup', function(){ var searchTerm = $(this).val().toLowerCase(); $('.live-search-list-group li').each(function(){ if ( $(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 || searchTerm.length < 1 ) { $(this).show(); } else { $(this).hide(); } }); }); var form = document.finish_poll; var submit_finish_poll = document.getElementById('submit_finish_poll'); if (submit_finish_poll !== null) { submit_finish_poll.onclick = function() { if ( g_chosen_datetimes.length === 0 && g_chosen_texts.length === 0 ) { alert(t('polls', 'Nothing selected!\nClick on cells to turn them green.')); return false; } if (chosen_type === 'event') { form.elements.chosenDates.value = JSON.stringify(g_chosen_datetimes); } else { form.elements.chosenDates.value = JSON.stringify(g_chosen_texts); } var title = document.getElementById('pollTitle'); if ( title === null || title.value.length === 0 ) { alert(t('polls', 'You must enter at least a title for the new poll.')); return false; } if (access_type === 'select') { if ( g_chosen_groups.length === 0 && g_chosen_users === 0 ) { alert(t('polls', 'Please select at least one user or group!')); return false; } form.elements.accessValues.value = JSON.stringify({ groups: g_chosen_groups, users: g_chosen_users }); } form.elements.isAnonymous.value = isAnonymous; form.elements.hideNames.value = hideNames; form.submit(); }; } });