/* Redmine - project management software Copyright (C) 2006-2023 Jean-Philippe Lang */ 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'); while (n.length && !n.hasClass('group')) { n.toggle(); n = n.next('tr'); } } 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'); } 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'); } 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'); 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 td.field input[type=checkbox]').each(function() { toggleFilter($(this).val()); }); $('#filters-table').on('click', 'td.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 i, select; var tr = $('').attr('id', 'tr_'+fieldId).html( '' + '' + '  ' ); select = tr.find('td.values select'); if (values.length > 1) { select.attr('multiple', true); } for (i = 0; i < filterValues.length; i++) { var filterValue = filterValues[i]; var option = $('').attr('label', filterValue[2]);} option = optgroup.append(option); } } else { option.val(filterValue).text(filterValue); if ($.inArray(filterValue, values) > -1) {option.prop('selected', true);} } select.append(option); } break; case "date": case "date_past": tr.find('td.values').append( '' + ' ' + ' '+labelDayPlural+'' ); $('#values_'+fieldId+'_1').val(values[0]).datepickerFallback(datepickerOptions); $('#values_'+fieldId+'_2').val(values[1]).datepickerFallback(datepickerOptions); $('#values_'+fieldId).val(values[0]); break; case "string": case "text": case "search": tr.find('td.values').append( '' ); $('#values_'+fieldId).val(values[0]); break; case "relation": tr.find('td.values').append( '' + '' ); $('#values_'+fieldId).val(values[0]); select = tr.find('td.values select'); for (i = 0; i < filterValues.length; i++) { var filterValue = filterValues[i]; var option = $('