2012-02-10 04:36:21 +04:00
|
|
|
/* Redmine - project management software
|
|
|
|
Copyright (C) 2006-2012 Jean-Philippe Lang */
|
2008-02-10 16:17:41 +03:00
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
function checkAll(id, checked) {
|
|
|
|
if (checked) {
|
|
|
|
$('#'+id).find('input[type=checkbox]').attr('checked', true);
|
|
|
|
} else {
|
|
|
|
$('#'+id).find('input[type=checkbox]').removeAttr('checked');
|
2012-02-10 04:35:58 +04:00
|
|
|
}
|
2007-04-04 22:20:45 +04:00
|
|
|
}
|
|
|
|
|
2008-08-26 20:05:02 +04:00
|
|
|
function toggleCheckboxesBySelector(selector) {
|
2012-02-10 04:35:58 +04:00
|
|
|
var all_checked = true;
|
2012-07-22 17:29:26 +04:00
|
|
|
$(selector).each(function(index) {
|
|
|
|
if (!$(this).is(':checked')) { all_checked = false; }
|
2010-09-29 01:09:06 +04:00
|
|
|
});
|
2012-07-22 17:29:26 +04:00
|
|
|
$(selector).attr('checked', !all_checked)
|
2010-09-29 01:09:06 +04:00
|
|
|
}
|
|
|
|
|
2008-06-29 23:50:07 +04:00
|
|
|
function showAndScrollTo(id, focus) {
|
2012-07-22 17:29:26 +04:00
|
|
|
$('#'+id).show();
|
|
|
|
if (focus!=null) {
|
|
|
|
$('#'+focus).focus();
|
|
|
|
}
|
|
|
|
$('html, body').animate({scrollTop: $('#'+id).offset().top}, 100);
|
2008-06-29 23:50:07 +04:00
|
|
|
}
|
|
|
|
|
2009-05-04 22:04:09 +04:00
|
|
|
function toggleRowGroup(el) {
|
2012-07-22 17:29:26 +04:00
|
|
|
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');
|
2012-02-10 04:35:58 +04:00
|
|
|
}
|
2009-05-04 22:04:09 +04:00
|
|
|
}
|
|
|
|
|
2011-03-20 19:01:25 +03:00
|
|
|
function collapseAllRowGroups(el) {
|
2012-07-22 17:29:26 +04:00
|
|
|
var tbody = $(el).parents('tbody').first();
|
|
|
|
tbody.children('tr').each(function(index) {
|
|
|
|
if ($(this).hasClass('group')) {
|
|
|
|
$(this).removeClass('open');
|
2011-03-20 19:01:25 +03:00
|
|
|
} else {
|
2012-07-22 17:29:26 +04:00
|
|
|
$(this).hide();
|
2011-03-20 19:01:25 +03:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
});
|
2011-03-20 19:01:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function expandAllRowGroups(el) {
|
2012-07-22 17:29:26 +04:00
|
|
|
var tbody = $(el).parents('tbody').first();
|
|
|
|
tbody.children('tr').each(function(index) {
|
|
|
|
if ($(this).hasClass('group')) {
|
|
|
|
$(this).addClass('open');
|
2011-03-20 19:01:25 +03:00
|
|
|
} else {
|
2012-07-22 17:29:26 +04:00
|
|
|
$(this).show();
|
2011-03-20 19:01:25 +03:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
});
|
2011-03-20 19:01:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleAllRowGroups(el) {
|
2012-07-22 17:29:26 +04:00
|
|
|
var tr = $(el).parents('tr').first();
|
|
|
|
if (tr.hasClass('open')) {
|
2011-03-20 19:01:25 +03:00
|
|
|
collapseAllRowGroups(el);
|
|
|
|
} else {
|
|
|
|
expandAllRowGroups(el);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-20 11:24:16 +04:00
|
|
|
function toggleFieldset(el) {
|
2012-07-22 17:29:26 +04:00
|
|
|
var fieldset = $(el).parents('fieldset').first();
|
|
|
|
fieldset.toggleClass('collapsed');
|
|
|
|
fieldset.children('div').toggle();
|
2009-09-20 11:24:16 +04:00
|
|
|
}
|
|
|
|
|
2011-02-20 18:38:07 +03:00
|
|
|
function hideFieldset(el) {
|
2012-07-22 17:29:26 +04:00
|
|
|
var fieldset = $(el).parents('fieldset').first();
|
|
|
|
fieldset.toggleClass('collapsed');
|
|
|
|
fieldset.children('div').hide();
|
2011-02-20 18:38:07 +03:00
|
|
|
}
|
|
|
|
|
2012-08-07 20:41:46 +04:00
|
|
|
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(){
|
2012-07-22 17:29:26 +04:00
|
|
|
if ($(this).attr('value') == field) {
|
|
|
|
$(this).attr('disabled', true);
|
2012-01-24 22:02:22 +04:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
});
|
2012-01-24 22:02:22 +04:00
|
|
|
}
|
|
|
|
|
2012-08-07 20:41:46 +04:00
|
|
|
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 = $('<tr class="filter">').attr('id', 'tr_'+fieldId).html(
|
|
|
|
'<td class="field"><input checked="checked" id="cb_'+fieldId+'" name="f[]" value="'+field+'" type="checkbox"><label for="cb_'+fieldId+'"> '+filterOptions['name']+'</label></td>' +
|
|
|
|
'<td class="operator"><select id="operators_'+fieldId+'" name="op['+field+']"></td>' +
|
|
|
|
'<td class="values"></td>'
|
|
|
|
);
|
|
|
|
filterTable.append(tr);
|
|
|
|
|
|
|
|
select = tr.find('td.operator select');
|
|
|
|
for (i=0;i<operators.length;i++){
|
2012-08-13 18:59:59 +04:00
|
|
|
var option = $('<option>').val(operators[i]).text(operatorLabels[operators[i]]);
|
2012-08-07 20:41:46 +04:00
|
|
|
if (operators[i] == operator) {option.attr('selected', true)};
|
|
|
|
select.append(option);
|
|
|
|
}
|
|
|
|
select.change(function(){toggleOperator(field)});
|
|
|
|
|
|
|
|
switch (filterOptions['type']){
|
|
|
|
case "list":
|
|
|
|
case "list_optional":
|
|
|
|
case "list_status":
|
|
|
|
case "list_subprojects":
|
|
|
|
tr.find('td.values').append(
|
|
|
|
'<span style="display:none;"><select class="value" id="values_'+fieldId+'_1" name="v['+field+'][]"></select>' +
|
|
|
|
' <span class="toggle-multiselect"> </span></span>'
|
|
|
|
);
|
|
|
|
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 = $('<option>');
|
|
|
|
if ($.isArray(filterValue)) {
|
2012-08-13 18:59:59 +04:00
|
|
|
option.val(filterValue[1]).text(filterValue[0]);
|
2012-09-27 09:42:10 +04:00
|
|
|
if ($.inArray(filterValue[1], values) > -1) {option.attr('selected', true);}
|
2012-08-07 20:41:46 +04:00
|
|
|
} else {
|
2012-08-13 18:59:59 +04:00
|
|
|
option.val(filterValue).text(filterValue);
|
2012-09-27 09:42:10 +04:00
|
|
|
if ($.inArray(filterValue, values) > -1) {option.attr('selected', true);}
|
2012-08-07 20:41:46 +04:00
|
|
|
}
|
|
|
|
select.append(option);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "date":
|
|
|
|
case "date_past":
|
|
|
|
tr.find('td.values').append(
|
2012-09-25 22:23:11 +04:00
|
|
|
'<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="10" class="value date_value" /></span>' +
|
|
|
|
' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="10" class="value date_value" /></span>' +
|
|
|
|
' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="3" class="value" /> '+labelDayPlural+'</span>'
|
2012-08-07 20:41:46 +04:00
|
|
|
);
|
|
|
|
$('#values_'+fieldId+'_1').val(values[0]).datepicker(datepickerOptions);
|
|
|
|
$('#values_'+fieldId+'_2').val(values[1]).datepicker(datepickerOptions);
|
|
|
|
$('#values_'+fieldId).val(values[0]);
|
|
|
|
break;
|
|
|
|
case "string":
|
|
|
|
case "text":
|
|
|
|
tr.find('td.values').append(
|
2012-09-25 22:23:11 +04:00
|
|
|
'<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="30" class="value" /></span>'
|
2012-08-07 20:41:46 +04:00
|
|
|
);
|
|
|
|
$('#values_'+fieldId).val(values[0]);
|
|
|
|
break;
|
2012-09-29 16:57:38 +04:00
|
|
|
case "relation":
|
|
|
|
tr.find('td.values').append(
|
|
|
|
'<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="6" class="value" /></span>' +
|
|
|
|
'<span style="display:none;"><select class="value" name="v['+field+'][]" id="values_'+fieldId+'_1"></select></span>'
|
|
|
|
);
|
|
|
|
$('#values_'+fieldId).val(values[0]);
|
|
|
|
select = tr.find('td.values select');
|
|
|
|
for (i=0;i<allProjects.length;i++){
|
|
|
|
var filterValue = allProjects[i];
|
|
|
|
var option = $('<option>');
|
|
|
|
option.val(filterValue[1]).text(filterValue[0]);
|
|
|
|
if (values[0] == filterValue[1]) {option.attr('selected', true)};
|
|
|
|
select.append(option);
|
|
|
|
}
|
2012-08-07 20:41:46 +04:00
|
|
|
case "integer":
|
|
|
|
case "float":
|
|
|
|
tr.find('td.values').append(
|
2012-09-25 22:23:11 +04:00
|
|
|
'<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_1" size="6" class="value" /></span>' +
|
|
|
|
' <span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'_2" size="6" class="value" /></span>'
|
2012-08-07 20:41:46 +04:00
|
|
|
);
|
|
|
|
$('#values_'+fieldId+'_1').val(values[0]);
|
|
|
|
$('#values_'+fieldId+'_2').val(values[1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleFilter(field) {
|
|
|
|
var fieldId = field.replace('.', '_');
|
|
|
|
if ($('#cb_' + fieldId).is(':checked')) {
|
|
|
|
$("#operators_" + fieldId).show().removeAttr('disabled');
|
|
|
|
toggleOperator(field);
|
2012-01-24 22:02:22 +04:00
|
|
|
} else {
|
2012-08-07 20:41:46 +04:00
|
|
|
$("#operators_" + fieldId).hide().attr('disabled', true);
|
2012-01-24 22:02:22 +04:00
|
|
|
enableValues(field, []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableValues(field, indexes) {
|
2012-08-07 20:41:46 +04:00
|
|
|
var fieldId = field.replace('.', '_');
|
|
|
|
$('#tr_'+fieldId+' td.values .value').each(function(index) {
|
2012-09-27 09:42:10 +04:00
|
|
|
if ($.inArray(index, indexes) >= 0) {
|
2012-07-22 17:29:26 +04:00
|
|
|
$(this).removeAttr('disabled');
|
|
|
|
$(this).parents('span').first().show();
|
2012-01-24 22:02:22 +04:00
|
|
|
} else {
|
2012-07-22 17:29:26 +04:00
|
|
|
$(this).val('');
|
|
|
|
$(this).attr('disabled', true);
|
|
|
|
$(this).parents('span').first().hide();
|
2012-01-24 22:02:22 +04:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
|
|
|
|
if ($(this).hasClass('group')) {
|
|
|
|
$(this).addClass('open');
|
|
|
|
} else {
|
|
|
|
$(this).show();
|
|
|
|
}
|
|
|
|
});
|
2012-01-24 22:02:22 +04:00
|
|
|
}
|
|
|
|
|
2012-08-07 20:41:46 +04:00
|
|
|
function toggleOperator(field) {
|
|
|
|
var fieldId = field.replace('.', '_');
|
|
|
|
var operator = $("#operators_" + fieldId);
|
2012-07-22 17:29:26 +04:00
|
|
|
switch (operator.val()) {
|
2012-01-24 22:02:22 +04:00
|
|
|
case "!*":
|
|
|
|
case "*":
|
|
|
|
case "t":
|
|
|
|
case "w":
|
|
|
|
case "o":
|
|
|
|
case "c":
|
|
|
|
enableValues(field, []);
|
|
|
|
break;
|
|
|
|
case "><":
|
|
|
|
enableValues(field, [0,1]);
|
|
|
|
break;
|
|
|
|
case "<t+":
|
|
|
|
case ">t+":
|
|
|
|
case "t+":
|
|
|
|
case ">t-":
|
|
|
|
case "<t-":
|
|
|
|
case "t-":
|
|
|
|
enableValues(field, [2]);
|
|
|
|
break;
|
2012-09-29 16:57:38 +04:00
|
|
|
case "=p":
|
|
|
|
case "=!p":
|
|
|
|
enableValues(field, [1]);
|
|
|
|
break;
|
2012-01-24 22:02:22 +04:00
|
|
|
default:
|
|
|
|
enableValues(field, [0]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:41:46 +04:00
|
|
|
function toggleMultiSelect(el) {
|
|
|
|
if (el.attr('multiple')) {
|
|
|
|
el.removeAttr('multiple');
|
2012-01-24 22:02:22 +04:00
|
|
|
} else {
|
2012-08-07 20:41:46 +04:00
|
|
|
el.attr('multiple', true);
|
2012-01-24 22:02:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function submit_query_form(id) {
|
|
|
|
selectAllOptions("selected_columns");
|
2012-07-22 17:29:26 +04:00
|
|
|
$('#'+id).submit();
|
2012-01-24 22:02:22 +04:00
|
|
|
}
|
|
|
|
|
2008-02-29 22:46:58 +03:00
|
|
|
var fileFieldCount = 1;
|
2007-04-04 22:20:45 +04:00
|
|
|
function addFileField() {
|
2012-07-22 17:29:26 +04:00
|
|
|
var fields = $('#attachments_fields');
|
|
|
|
if (fields.children().length >= 10) return false;
|
2011-07-10 00:11:18 +04:00
|
|
|
fileFieldCount++;
|
2012-07-22 17:29:26 +04:00
|
|
|
var s = fields.children('span').first().clone();
|
|
|
|
s.children('input.file').attr('name', "attachments[" + fileFieldCount + "][file]").val('');
|
|
|
|
s.children('input.description').attr('name', "attachments[" + fileFieldCount + "][description]").val('');
|
|
|
|
fields.append(s);
|
2007-04-04 22:20:45 +04:00
|
|
|
}
|
|
|
|
|
2011-07-10 00:11:18 +04:00
|
|
|
function removeFileField(el) {
|
2012-07-22 17:29:26 +04:00
|
|
|
var fields = $('#attachments_fields');
|
|
|
|
var s = $(el).parents('span').first();
|
|
|
|
if (fields.children().length > 1) {
|
2012-02-10 04:35:58 +04:00
|
|
|
s.remove();
|
|
|
|
} else {
|
2012-07-22 17:29:26 +04:00
|
|
|
s.children('input.file').val('');
|
|
|
|
s.children('input.description').val('');
|
2012-02-10 04:35:58 +04:00
|
|
|
}
|
2011-07-10 00:11:18 +04:00
|
|
|
}
|
|
|
|
|
2011-11-26 02:32:07 +04:00
|
|
|
function checkFileSize(el, maxSize, message) {
|
|
|
|
var files = el.files;
|
|
|
|
if (files) {
|
|
|
|
for (var i=0; i<files.length; i++) {
|
|
|
|
if (files[i].size > maxSize) {
|
|
|
|
alert(message);
|
|
|
|
el.value = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-04 22:20:45 +04:00
|
|
|
function showTab(name) {
|
2012-07-22 17:29:26 +04:00
|
|
|
$('div#content .tab-content').hide();
|
|
|
|
$('div.tabs a').removeClass('selected');
|
|
|
|
$('#tab-content-' + name).show();
|
|
|
|
$('#tab-' + name).addClass('selected');
|
2012-02-10 04:35:58 +04:00
|
|
|
return false;
|
2007-04-27 23:32:57 +04:00
|
|
|
}
|
|
|
|
|
2009-12-14 23:13:29 +03:00
|
|
|
function moveTabRight(el) {
|
2012-07-22 17:29:26 +04:00
|
|
|
var lis = $(el).parents('div.tabs').first().find('ul').children();
|
2012-02-10 04:35:58 +04:00
|
|
|
var tabsWidth = 0;
|
2012-07-22 17:29:26 +04:00
|
|
|
var i = 0;
|
|
|
|
lis.each(function(){
|
|
|
|
if ($(this).is(':visible')) {
|
|
|
|
tabsWidth += $(this).width() + 6;
|
2012-02-10 04:35:58 +04:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
});
|
|
|
|
if (tabsWidth < $(el).parents('div.tabs').first().width() - 60) { return; }
|
|
|
|
while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
|
|
|
|
lis.eq(i).hide();
|
2009-12-14 23:13:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function moveTabLeft(el) {
|
2012-07-22 17:29:26 +04:00
|
|
|
var lis = $(el).parents('div.tabs').first().find('ul').children();
|
2012-02-10 04:35:58 +04:00
|
|
|
var i = 0;
|
2012-07-22 17:29:26 +04:00
|
|
|
while (i<lis.length && !lis.eq(i).is(':visible')) { i++; }
|
2012-02-10 04:35:58 +04:00
|
|
|
if (i>0) {
|
2012-07-22 17:29:26 +04:00
|
|
|
lis.eq(i-1).show();
|
2012-02-10 04:35:58 +04:00
|
|
|
}
|
2009-12-14 23:13:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function displayTabsButtons() {
|
2012-02-10 04:35:58 +04:00
|
|
|
var lis;
|
|
|
|
var tabsWidth = 0;
|
2012-07-22 17:29:26 +04:00
|
|
|
var el;
|
|
|
|
$('div.tabs').each(function() {
|
|
|
|
el = $(this);
|
|
|
|
lis = el.find('ul').children();
|
|
|
|
lis.each(function(){
|
|
|
|
if ($(this).is(':visible')) {
|
|
|
|
tabsWidth += $(this).width() + 6;
|
2012-02-10 04:35:58 +04:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
});
|
|
|
|
if ((tabsWidth < el.width() - 60) && (lis.first().is(':visible'))) {
|
|
|
|
el.find('div.tabs-buttons').hide();
|
2012-02-10 04:35:58 +04:00
|
|
|
} else {
|
2012-07-22 17:29:26 +04:00
|
|
|
el.find('div.tabs-buttons').show();
|
2012-02-10 04:35:58 +04:00
|
|
|
}
|
|
|
|
});
|
2009-12-14 23:13:29 +03:00
|
|
|
}
|
|
|
|
|
2007-05-05 17:22:27 +04:00
|
|
|
function setPredecessorFieldsVisibility() {
|
2012-07-22 17:29:26 +04:00
|
|
|
var relationType = $('#relation_relation_type');
|
|
|
|
if (relationType.val() == "precedes" || relationType.val() == "follows") {
|
|
|
|
$('#predecessor_fields').show();
|
|
|
|
} else {
|
|
|
|
$('#predecessor_fields').hide();
|
|
|
|
}
|
2007-08-16 20:45:06 +04:00
|
|
|
}
|
|
|
|
|
2011-11-20 17:23:20 +04:00
|
|
|
function showModal(id, width) {
|
2012-07-22 19:42:29 +04:00
|
|
|
var el = $('#'+id).first();
|
2012-07-22 17:29:26 +04:00
|
|
|
if (el.length == 0 || el.is(':visible')) {return;}
|
2012-07-22 19:42:29 +04:00
|
|
|
var title = el.find('h3.title').text();
|
|
|
|
el.dialog({
|
|
|
|
width: width,
|
|
|
|
modal: true,
|
|
|
|
resizable: false,
|
|
|
|
dialogClass: 'modal',
|
|
|
|
title: title
|
|
|
|
});
|
2012-07-22 17:29:26 +04:00
|
|
|
el.find("input[type=text], input[type=submit]").first().focus();
|
2011-11-20 17:23:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function hideModal(el) {
|
2012-02-11 17:05:41 +04:00
|
|
|
var modal;
|
2012-07-22 17:29:26 +04:00
|
|
|
if (el) {
|
2012-07-22 19:42:29 +04:00
|
|
|
modal = $(el).parents('.ui-dialog-content');
|
2012-07-22 17:29:26 +04:00
|
|
|
} else {
|
|
|
|
modal = $('#ajax-modal');
|
2011-11-20 17:23:20 +04:00
|
|
|
}
|
2012-07-22 19:42:29 +04:00
|
|
|
modal.dialog("close");
|
2011-11-20 17:23:20 +04:00
|
|
|
}
|
|
|
|
|
2012-07-18 21:47:19 +04:00
|
|
|
function submitPreview(url, form, target) {
|
2012-07-22 17:29:26 +04:00
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
type: 'post',
|
|
|
|
data: $('#'+form).serialize(),
|
|
|
|
success: function(data){
|
|
|
|
$('#'+target).html(data);
|
|
|
|
}
|
2012-07-18 21:47:19 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2007-10-22 23:34:21 +04:00
|
|
|
function collapseScmEntry(id) {
|
2012-07-22 17:29:26 +04:00
|
|
|
$('.'+id).each(function() {
|
|
|
|
if ($(this).hasClass('open')) {
|
|
|
|
collapseScmEntry($(this).attr('id'));
|
|
|
|
}
|
|
|
|
$(this).hide();
|
|
|
|
});
|
|
|
|
$('#'+id).removeClass('open');
|
2007-10-22 23:34:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function expandScmEntry(id) {
|
2012-07-22 17:29:26 +04:00
|
|
|
$('.'+id).each(function() {
|
|
|
|
$(this).show();
|
|
|
|
if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) {
|
|
|
|
expandScmEntry($(this).attr('id'));
|
2007-10-22 23:34:21 +04:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
});
|
|
|
|
$('#'+id).addClass('open');
|
2007-10-22 23:34:21 +04:00
|
|
|
}
|
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
function scmEntryClick(id, url) {
|
|
|
|
el = $('#'+id);
|
|
|
|
if (el.hasClass('open')) {
|
2007-10-22 23:34:21 +04:00
|
|
|
collapseScmEntry(id);
|
2012-07-22 17:29:26 +04:00
|
|
|
el.addClass('collapsed');
|
2007-10-22 23:34:21 +04:00
|
|
|
return false;
|
2012-07-22 17:29:26 +04:00
|
|
|
} else if (el.hasClass('loaded')) {
|
2007-10-22 23:34:21 +04:00
|
|
|
expandScmEntry(id);
|
2012-07-22 17:29:26 +04:00
|
|
|
el.removeClass('collapsed');
|
2007-10-22 23:34:21 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
if (el.hasClass('loading')) {
|
2007-10-24 00:42:15 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
el.addClass('loading');
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
success: function(data){
|
|
|
|
el.after(data);
|
|
|
|
el.addClass('open').addClass('loaded').removeClass('loading');
|
|
|
|
}
|
|
|
|
});
|
2007-10-22 23:34:21 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-25 23:25:28 +04:00
|
|
|
function randomKey(size) {
|
2012-02-10 04:35:58 +04:00
|
|
|
var chars = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
|
|
|
|
var key = '';
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
key += chars[Math.floor(Math.random() * chars.length)];
|
|
|
|
}
|
|
|
|
return key;
|
2008-06-25 23:25:28 +04:00
|
|
|
}
|
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
// Can't use Rails' remote select because we need the form data
|
|
|
|
function updateIssueFrom(url) {
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
type: 'post',
|
|
|
|
data: $('#issue-form').serialize()
|
|
|
|
});
|
2010-03-13 17:56:49 +03:00
|
|
|
}
|
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
function updateBulkEditFrom(url) {
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
type: 'post',
|
|
|
|
data: $('#bulk_edit_form').serialize()
|
|
|
|
});
|
2010-12-12 19:04:28 +03:00
|
|
|
}
|
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
function observeAutocompleteField(fieldId, url) {
|
|
|
|
$('#'+fieldId).autocomplete({
|
|
|
|
source: url,
|
|
|
|
minLength: 2,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function observeSearchfield(fieldId, targetId, url) {
|
|
|
|
$('#'+fieldId).each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
$this.attr('data-value-was', $this.val());
|
|
|
|
var check = function() {
|
|
|
|
var val = $this.val();
|
|
|
|
if ($this.attr('data-value-was') != val){
|
|
|
|
$this.attr('data-value-was', val);
|
2012-09-29 20:43:11 +04:00
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
type: 'get',
|
|
|
|
data: {q: $this.val()},
|
|
|
|
success: function(data){ $('#'+targetId).html(data); },
|
|
|
|
beforeSend: function(){ $this.addClass('ajax-loading'); },
|
|
|
|
complete: function(){ $this.removeClass('ajax-loading'); }
|
|
|
|
});
|
2012-07-22 17:29:26 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var reset = function() {
|
|
|
|
if (timer) {
|
|
|
|
clearInterval(timer);
|
|
|
|
timer = setInterval(check, 300);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var timer = setInterval(check, 300);
|
|
|
|
$this.bind('keyup click mousemove', reset);
|
|
|
|
});
|
2011-01-07 00:02:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function observeProjectModules() {
|
|
|
|
var f = function() {
|
|
|
|
/* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */
|
2012-07-22 17:29:26 +04:00
|
|
|
if ($('#project_enabled_module_names_issue_tracking').attr('checked')) {
|
|
|
|
$('#project_trackers').show();
|
|
|
|
}else{
|
|
|
|
$('#project_trackers').hide();
|
|
|
|
}
|
2011-01-07 00:02:19 +03:00
|
|
|
};
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
$(window).load(f);
|
|
|
|
$('#project_enabled_module_names_issue_tracking').change(f);
|
2011-01-07 00:02:19 +03:00
|
|
|
}
|
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
function initMyPageSortable(list, url) {
|
|
|
|
$('#list-'+list).sortable({
|
|
|
|
connectWith: '.block-receiver',
|
|
|
|
tolerance: 'pointer',
|
|
|
|
update: function(){
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
type: 'post',
|
|
|
|
data: {'blocks': $.map($('#list-'+list).children(), function(el){return $(el).attr('id');})}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$("#list-top, #list-left, #list-right").disableSelection();
|
|
|
|
}
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
var warnLeavingUnsavedMessage;
|
|
|
|
function warnLeavingUnsaved(message) {
|
|
|
|
warnLeavingUnsavedMessage = message;
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
$('form').submit(function(){
|
|
|
|
$('textarea').removeData('changed');
|
|
|
|
});
|
|
|
|
$('textarea').change(function(){
|
|
|
|
$(this).data('changed', 'changed');
|
|
|
|
});
|
|
|
|
window.onbeforeunload = function(){
|
|
|
|
var warn = false;
|
|
|
|
$('textarea').blur().each(function(){
|
|
|
|
if ($(this).data('changed')) {
|
|
|
|
warn = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (warn) {return warnLeavingUnsavedMessage;}
|
|
|
|
};
|
|
|
|
};
|
2011-01-07 00:02:19 +03:00
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
$(document).ready(function(){
|
|
|
|
$('#ajax-indicator').bind('ajaxSend', function(){
|
|
|
|
if ($('.ajax-loading').length == 0) {
|
|
|
|
$('#ajax-indicator').show();
|
2007-04-27 23:32:57 +04:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
});
|
|
|
|
$('#ajax-indicator').bind('ajaxStop', function(){
|
|
|
|
$('#ajax-indicator').hide();
|
|
|
|
});
|
2007-04-27 23:32:57 +04:00
|
|
|
});
|
2010-02-25 00:23:20 +03:00
|
|
|
|
2010-06-19 23:51:43 +04:00
|
|
|
function hideOnLoad() {
|
2012-07-22 17:29:26 +04:00
|
|
|
$('.hol').hide();
|
2010-06-19 23:51:43 +04:00
|
|
|
}
|
|
|
|
|
2012-04-13 21:01:46 +04:00
|
|
|
function addFormObserversForDoubleSubmit() {
|
2012-07-22 17:29:26 +04:00
|
|
|
$('form[method=post]').each(function() {
|
|
|
|
if (!$(this).hasClass('multiple-submit')) {
|
|
|
|
$(this).submit(function(form_submission) {
|
|
|
|
if ($(form_submission.target).attr('data-submitted')) {
|
|
|
|
form_submission.preventDefault();
|
2012-04-19 11:17:48 +04:00
|
|
|
} else {
|
2012-07-22 17:29:26 +04:00
|
|
|
$(form_submission.target).attr('data-submitted', true);
|
2012-04-19 11:17:48 +04:00
|
|
|
}
|
2012-04-13 21:01:46 +04:00
|
|
|
});
|
2012-04-19 11:17:48 +04:00
|
|
|
}
|
2012-04-13 21:01:46 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
$(document).ready(hideOnLoad);
|
|
|
|
$(document).ready(addFormObserversForDoubleSubmit);
|