2011-05-15 22:06:54 +02:00
|
|
|
// Load following statements, when DOM is ready
|
|
|
|
$(function() {
|
2011-05-19 19:49:37 +02:00
|
|
|
|
|
|
|
// Show/Hide a specific DOM element
|
|
|
|
$('a[data-toggle-this]').click(function() {
|
|
|
|
$($(this).data('toggle-this')).toggle();
|
2011-05-15 22:06:54 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-05-27 14:09:01 +02:00
|
|
|
// Remove this item from DOM
|
|
|
|
$('a[data-remove-this').click(function() {
|
|
|
|
$($(this).data('remove-this')).remove();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-05-19 19:49:37 +02:00
|
|
|
// Check/Uncheck a single checkbox
|
|
|
|
$('[data-check-this]').live('click', function() {
|
|
|
|
var checkbox = $($(this).data('check-this'));
|
|
|
|
checkbox.attr('checked', !checkbox.is(':checked'));
|
|
|
|
highlightRow(checkbox);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-06-10 13:53:51 +02:00
|
|
|
// Check/Uncheck all checkboxes for a specific form
|
2011-05-19 19:49:37 +02:00
|
|
|
$('input[data-check-all]').live('click', function() {
|
|
|
|
var status = $(this).is(':checked')
|
|
|
|
$($(this).data('check-all')).find('input[type="checkbox"]').each(function() {
|
|
|
|
$(this).attr('checked', status);
|
|
|
|
highlightRow($(this));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Submit form when changing a select menu.
|
|
|
|
$('form[data-submit-onchange] select').live('change', function() {
|
|
|
|
var confirmMessage = $(this).children(':selected').data('confirm');
|
|
|
|
if (confirmMessage && confirm(confirmMessage)) {
|
|
|
|
$(this).parents('form').submit();
|
|
|
|
} else {
|
|
|
|
$(this).parents('form').submit();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Submit form when changing text of an input field
|
|
|
|
// Use jquery observe_field plugin
|
|
|
|
$('form[data-submit-onchange] input[type=text]').each(function() {
|
|
|
|
$(this).observe_field(1, function() {
|
|
|
|
$(this).parents('form').submit();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Submit form when clicking on checkbox
|
|
|
|
$('form[data-submit-onchange] input[type=checkbox]:not(input[data-ignore-onchange])').click(function() {
|
|
|
|
$(this).parents('form').submit();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('[data-redirect-to]').bind('change', function() {
|
|
|
|
var newLocation = $(this).children(':selected').val();
|
|
|
|
if (newLocation != "") {
|
|
|
|
document.location.href = newLocation;
|
|
|
|
}
|
|
|
|
});
|
2011-06-10 11:43:56 +02:00
|
|
|
|
|
|
|
// Remote paginations
|
|
|
|
$('div.pagination[data-remote] a').live('click', function() {
|
|
|
|
$.getScript($(this).attr('href'));
|
|
|
|
return false;
|
|
|
|
});
|
2011-05-19 19:49:37 +02:00
|
|
|
});
|
2011-05-15 22:06:54 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
|
|
|
|
// gives the row an yellow background
|
2011-05-19 19:49:37 +02:00
|
|
|
function highlightRow(checkbox) {
|
|
|
|
var row = checkbox.parents('tr');
|
|
|
|
if (checkbox.is(':checked')) {
|
|
|
|
row.addClass('selected');
|
|
|
|
} else {
|
|
|
|
row.removeClass('selected');
|
|
|
|
}
|
2009-01-06 11:49:19 +01:00
|
|
|
|
|
|
|
}
|
2009-02-09 20:12:56 +01:00
|
|
|
|
|
|
|
// Use with auto_complete to set a unique id,
|
|
|
|
// e.g. when the user selects a (may not unique) name
|
|
|
|
// There must be a hidden field with the id 'hidden_field'
|
|
|
|
function setHiddenId(text, li) {
|
|
|
|
$('hidden_id').value = li.id;
|
|
|
|
}
|