chrono/chrono/manager/static/js/chrono.manager.js

65 lines
2.9 KiB
JavaScript

$(function() {
$('[data-total]').each(function() {
var total = $(this).data('total');
var booked = $(this).data('booked');
$(this).find('.occupation-bar').css('max-width', 100 * booked / total + '%');
});
$('.date-title').on('click', function() {
const $datePicker = $(this).parent().find('.date-picker');
$datePicker.toggle();
if ($datePicker.css("display") !== "none" && document.body.classList.contains("dayview")) {
const dateInput = document.querySelector('.date-picker--input');
dateInput.focus();
if (dateInput.showPicker) dateInput.showPicker();
}
});
$('.date-picker-opener').on('click', function() { $('.date-title').trigger('click'); });
$('.date-picker button').on('click', function() {
if (document.body.classList.contains("dayview")) {
window.location = '../../../' + $('.date-picker--input').val().replaceAll("-", '/') + '/';
return false;
}
if ($('[name=day]').val()) {
window.location = '../../../' + $('[name=year]').val() + '/' + $('[name=month]').val() + '/' + $('[name=day]').val() + '/';
} else if ($('[name=month]').val()) {
window.location = '../../../' + $('[name=year]').val() + '/' + $('[name=month]').val() + '/1/';
} else {
window.location = '../../../' + $('[name=week]').val() + '/';
}
return false;
});
if (window.navigator.userAgent.indexOf('MSIE') > 0 || window.navigator.userAgent.match(/Trident.*rv\:11\./)) {
// IE doesn't support percentage units inside table cells so we have to go
// over all <div>s and convert the values to pixels.
var td_height = $('table.agenda-table tbody td').height();
$('table.agenda-table tbody td div').each(function(idx, elem) {
var parsed_height = $(elem).attr('style').match(/height: ([0-9]+)%/)[1];
$(elem).css('height', (parseInt(parsed_height) * td_height / 100) + 'px');
var parsed_top = $(elem).attr('style').match(/top: ([0-9]+)%/)[1];
$(elem).css('top', (parseInt(parsed_top) * td_height / 100) + 'px');
var parsed_min_height = $(elem).attr('style').match(/min-height: ([0-9]+)%/);
if (parsed_min_height) {
$(elem).css('min-height', (parseInt(parsed_min_height[1]) * td_height / 100) + 'px');
}
});
}
if ($('#add-custom-field-form').length) {
var property_forms = $('.custom-field-form');
var total_form = $('#id_form-TOTAL_FORMS');
var form_num = property_forms.length - 1;
$('#add-custom-field-form').on('click', function() {
var new_form = $(property_forms[0]).clone();
var form_regex = RegExp(`form-(\\d){1}-`,'g');
form_num++;
new_form.html(new_form.html().replace(form_regex, `form-${form_num}-`));
new_form.appendTo('#custom-field-forms tbody');
$('#id_form-' + form_num + '-varname').val('');
$('#id_form-' + form_num + '-label').val('');
$('#id_form-' + form_num + '-field_type').val('');
total_form.val(form_num + 1);
})
}
});