/** * Redmine - project management software * Copyright (C) 2006- Jean-Philippe Lang * This code is released under the GNU General Public License. */ function sanitizeHTML(string) { var temp = document.createElement('span'); temp.textContent = string; return temp.innerHTML; } function checkAll(id, checked) { $('#'+id).find('input[type=checkbox]:enabled').prop('checked', checked); } function toggleCheckboxesBySelector(selector) { var all_checked = true; $(selector).each(function(index) { if (!$(this).is(':checked')) { all_checked = false; } }); $(selector).prop('checked', !all_checked).trigger('change'); } function showAndScrollTo(id, focus) { $('#'+id).show(); if (focus !== null) { $('#'+focus).focus(); } $('html, body').animate({scrollTop: $('#'+id).offset().top}, 100); } function toggleRowGroup(el) { var tr = $(el).parents('tr').first(); var n = tr.next(); tr.toggleClass('open'); $(el).toggleClass('icon-expanded icon-collapsed'); toggleExpendCollapseIcon(el) while (n.length && !n.hasClass('group')) { n.toggle(); n = n.next('tr'); } } function toggleExpendCollapseIcon(el) { if (el.classList.contains('icon-expanded')) { updateSVGIcon(el, 'angle-down') } else { updateSVGIcon(el, 'angle-right') } } function updateSVGIcon(element, icon) { const iconElement = element.getElementsByTagName("use").item(0) if (iconElement === null) { return false; } const iconPath = iconElement.getAttribute('href'); iconElement.setAttribute('href', iconPath.replace(/#.*$/g, "#icon--" + icon)) } function collapseAllRowGroups(el) { var tbody = $(el).parents('tbody').first(); tbody.children('tr').each(function(index) { if ($(this).hasClass('group')) { $(this).removeClass('open'); $(this).find('.expander').switchClass('icon-expanded', 'icon-collapsed'); updateSVGIcon($(this).find('.expander')[0], 'angle-right') } else { $(this).hide(); } }); } function expandAllRowGroups(el) { var tbody = $(el).parents('tbody').first(); tbody.children('tr').each(function(index) { if ($(this).hasClass('group')) { $(this).addClass('open'); $(this).find('.expander').switchClass('icon-collapsed', 'icon-expanded'); updateSVGIcon($(this).find('.expander')[0], 'angle-down') } else { $(this).show(); } }); } function toggleAllRowGroups(el) { var tr = $(el).parents('tr').first(); if (tr.hasClass('open')) { collapseAllRowGroups(el); } else { expandAllRowGroups(el); } } function toggleFieldset(el) { var fieldset = $(el).parents('fieldset').first(); fieldset.toggleClass('collapsed'); fieldset.children('legend').toggleClass('icon-expanded icon-collapsed'); toggleExpendCollapseIcon(fieldset.children('legend')[0]) fieldset.children('div').toggle(); } function hideFieldset(el) { var fieldset = $(el).parents('fieldset').first(); fieldset.toggleClass('collapsed'); fieldset.children('div').hide(); } // columns selection function moveOptions(theSelFrom, theSelTo) { $(theSelFrom).find('option:selected').detach().prop("selected", false).appendTo($(theSelTo)); } function moveOptionUp(theSel) { $(theSel).find('option:selected').each(function(){ $(this).prev(':not(:selected)').detach().insertAfter($(this)); }); } function moveOptionTop(theSel) { $(theSel).find('option:selected').detach().prependTo($(theSel)); } function moveOptionDown(theSel) { $($(theSel).find('option:selected').get().reverse()).each(function(){ $(this).next(':not(:selected)').detach().insertBefore($(this)); }); } function moveOptionBottom(theSel) { $(theSel).find('option:selected').detach().appendTo($(theSel)); } function initFilters() { $('#add_filter_select').change(function() { addFilter($(this).val(), '', []); }); $('#filters-table .field input[type=checkbox]').each(function() { toggleFilter($(this).val()); }); $('#filters-table').on('click', '.field input[type=checkbox]', function() { toggleFilter($(this).val()); }); $('#filters-table').on('keypress', 'input[type=text]', function(e) { if (e.keyCode == 13) $(this).closest('form').submit(); }); } function addFilter(field, operator, values) { var fieldId = field.replace('.', '_'); var tr = $('#tr_'+fieldId); var filterOptions = availableFilters[field]; if (!filterOptions) return; if (filterOptions['remote'] && filterOptions['values'] == null) { $.getJSON(filtersUrl, {'name': field}).done(function(data) { filterOptions['values'] = data; addFilter(field, operator, values) ; }); return; } if (tr.length > 0) { tr.show(); } else { buildFilterRow(field, operator, values); } $('#cb_'+fieldId).prop('checked', true); toggleFilter(field); toggleMultiSelectIconInit(); $('#add_filter_select').val('').find('option').each(function() { if ($(this).attr('value') == field) { $(this).attr('disabled', true); } }); } function buildFilterRow(field, operator, values) { var fieldId = field.replace('.', '_'); var filterTable = $("#filters-table"); var filterOptions = availableFilters[field]; if (!filterOptions) return; var operators = operatorByType[filterOptions['type']]; var filterValues = filterOptions['values']; var select; var tr = $('
').attr('id', 'tr_'+fieldId).html( '
' + '
' + '
' ); filterTable.append(tr); select = tr.find('.operator select'); operators.forEach(function(op) { var option = $('