application.js
742 lines
| 20.9 KiB
| application/javascript
|
JavascriptLexer
|
r8711 | /* Redmine - project management software | ||
|
r14856 | Copyright (C) 2006-2016 Jean-Philippe Lang */ | ||
|
r1116 | |||
|
r9885 | function checkAll(id, checked) { | ||
|
r13045 | $('#'+id).find('input[type=checkbox]:enabled').prop('checked', checked); | ||
|
r416 | } | ||
|
r1769 | function toggleCheckboxesBySelector(selector) { | ||
|
r8710 | var all_checked = true; | ||
|
r9885 | $(selector).each(function(index) { | ||
if (!$(this).is(':checked')) { all_checked = false; } | ||||
|
r4108 | }); | ||
|
r13045 | $(selector).prop('checked', !all_checked); | ||
|
r4108 | } | ||
|
r1591 | function showAndScrollTo(id, focus) { | ||
|
r9885 | $('#'+id).show(); | ||
|
r11499 | if (focus !== null) { | ||
|
r9885 | $('#'+focus).focus(); | ||
} | ||||
$('html, body').animate({scrollTop: $('#'+id).offset().top}, 100); | ||||
|
r1591 | } | ||
|
r2615 | function toggleRowGroup(el) { | ||
|
r9885 | 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'); | ||||
|
r8710 | } | ||
|
r2615 | } | ||
|
r5054 | function collapseAllRowGroups(el) { | ||
|
r9885 | var tbody = $(el).parents('tbody').first(); | ||
tbody.children('tr').each(function(index) { | ||||
if ($(this).hasClass('group')) { | ||||
$(this).removeClass('open'); | ||||
|
r5054 | } else { | ||
|
r9885 | $(this).hide(); | ||
|
r5054 | } | ||
|
r9885 | }); | ||
|
r5054 | } | ||
function expandAllRowGroups(el) { | ||||
|
r9885 | var tbody = $(el).parents('tbody').first(); | ||
tbody.children('tr').each(function(index) { | ||||
if ($(this).hasClass('group')) { | ||||
$(this).addClass('open'); | ||||
|
r5054 | } else { | ||
|
r9885 | $(this).show(); | ||
|
r5054 | } | ||
|
r9885 | }); | ||
|
r5054 | } | ||
function toggleAllRowGroups(el) { | ||||
|
r9885 | var tr = $(el).parents('tr').first(); | ||
if (tr.hasClass('open')) { | ||||
|
r5054 | collapseAllRowGroups(el); | ||
} else { | ||||
expandAllRowGroups(el); | ||||
} | ||||
} | ||||
|
r2777 | function toggleFieldset(el) { | ||
|
r9885 | var fieldset = $(el).parents('fieldset').first(); | ||
fieldset.toggleClass('collapsed'); | ||||
fieldset.children('div').toggle(); | ||||
|
r2777 | } | ||
|
r4775 | function hideFieldset(el) { | ||
|
r9885 | var fieldset = $(el).parents('fieldset').first(); | ||
fieldset.toggleClass('collapsed'); | ||||
fieldset.children('div').hide(); | ||||
|
r4775 | } | ||
|
r13236 | // 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)); | ||||
} | ||||
|
r11514 | function initFilters() { | ||
$('#add_filter_select').change(function() { | ||||
|
r9979 | addFilter($(this).val(), '', []); | ||
}); | ||||
|
r11514 | $('#filters-table td.field input[type=checkbox]').each(function() { | ||
|
r9979 | toggleFilter($(this).val()); | ||
}); | ||||
|
r13044 | $('#filters-table').on('click', 'td.field input[type=checkbox]', function() { | ||
|
r9979 | toggleFilter($(this).val()); | ||
}); | ||||
|
r13044 | $('#filters-table').on('click', '.toggle-multiselect', function() { | ||
|
r9979 | toggleMultiSelect($(this).siblings('select')); | ||
}); | ||||
|
r13044 | $('#filters-table').on('keypress', 'input[type=text]', function(e) { | ||
|
r13235 | if (e.keyCode == 13) $(this).closest('form').submit(); | ||
|
r9979 | }); | ||
} | ||||
function addFilter(field, operator, values) { | ||||
var fieldId = field.replace('.', '_'); | ||||
var tr = $('#tr_'+fieldId); | ||||
if (tr.length > 0) { | ||||
tr.show(); | ||||
} else { | ||||
buildFilterRow(field, operator, values); | ||||
} | ||||
|
r13045 | $('#cb_'+fieldId).prop('checked', true); | ||
|
r9979 | toggleFilter(field); | ||
|
r13280 | $('#add_filter_select').val('').find('option').each(function() { | ||
|
r9885 | if ($(this).attr('value') == field) { | ||
$(this).attr('disabled', true); | ||||
|
r8578 | } | ||
|
r9885 | }); | ||
|
r8578 | } | ||
|
r9979 | function buildFilterRow(field, operator, values) { | ||
var fieldId = field.replace('.', '_'); | ||||
var filterTable = $("#filters-table"); | ||||
var filterOptions = availableFilters[field]; | ||||
|
r12004 | if (!filterOptions) return; | ||
|
r9979 | 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'); | ||||
|
r11514 | for (i = 0; i < operators.length; i++) { | ||
|
r10018 | var option = $('<option>').val(operators[i]).text(operatorLabels[operators[i]]); | ||
|
r11502 | if (operators[i] == operator) { option.attr('selected', true); } | ||
|
r9979 | select.append(option); | ||
} | ||||
|
r11503 | select.change(function(){ toggleOperator(field); }); | ||
|
r9979 | |||
|
r11514 | switch (filterOptions['type']) { | ||
|
r9979 | 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'); | ||||
|
r11502 | if (values.length > 1) { select.attr('multiple', true); } | ||
|
r11514 | for (i = 0; i < filterValues.length; i++) { | ||
|
r9979 | var filterValue = filterValues[i]; | ||
var option = $('<option>'); | ||||
if ($.isArray(filterValue)) { | ||||
|
r10018 | option.val(filterValue[1]).text(filterValue[0]); | ||
|
r10278 | if ($.inArray(filterValue[1], values) > -1) {option.attr('selected', true);} | ||
|
r9979 | } else { | ||
|
r10018 | option.val(filterValue).text(filterValue); | ||
|
r10278 | if ($.inArray(filterValue, values) > -1) {option.attr('selected', true);} | ||
|
r9979 | } | ||
select.append(option); | ||||
} | ||||
break; | ||||
case "date": | ||||
case "date_past": | ||||
tr.find('td.values').append( | ||||
|
r10260 | '<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>' | ||||
|
r9979 | ); | ||
$('#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( | ||||
|
r10260 | '<span style="display:none;"><input type="text" name="v['+field+'][]" id="values_'+fieldId+'" size="30" class="value" /></span>' | ||
|
r9979 | ); | ||
$('#values_'+fieldId).val(values[0]); | ||||
break; | ||||
|
r10303 | 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'); | ||||
|
r11514 | for (i = 0; i < allProjects.length; i++) { | ||
|
r10303 | var filterValue = allProjects[i]; | ||
var option = $('<option>'); | ||||
option.val(filterValue[1]).text(filterValue[0]); | ||||
|
r11502 | if (values[0] == filterValue[1]) { option.attr('selected', true); } | ||
|
r10303 | select.append(option); | ||
} | ||||
|
r13468 | break; | ||
|
r9979 | case "integer": | ||
case "float": | ||||
|
r13922 | case "tree": | ||
|
r9979 | tr.find('td.values').append( | ||
|
r10260 | '<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>' | ||||
|
r9979 | ); | ||
$('#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); | ||||
|
r8578 | } else { | ||
|
r9979 | $("#operators_" + fieldId).hide().attr('disabled', true); | ||
|
r8578 | enableValues(field, []); | ||
} | ||||
} | ||||
function enableValues(field, indexes) { | ||||
|
r9979 | var fieldId = field.replace('.', '_'); | ||
$('#tr_'+fieldId+' td.values .value').each(function(index) { | ||||
|
r10278 | if ($.inArray(index, indexes) >= 0) { | ||
|
r9885 | $(this).removeAttr('disabled'); | ||
$(this).parents('span').first().show(); | ||||
|
r8578 | } else { | ||
|
r9885 | $(this).val(''); | ||
$(this).attr('disabled', true); | ||||
$(this).parents('span').first().hide(); | ||||
|
r8578 | } | ||
|
r9885 | |||
if ($(this).hasClass('group')) { | ||||
$(this).addClass('open'); | ||||
} else { | ||||
$(this).show(); | ||||
} | ||||
}); | ||||
|
r8578 | } | ||
|
r9979 | function toggleOperator(field) { | ||
var fieldId = field.replace('.', '_'); | ||||
var operator = $("#operators_" + fieldId); | ||||
|
r9885 | switch (operator.val()) { | ||
|
r8578 | case "!*": | ||
case "*": | ||||
case "t": | ||||
|
r10740 | case "ld": | ||
|
r8578 | case "w": | ||
|
r10740 | case "lw": | ||
case "l2w": | ||||
case "m": | ||||
case "lm": | ||||
case "y": | ||||
|
r8578 | case "o": | ||
case "c": | ||||
|
r14427 | case "*o": | ||
case "!o": | ||||
|
r8578 | enableValues(field, []); | ||
break; | ||||
case "><": | ||||
enableValues(field, [0,1]); | ||||
break; | ||||
case "<t+": | ||||
case ">t+": | ||||
|
r10546 | case "><t+": | ||
|
r8578 | case "t+": | ||
case ">t-": | ||||
case "<t-": | ||||
|
r10546 | case "><t-": | ||
|
r8578 | case "t-": | ||
enableValues(field, [2]); | ||||
break; | ||||
|
r10303 | case "=p": | ||
case "=!p": | ||||
|
r10348 | case "!p": | ||
|
r10303 | enableValues(field, [1]); | ||
break; | ||||
|
r8578 | default: | ||
enableValues(field, [0]); | ||||
break; | ||||
} | ||||
} | ||||
|
r9979 | function toggleMultiSelect(el) { | ||
if (el.attr('multiple')) { | ||||
el.removeAttr('multiple'); | ||||
|
r11985 | el.attr('size', 1); | ||
|
r8578 | } else { | ||
|
r9979 | el.attr('multiple', true); | ||
|
r11985 | if (el.children().length > 10) | ||
el.attr('size', 10); | ||||
else | ||||
el.attr('size', 4); | ||||
|
r8578 | } | ||
} | ||||
|
r11535 | function showTab(name, url) { | ||
|
r14346 | $('#tab-content-' + name).parent().find('.tab-content').hide(); | ||
$('#tab-content-' + name).parent().find('div.tabs a').removeClass('selected'); | ||||
|
r9885 | $('#tab-content-' + name).show(); | ||
$('#tab-' + name).addClass('selected'); | ||||
|
r11535 | //replaces current URL with the "href" attribute of the current link | ||
//(only triggered if supported by browser) | ||||
if ("replaceState" in window.history) { | ||||
window.history.replaceState(null, document.title, url); | ||||
} | ||||
|
r8710 | return false; | ||
|
r482 | } | ||
|
r3060 | function moveTabRight(el) { | ||
|
r9885 | var lis = $(el).parents('div.tabs').first().find('ul').children(); | ||
|
r14867 | var bw = $(el).parents('div.tabs-buttons').outerWidth(true); | ||
|
r8710 | var tabsWidth = 0; | ||
|
r9885 | var i = 0; | ||
|
r11514 | lis.each(function() { | ||
|
r9885 | if ($(this).is(':visible')) { | ||
|
r14867 | tabsWidth += $(this).outerWidth(true); | ||
|
r8710 | } | ||
|
r9885 | }); | ||
|
r14867 | if (tabsWidth < $(el).parents('div.tabs').first().width() - bw) { return; } | ||
$(el).siblings('.tab-left').removeClass('disabled'); | ||||
|
r9885 | while (i<lis.length && !lis.eq(i).is(':visible')) { i++; } | ||
|
r14867 | var w = lis.eq(i).width(); | ||
|
r9885 | lis.eq(i).hide(); | ||
|
r14867 | if (tabsWidth - w < $(el).parents('div.tabs').first().width() - bw) { | ||
$(el).addClass('disabled'); | ||||
} | ||||
|
r3060 | } | ||
function moveTabLeft(el) { | ||||
|
r9885 | var lis = $(el).parents('div.tabs').first().find('ul').children(); | ||
|
r8710 | var i = 0; | ||
|
r11514 | while (i < lis.length && !lis.eq(i).is(':visible')) { i++; } | ||
if (i > 0) { | ||||
|
r9885 | lis.eq(i-1).show(); | ||
|
r14867 | $(el).siblings('.tab-right').removeClass('disabled'); | ||
} | ||||
if (i <= 1) { | ||||
$(el).addClass('disabled'); | ||||
|
r8710 | } | ||
|
r3060 | } | ||
function displayTabsButtons() { | ||||
|
r8710 | var lis; | ||
|
r14242 | var tabsWidth; | ||
|
r9885 | var el; | ||
|
r14867 | var numHidden; | ||
|
r9885 | $('div.tabs').each(function() { | ||
el = $(this); | ||||
lis = el.find('ul').children(); | ||||
|
r14242 | tabsWidth = 0; | ||
|
r14867 | numHidden = 0; | ||
|
r9885 | lis.each(function(){ | ||
if ($(this).is(':visible')) { | ||||
|
r14867 | tabsWidth += $(this).outerWidth(true); | ||
} else { | ||||
numHidden++; | ||||
|
r8710 | } | ||
|
r9885 | }); | ||
|
r14867 | var bw = $(el).parents('div.tabs-buttons').outerWidth(true); | ||
if ((tabsWidth < el.width() - bw) && (lis.first().is(':visible'))) { | ||||
|
r9885 | el.find('div.tabs-buttons').hide(); | ||
|
r8710 | } else { | ||
|
r14867 | el.find('div.tabs-buttons').show().children('button.tab-left').toggleClass('disabled', numHidden == 0); | ||
|
r8710 | } | ||
}); | ||||
|
r3060 | } | ||
|
r503 | function setPredecessorFieldsVisibility() { | ||
|
r9885 | var relationType = $('#relation_relation_type'); | ||
if (relationType.val() == "precedes" || relationType.val() == "follows") { | ||||
$('#predecessor_fields').show(); | ||||
} else { | ||||
$('#predecessor_fields').hide(); | ||||
} | ||||
|
r642 | } | ||
|
r13504 | function showModal(id, width, title) { | ||
|
r9887 | var el = $('#'+id).first(); | ||
|
r11499 | if (el.length === 0 || el.is(':visible')) {return;} | ||
|
r13504 | if (!title) title = el.find('h3.title').text(); | ||
|
r13957 | // moves existing modals behind the transparent background | ||
$(".modal").zIndex(99); | ||||
|
r9887 | el.dialog({ | ||
width: width, | ||||
modal: true, | ||||
resizable: false, | ||||
dialogClass: 'modal', | ||||
title: title | ||||
|
r13958 | }).on('dialogclose', function(){ | ||
$(".modal").zIndex(101); | ||||
|
r9887 | }); | ||
|
r9885 | el.find("input[type=text], input[type=submit]").first().focus(); | ||
|
r7754 | } | ||
function hideModal(el) { | ||||
|
r8725 | var modal; | ||
|
r9885 | if (el) { | ||
|
r9887 | modal = $(el).parents('.ui-dialog-content'); | ||
|
r9885 | } else { | ||
modal = $('#ajax-modal'); | ||||
|
r7754 | } | ||
|
r9887 | modal.dialog("close"); | ||
|
r7754 | } | ||
|
r9848 | function submitPreview(url, form, target) { | ||
|
r9885 | $.ajax({ | ||
url: url, | ||||
type: 'post', | ||||
data: $('#'+form).serialize(), | ||||
success: function(data){ | ||||
$('#'+target).html(data); | ||||
} | ||||
|
r9848 | }); | ||
} | ||||
|
r850 | function collapseScmEntry(id) { | ||
|
r9885 | $('.'+id).each(function() { | ||
if ($(this).hasClass('open')) { | ||||
collapseScmEntry($(this).attr('id')); | ||||
} | ||||
$(this).hide(); | ||||
}); | ||||
$('#'+id).removeClass('open'); | ||||
|
r850 | } | ||
function expandScmEntry(id) { | ||||
|
r9885 | $('.'+id).each(function() { | ||
$(this).show(); | ||||
if ($(this).hasClass('loaded') && !$(this).hasClass('collapsed')) { | ||||
expandScmEntry($(this).attr('id')); | ||||
|
r850 | } | ||
|
r9885 | }); | ||
$('#'+id).addClass('open'); | ||||
|
r850 | } | ||
|
r9885 | function scmEntryClick(id, url) { | ||
|
r12044 | var el = $('#'+id); | ||
|
r9885 | if (el.hasClass('open')) { | ||
|
r850 | collapseScmEntry(id); | ||
|
r9885 | el.addClass('collapsed'); | ||
|
r850 | return false; | ||
|
r9885 | } else if (el.hasClass('loaded')) { | ||
|
r850 | expandScmEntry(id); | ||
|
r9885 | el.removeClass('collapsed'); | ||
|
r850 | return false; | ||
} | ||||
|
r9885 | if (el.hasClass('loading')) { | ||
|
r855 | return false; | ||
} | ||||
|
r9885 | el.addClass('loading'); | ||
$.ajax({ | ||||
url: url, | ||||
|
r11514 | success: function(data) { | ||
|
r9885 | el.after(data); | ||
el.addClass('open').addClass('loaded').removeClass('loading'); | ||||
} | ||||
}); | ||||
|
r850 | return true; | ||
} | ||||
|
r1570 | function randomKey(size) { | ||
|
r11511 | var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | ||
|
r8710 | var key = ''; | ||
|
r11511 | for (var i = 0; i < size; i++) { | ||
key += chars.charAt(Math.floor(Math.random() * chars.length)); | ||||
|
r8710 | } | ||
return key; | ||||
|
r1570 | } | ||
|
r14406 | function updateIssueFrom(url, el) { | ||
|
r11936 | $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ | ||
$(this).data('valuebeforeupdate', $(this).val()); | ||||
}); | ||||
|
r14406 | if (el) { | ||
$("#form_update_triggered_by").val($(el).attr('id')); | ||||
} | ||||
|
r13990 | return $.ajax({ | ||
|
r9885 | url: url, | ||
type: 'post', | ||||
data: $('#issue-form').serialize() | ||||
}); | ||||
|
r3459 | } | ||
|
r11936 | function replaceIssueFormWith(html){ | ||
var replacement = $(html); | ||||
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){ | ||||
var object_id = $(this).attr('id'); | ||||
if (object_id && $(this).data('valuebeforeupdate')!=$(this).val()) { | ||||
replacement.find('#'+object_id).val($(this).val()); | ||||
} | ||||
}); | ||||
$('#all_attributes').empty(); | ||||
$('#all_attributes').prepend(replacement); | ||||
} | ||||
|
r9885 | function updateBulkEditFrom(url) { | ||
$.ajax({ | ||||
url: url, | ||||
type: 'post', | ||||
data: $('#bulk_edit_form').serialize() | ||||
}); | ||||
|
r4388 | } | ||
|
r10850 | function observeAutocompleteField(fieldId, url, options) { | ||
|
r10582 | $(document).ready(function() { | ||
|
r10850 | $('#'+fieldId).autocomplete($.extend({ | ||
|
r10582 | source: url, | ||
|
r10852 | minLength: 2, | ||
|
r14919 | position: {collision: "flipfit"}, | ||
|
r10852 | search: function(){$('#'+fieldId).addClass('ajax-loading');}, | ||
|
r11498 | response: function(){$('#'+fieldId).removeClass('ajax-loading');} | ||
|
r10850 | }, options)); | ||
|
r10852 | $('#'+fieldId).addClass('autocomplete'); | ||
|
r9885 | }); | ||
} | ||||
function observeSearchfield(fieldId, targetId, url) { | ||||
$('#'+fieldId).each(function() { | ||||
var $this = $(this); | ||||
|
r10852 | $this.addClass('autocomplete'); | ||
|
r9885 | $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); | ||||
|
r10317 | $.ajax({ | ||
url: url, | ||||
type: 'get', | ||||
data: {q: $this.val()}, | ||||
|
r10970 | success: function(data){ if(targetId) $('#'+targetId).html(data); }, | ||
|
r10317 | beforeSend: function(){ $this.addClass('ajax-loading'); }, | ||
complete: function(){ $this.removeClass('ajax-loading'); } | ||||
}); | ||||
|
r9885 | } | ||
}; | ||||
var reset = function() { | ||||
if (timer) { | ||||
clearInterval(timer); | ||||
timer = setInterval(check, 300); | ||||
} | ||||
}; | ||||
var timer = setInterval(check, 300); | ||||
$this.bind('keyup click mousemove', reset); | ||||
}); | ||||
|
r4528 | } | ||
|
r13370 | function beforeShowDatePicker(input, inst) { | ||
var default_date = null; | ||||
switch ($(input).attr("id")) { | ||||
case "issue_start_date" : | ||||
if ($("#issue_due_date").size() > 0) { | ||||
default_date = $("#issue_due_date").val(); | ||||
} | ||||
break; | ||||
case "issue_due_date" : | ||||
if ($("#issue_start_date").size() > 0) { | ||||
|
r14587 | var start_date = $("#issue_start_date").val(); | ||
if (start_date != "") { | ||||
start_date = new Date(Date.parse(start_date)); | ||||
if (start_date > new Date()) { | ||||
default_date = $("#issue_start_date").val(); | ||||
} | ||||
} | ||||
|
r13370 | } | ||
break; | ||||
} | ||||
$(input).datepicker("option", "defaultDate", default_date); | ||||
} | ||||
|
r14954 | (function($){ | ||
$.fn.positionedItems = function(sortableOptions, options){ | ||||
var settings = $.extend({ | ||||
firstPosition: 1 | ||||
}, options ); | ||||
return this.sortable($.extend({ | ||||
handle: ".sort-handle", | ||||
helper: function(event, ui){ | ||||
|
r14955 | ui.children('td').each(function(){ | ||
|
r14954 | $(this).width($(this).width()); | ||
}); | ||||
return ui; | ||||
}, | ||||
update: function(event, ui) { | ||||
var sortable = $(this); | ||||
var url = ui.item.find(".sort-handle").data("reorder-url"); | ||||
var param = ui.item.find(".sort-handle").data("reorder-param"); | ||||
var data = {}; | ||||
data[param] = {position: ui.item.index() + settings['firstPosition']}; | ||||
$.ajax({ | ||||
url: url, | ||||
type: 'put', | ||||
dataType: 'script', | ||||
data: data, | ||||
success: function(data){ | ||||
sortable.children(":even").removeClass("even").addClass("odd"); | ||||
sortable.children(":odd").removeClass("odd").addClass("even"); | ||||
}, | ||||
error: function(jqXHR, textStatus, errorThrown){ | ||||
alert(jqXHR.status); | ||||
sortable.sortable("cancel"); | ||||
} | ||||
}); | ||||
}, | ||||
}, sortableOptions)); | ||||
} | ||||
}( jQuery )); | ||||
|
r9885 | 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(); | ||||
} | ||||
|
r8711 | |||
|
r9885 | var warnLeavingUnsavedMessage; | ||
function warnLeavingUnsaved(message) { | ||||
warnLeavingUnsavedMessage = message; | ||||
|
r13044 | $(document).on('submit', 'form', function(){ | ||
|
r9885 | $('textarea').removeData('changed'); | ||
}); | ||||
|
r13044 | $(document).on('change', 'textarea', function(){ | ||
|
r9885 | $(this).data('changed', 'changed'); | ||
}); | ||||
window.onbeforeunload = function(){ | ||||
var warn = false; | ||||
$('textarea').blur().each(function(){ | ||||
if ($(this).data('changed')) { | ||||
warn = true; | ||||
} | ||||
}); | ||||
if (warn) {return warnLeavingUnsavedMessage;} | ||||
}; | ||||
|
r11501 | } | ||
|
r4528 | |||
|
r10768 | function setupAjaxIndicator() { | ||
|
r13045 | $(document).bind('ajaxSend', function(event, xhr, settings) { | ||
|
r11499 | if ($('.ajax-loading').length === 0 && settings.contentType != 'application/octet-stream') { | ||
|
r9885 | $('#ajax-indicator').show(); | ||
|
r482 | } | ||
|
r9885 | }); | ||
|
r13045 | $(document).bind('ajaxStop', function() { | ||
|
r9885 | $('#ajax-indicator').hide(); | ||
}); | ||||
|
r10768 | } | ||
|
r3369 | |||
|
r14685 | function setupTabs() { | ||
if($('.tabs').length > 0) { | ||||
displayTabsButtons(); | ||||
$(window).resize(displayTabsButtons); | ||||
} | ||||
} | ||||
|
r3670 | function hideOnLoad() { | ||
|
r9885 | $('.hol').hide(); | ||
|
r3670 | } | ||
|
r9257 | function addFormObserversForDoubleSubmit() { | ||
|
r9885 | $('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(); | ||||
|
r9308 | } else { | ||
|
r9885 | $(form_submission.target).attr('data-submitted', true); | ||
|
r9308 | } | ||
|
r9257 | }); | ||
|
r9308 | } | ||
|
r9257 | }); | ||
} | ||||
|
r12395 | function defaultFocus(){ | ||
|
r14014 | if (($('#content :focus').length == 0) && (window.location.hash == '')) { | ||
|
r12395 | $('#content input[type=text], #content textarea').first().focus(); | ||
} | ||||
} | ||||
|
r10748 | function blockEventPropagation(event) { | ||
event.stopPropagation(); | ||||
event.preventDefault(); | ||||
} | ||||
|
r12125 | function toggleDisabledOnChange() { | ||
var checked = $(this).is(':checked'); | ||||
$($(this).data('disables')).attr('disabled', checked); | ||||
$($(this).data('enables')).attr('disabled', !checked); | ||||
} | ||||
function toggleDisabledInit() { | ||||
$('input[data-disables], input[data-enables]').each(toggleDisabledOnChange); | ||||
} | ||||
$(document).ready(function(){ | ||||
$('#content').on('change', 'input[data-disables], input[data-enables]', toggleDisabledOnChange); | ||||
toggleDisabledInit(); | ||||
}); | ||||
|
r14385 | function keepAnchorOnSignIn(form){ | ||
var hash = decodeURIComponent(self.document.location.hash); | ||||
if (hash) { | ||||
if (hash.indexOf("#") === -1) { | ||||
hash = "#" + hash; | ||||
} | ||||
form.action = form.action + hash; | ||||
} | ||||
return true; | ||||
} | ||||
|
r10768 | $(document).ready(setupAjaxIndicator); | ||
|
r9885 | $(document).ready(hideOnLoad); | ||
$(document).ready(addFormObserversForDoubleSubmit); | ||||
|
r12395 | $(document).ready(defaultFocus); | ||
|
r14685 | $(document).ready(setupTabs); | ||