Files
racalmas/website/agenda/planung/js/studio-timeslots.js
2024-04-21 00:14:03 +02:00

136 lines
3.8 KiB
JavaScript

// preselect options in select boxes
function setSelectedOptions(){
$('#edit_schedule select').each(
function(){
var value=$(this).attr('value');
if (value==null) return;
$(this).children().each(
function(){
if ($(this).attr('value')==value){
$(this).attr('selected','selected');
}
}
);
}
);
}
function updateWeekdays(){
$('.schedule input.datetimepicker').each(
function(){
var weekday=getWeekday(parseDateTime($(this).val()));
$(this).parent().prev().html(weekday);
}
);
}
function showDates(){
var date=$('#show_date select').val();
var url='studio-timeslots.cgi?';
url+='project_id='+getProjectId();
url+='&studio_id='+getStudioId();
url+='&action=show_dates';
url+='&show_date='+date;
updateContainer(
'show_schedule',
url,
function(){
initTable();
}
);
}
function initTable(){
$('#schedule_table').tablesorter({
widgets: ["filter","scroller"],
widgetOptions : {
scroller_height : 500,
scroller_width : '100%',
scroller_barWidth : 18,
scroller_upAfterSort: true,
scroller_jumpToHeader: true,
scroller_idPrefix : 's_'
},
usNumberFormat : false
});
$('.tablesorter-scroller-header').css('width','95%');
$('.tablesorter-scroller-table').css('width','95%');
$('.tablesorter-scroller-header table').css('width','95%');
$('.tablesorter-scroller-table table').css('width','95%');
}
// show/hide schedule fields depending on period type for a given schedule element
function showScheduleFields(id){
var select='#'+id+' select[name="period_type"]';
var type=$(select).val();
//hide and show values for different schedule types
if (type=='days' || type=='') {
$('#'+id+' div.cell.frequency').show();
$('#'+id+' div.cell.end').show();
$('#'+id+' div.cell.schedule_weekday').hide();
$('#'+id+' div.cell.week_of_month').hide();
$('#'+id+' div.cell.schedule_month').hide();
$('#'+id+' div.cell.nextDay').hide();
}else if(type=='week_of_month'){
$('#'+id+' div.cell.frequency').hide();
$('#'+id+' div.cell.end').show();
$('#'+id+' div.cell.schedule_weekday').show();
$('#'+id+' div.cell.week_of_month').show();
$('#'+id+' div.cell.schedule_month').show();
$('#'+id+' div.cell.nextDay').show();
}else{
alert("invalid schedule type");
}
}
function initScheduleFields(){
$('div.row.schedule form').each(function(){
var id = $(this).attr('id');
if(contains(id,'schedule_'))showScheduleFields(id);
});
}
$(document).ready(
function(){
setupLocalization(function(){
addBackButton();
updateWeekdays();
});
setTabs('#tabs');
initTextWidth();
setTextWidth('.datetimepicker.start', 130);
setTextWidth('.datetimepicker.end', 130);
setTextWidth('.datetimepicker.end_date', 90);
setTextWidth('.datetimepicker.weekday', 20);
setTextWidth('.datetimepicker.frequency', 20);
showDateTimePicker('.datetimepicker.start', {
onSelect: function(){updateWeekdays();}
});
showDateTimePicker('.datetimepicker.end', {
onSelect: function(){updateWeekdays();}
});
showDatePicker('.datetimepicker.end_date', {
onSelect: function(){updateWeekdays();}
});
initScheduleFields();
setSelectedOptions();
showYearPicker('#show_date', {
onSelect: function(){
showDates();
}
});
showDates();
});