bouffeatulm/tpl/default/js/main.js

93 lines
3.5 KiB
JavaScript
Raw Normal View History

function set_days_month_year() {
2013-08-22 23:14:14 +02:00
var date_day = $('#date_day option:selected').val();
var date_month = $('#date_month option:selected').val();
var date_year = $('#date_year option:selected').val();
// Handle day for month
if(["4", "6", "9", "11"].indexOf(date_month) > -1) {
(! $('#date_day options[value=29]').length) && $('#date_day').append('<option value="29">29</option>');
(! $('#date_day options[value=30]').length) && $('#date_day').append('<option value="30">30</option>');
$('#date_day option[value=31]').remove();
}
else if(date_month == "2") {
// Handle bissextile years
$('#date_day option[value=30]').remove();
$('#date_day option[value=31]').remove();
if(date_year % 4 != 0 || date_year % 400 == 0) {
$('#date_day option[value=29]').remove();
}
}
else {
(! $('#date_day options[value=29]').length) && $('#date_day').append('<option value="29">29</option>');
(! $('#date_day options[value=30]').length) && $('#date_day').append('<option value="30">30</option>');
(! $('#date_day options[value=31]').length) && $('#date_day').append('<option value="31">31</option>');
}
}
2013-08-17 18:43:35 +02:00
function guest_user_label(id) {
if(document.getElementById('guest_user_'+id).value > 1) {
2013-08-17 18:43:35 +02:00
document.getElementById('guest_user_'+id+'_label').innerHTML = ' guests';
if(!document.getElementById('users_in_'+id).checked) {
document.getElementById('users_in_'+id).checked = true;
}
}
2013-08-17 18:43:35 +02:00
else
document.getElementById('guest_user_'+id+'_label').innerHTML = ' guest';
2013-08-17 18:43:35 +02:00
}
function toggle_password(id) {
if(document.getElementById(id).type == 'password')
document.getElementById(id).type = 'text';
else
document.getElementById(id).type = 'password';
}
2013-08-30 20:07:52 +02:00
function payback_nobody() {
var users = document.getElementById('global_payback_form').getElementsByClassName("users_in");
for(var index = 0; index < users.length; index ++) {
users[index].checked = false;
}
return false;
}
function payback_everybody() {
var users = document.getElementById('global_payback_form').getElementsByClassName("users_in");
for(var index = 0; index < users.length; index ++) {
users[index].checked = true;
}
return false;
}
2013-08-30 20:07:52 +02:00
$(document).ready(function() {
$('#balance_table td, #global_paybacks_table td').hover(function() {
2013-08-30 20:07:52 +02:00
$(this).closest('tr').find('td,th').addClass('highlight_td');
var col = $(this).index()+1;
$(this).closest('table').find('tr :nth-child('+col+')').addClass('highlight_td');
}, function() {
$(this).closest('tr').find('td,th').removeClass('highlight_td');
var col = $(this).index()+1;
$(this).closest('table').find('tr :nth-child('+col+')').removeClass('highlight_td');
});
$('#balance_table tr:first-child th:not(:first-child), #global_paybacks_table tr:first-child th:not(:first-child)').hover(function() {
2013-08-30 20:07:52 +02:00
var col = $(this).index()+1;
$(this).closest('table').find('tr :nth-child('+col+')').addClass('highlight_td');
}, function() {
var col = $(this).index()+1;
$(this).closest('table').find('tr :nth-child('+col+')').removeClass('highlight_td');
});
2013-09-08 16:29:55 +02:00
if($('#invoice_form').length) {
$('#invoice_form input[id^=users_in]').each(function () {
var id = $(this).attr('id').replace('users_in_', '');
guest_user_label(id);
});
}
2013-08-30 20:07:52 +02:00
});