/* Redmine - project management software
Copyright (C) 2006-2013 Jean-Philippe Lang */
function checkAll(id, checked) {
if (checked) {
$('#'+id).find('input[type=checkbox]').attr('checked', true);
} else {
$('#'+id).find('input[type=checkbox]').removeAttr('checked');
}
}
function toggleCheckboxesBySelector(selector) {
var all_checked = true;
$(selector).each(function(index) {
if (!$(this).is(':checked')) { all_checked = false; }
});
$(selector).attr('checked', !all_checked);
}
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');
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');
} 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');
} 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('div').toggle();
}
function hideFieldset(el) {
var fieldset = $(el).parents('fieldset').first();
fieldset.toggleClass('collapsed');
fieldset.children('div').hide();
}
function initFilters() {
$('#add_filter_select').change(function() {
addFilter($(this).val(), '', []);
});
$('#filters-table td.field input[type=checkbox]').each(function() {
toggleFilter($(this).val());
});
$('#filters-table td.field input[type=checkbox]').live('click', function() {
toggleFilter($(this).val());
});
$('#filters-table .toggle-multiselect').live('click', function() {
toggleMultiSelect($(this).siblings('select'));
});
$('#filters-table input[type=text]').live('keypress', function(e) {
if (e.keyCode == 13) submit_query_form("query_form");
});
}
function addFilter(field, operator, values) {
var fieldId = field.replace('.', '_');
var tr = $('#tr_'+fieldId);
if (tr.length > 0) {
tr.show();
} else {
buildFilterRow(field, operator, values);
}
$('#cb_'+fieldId).attr('checked', true);
toggleFilter(field);
$('#add_filter_select').val('').children('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];
var operators = operatorByType[filterOptions['type']];
var filterValues = filterOptions['values'];
var i, select;
var tr = $('
').attr('id', 'tr_'+fieldId).html(
' | ' +
' | ' +
' | '
);
filterTable.append(tr);
select = tr.find('td.operator select');
for (i = 0; i < operators.length; i++) {
var option = $('