2012-09-30 21:15:55 +02:00
|
|
|
//= require jquery
|
|
|
|
//= require jquery_ujs
|
2016-08-12 15:54:28 +02:00
|
|
|
//= require select2-full
|
2012-10-06 17:14:57 +02:00
|
|
|
//= require twitter/bootstrap
|
2012-09-30 21:15:55 +02:00
|
|
|
//= require jquery.tokeninput
|
2013-07-07 01:47:22 +02:00
|
|
|
//= require bootstrap-datepicker/core
|
|
|
|
//= require bootstrap-datepicker/locales/bootstrap-datepicker.de
|
2017-11-06 14:15:53 +01:00
|
|
|
//= require bootstrap-datepicker/locales/bootstrap-datepicker.es
|
2013-07-07 01:47:22 +02:00
|
|
|
//= require bootstrap-datepicker/locales/bootstrap-datepicker.nl
|
2013-10-17 16:48:34 +02:00
|
|
|
//= require bootstrap-datepicker/locales/bootstrap-datepicker.fr
|
2013-09-18 23:15:21 +02:00
|
|
|
//= require list
|
|
|
|
//= require list.unlist
|
2013-10-04 18:28:45 +02:00
|
|
|
//= require list.delay
|
|
|
|
//= require list.reset
|
2013-10-04 14:53:22 +02:00
|
|
|
//= require i18n
|
|
|
|
//= require i18n/translations
|
2012-09-30 21:15:55 +02:00
|
|
|
//= require_self
|
|
|
|
//= require ordering
|
2013-07-16 22:01:56 +02:00
|
|
|
//= require stupidtable
|
2014-01-25 15:19:50 +01:00
|
|
|
//= require touchclick
|
2014-01-23 16:17:16 +01:00
|
|
|
//= require delta_input
|
2014-11-22 00:33:16 +01:00
|
|
|
//= require recurring_select
|
2012-09-30 21:15:55 +02:00
|
|
|
|
2016-08-12 15:54:28 +02:00
|
|
|
$.fn.select2.defaults.set('theme', 'bootstrap');
|
|
|
|
|
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
|
2013-07-08 22:41:06 +02:00
|
|
|
$(document).on('click', 'a[data-toggle-this]', function() {
|
2011-05-19 19:49:37 +02:00
|
|
|
$($(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
|
2013-07-08 22:41:06 +02:00
|
|
|
$(document).on('click', 'a[data-remove-this]', function() {
|
2011-05-27 14:09:01 +02:00
|
|
|
$($(this).data('remove-this')).remove();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-05-19 19:49:37 +02:00
|
|
|
// Check/Uncheck a single checkbox
|
2013-07-08 22:41:06 +02:00
|
|
|
$(document).on('click', '[data-check-this]', function() {
|
2011-05-19 19:49:37 +02:00
|
|
|
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
|
2013-07-08 22:41:06 +02:00
|
|
|
$(document).on('click', 'input[data-check-all]', function() {
|
2013-06-06 17:06:05 +02:00
|
|
|
var status = $(this).is(':checked');
|
|
|
|
var context = $(this).data('check-all');
|
|
|
|
var elms = $('input[type="checkbox"]', context);
|
|
|
|
for(i=elms.length-1; i>=0; --i) { // performance can be an issue here, so use native loop
|
|
|
|
var elm = elms[i];
|
|
|
|
elm.checked = status;
|
|
|
|
highlightRow($(elm));
|
|
|
|
}
|
2011-05-19 19:49:37 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Submit form when changing a select menu.
|
2014-02-19 16:21:00 +01:00
|
|
|
$(document).on('change', 'form[data-submit-onchange] select:not([data-ignore-onchange])', function() {
|
2011-05-19 19:49:37 +02:00
|
|
|
var confirmMessage = $(this).children(':selected').data('confirm');
|
2012-10-28 18:03:50 +01:00
|
|
|
if (confirmMessage) {
|
|
|
|
if (confirm(confirmMessage)) {
|
|
|
|
$(this).parents('form').submit();
|
|
|
|
}
|
2011-05-19 19:49:37 +02:00
|
|
|
} else {
|
|
|
|
$(this).parents('form').submit();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Submit form when clicking on checkbox
|
2014-02-19 16:21:00 +01:00
|
|
|
$(document).on('click', 'form[data-submit-onchange] input[type=checkbox]:not([data-ignore-onchange])', function() {
|
2011-05-19 19:49:37 +02:00
|
|
|
$(this).parents('form').submit();
|
|
|
|
});
|
|
|
|
|
2014-01-23 16:17:16 +01:00
|
|
|
// Submit form when changing text of an input field.
|
2014-02-19 11:41:10 +01:00
|
|
|
// Submission will be done after 500ms of not typed, unless data-submit-onchange=changed,
|
2014-01-23 16:17:16 +01:00
|
|
|
// in which case it happens when the input box loses its focus ('changed' event).
|
2014-05-07 10:55:26 +02:00
|
|
|
// (changeDate is for bootstrap-datepicker)
|
|
|
|
$(document).on('changed keyup focusin changeDate', 'form[data-submit-onchange] input[type=text]:not([data-ignore-onchange])', function(e) {
|
2014-01-23 16:17:16 +01:00
|
|
|
var input = $(this);
|
|
|
|
// when form has data-submit-onchange=changed, don't do updates while typing
|
2014-05-07 10:55:26 +02:00
|
|
|
if (e.type!='changed' && e.type!='changeDate' && input.parents('form[data-submit-onchange=changed]').length>0) {
|
2014-01-23 16:17:16 +01:00
|
|
|
return true;
|
|
|
|
}
|
2014-05-07 10:55:26 +02:00
|
|
|
// remember old value when it's getting the focus (unless we already have a change pending)
|
2014-01-23 16:17:16 +01:00
|
|
|
if (e.type=='focusin') {
|
2014-05-07 10:55:26 +02:00
|
|
|
if (!input.data('submit-timeout-id')) input.data('old-value', input.val());
|
2014-01-23 16:17:16 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// trigger timeout to submit form when value was changed
|
|
|
|
clearTimeout(input.data('submit-timeout-id'));
|
|
|
|
input.data('submit-timeout-id', setTimeout(function() {
|
|
|
|
if (input.val() != input.data('old-value')) input.parents('form').submit();
|
|
|
|
input.removeData('submit-timeout-id');
|
|
|
|
input.removeData('old-value');
|
|
|
|
}, 500));
|
|
|
|
});
|
|
|
|
|
2011-05-19 19:49:37 +02:00
|
|
|
$('[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
|
2013-07-08 22:41:06 +02:00
|
|
|
$(document).on('click', 'div.pagination[data-remote] a', function() {
|
2011-06-10 11:43:56 +02:00
|
|
|
$.getScript($(this).attr('href'));
|
|
|
|
return false;
|
|
|
|
});
|
2011-06-20 00:48:05 +02:00
|
|
|
|
2013-12-18 22:22:34 +01:00
|
|
|
// Disable action of disabled buttons
|
|
|
|
$(document).on('click', 'a.disabled', function() {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2014-07-02 13:55:05 +02:00
|
|
|
// Handle ajax errors
|
|
|
|
// render json: {error: "can't except this!"}, status: :unprocessable_entity
|
|
|
|
$(document).ajaxError(function(ev, xhr, settings, exception) {
|
|
|
|
try {
|
|
|
|
msg = xhr.responseJSON.error;
|
|
|
|
} catch(err) {
|
|
|
|
msg = I18n.t('errors.general');
|
|
|
|
}
|
|
|
|
alert(msg);
|
2011-06-20 00:48:05 +02:00
|
|
|
});
|
2012-10-08 21:52:03 +02:00
|
|
|
|
2013-12-23 11:50:57 +01:00
|
|
|
// The autocomplete attribute is used for both autocompletion and storing
|
|
|
|
// for passwords, it's nice to store it when editing one's own profile,
|
|
|
|
// but never autocomplete. Only implemented for passwords.
|
|
|
|
$('input[type="password"][autocomplete="off"][data-store="on"]').each(function() {
|
|
|
|
$(this).on('change', function() {
|
|
|
|
$(this).removeAttr('autocomplete');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-10-08 21:52:03 +02:00
|
|
|
// Use bootstrap datepicker for dateinput
|
2014-02-20 12:37:51 +01:00
|
|
|
$('.datepicker').datepicker({format: 'yyyy-mm-dd', language: I18n.locale, todayHighlight: true});
|
2013-10-09 10:35:27 +02:00
|
|
|
|
|
|
|
// bootstrap tooltips (for price)
|
|
|
|
// Extra options don't work when using selector, so override defaults
|
|
|
|
// https://github.com/twbs/bootstrap/issues/3875 . These can still be
|
|
|
|
// overridden per tooltip using data-placement attributes and the like.
|
|
|
|
$.extend($.fn.tooltip.defaults, {
|
|
|
|
html: true,
|
|
|
|
animation: false,
|
|
|
|
placement: 'left',
|
|
|
|
container: 'body'
|
|
|
|
});
|
|
|
|
$(document).tooltip({
|
|
|
|
selector: '[data-toggle~="tooltip"]',
|
|
|
|
});
|
2016-08-12 15:54:28 +02:00
|
|
|
|
2013-07-16 22:01:56 +02:00
|
|
|
// See stupidtable.js for initialization of local table sorting
|
2011-05-19 19:49:37 +02:00
|
|
|
});
|
2011-05-15 22:06:54 +02:00
|
|
|
|
2013-07-16 22:01:56 +02:00
|
|
|
// retrigger last local table sorting
|
|
|
|
function updateSort(table) {
|
|
|
|
$('.sorting-asc, .sorting-desc', table).toggleClass('.sorting-asc .sorting-desc')
|
|
|
|
.removeData('sort-dir').trigger('click'); // CAUTION: removing data field of plugin
|
2013-06-13 23:33:24 +02:00
|
|
|
}
|
2009-01-06 11:49:19 +01:00
|
|
|
|
|
|
|
// gives the row an yellow background
|
2013-06-06 17:09:22 +02:00
|
|
|
function highlightRow(checkbox) {
|
2013-07-16 22:03:47 +02:00
|
|
|
var row = checkbox.closest('tr');
|
|
|
|
if (checkbox.is(':checked')) {
|
2013-07-16 22:04:44 +02:00
|
|
|
row.addClass('selected');
|
2013-07-16 22:03:47 +02:00
|
|
|
} else {
|
2013-07-16 22:04:44 +02:00
|
|
|
row.removeClass('selected');
|
2013-07-16 22:03:47 +02:00
|
|
|
}
|
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;
|
2013-06-13 23:33:24 +02:00
|
|
|
}
|