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

60 lines
2.6 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() {
$(this).parent().find('.date-picker').toggle();
});
$('.date-picker button').on('click', function() {
if ($('[name=day]').val()) {
window.location = '../../../' + $('[name=year]').val() + '/' + $('[name=month]').val() + '/' + $('[name=day]').val() + '/';
} else {
window.location = '../../' + $('[name=year]').val() + '/' + $('[name=month]').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);
})
}
/* focus tab from #open:<tab slug> anchor, to point to open panel */
if (document.location.hash && document.location.hash.indexOf('#open:') == 0) {
const $tab_button = $('#tab-' + document.location.hash.substring(6) + '[role=tab]');
if ($tab_button.length) {
$('.pk-tabs')[0].tabs.selectTab($tab_button[0]);
}
}
});