/** * * Full Calendar callback methods. * */ function scheduleRefetchEvents(json) { if(json.show_error == true){ alert("The show instance doesn't exist anymore!") } $("#schedule_calendar").fullCalendar( 'refetchEvents' ); } function openAddShowForm() { if($("#add-show-form").length == 1) { if( ($("#add-show-form").css('display')=='none')) { $("#add-show-form").show(); var windowWidth = $(window).width(); // margin on showform are 16 px on each side var calendarWidth = 100-(($("#schedule-add-show").width() + (16 * 4))/windowWidth*100); var widthPercent = parseInt(calendarWidth)+"%"; $("#schedule_calendar").css("width", widthPercent); $("#schedule_calendar").fullCalendar('render'); } $("#schedule-show-what").show(0, function(){ $add_show_name = $("#add_show_name"); $add_show_name.focus(); $add_show_name.select(); }); } } function makeAddShowButton(){ $('.fc-header-left') .append('') .append('Show') .find('span.fc-button:last > a') .click(function(){ openAddShowForm(); removeAddShowButton(); }); } function removeAddShowButton(){ var aTag = $('.fc-header-left') .find("span.fc-button:last > a"); var span = aTag.parent(); span.prev().remove(); span.remove(); } function pad(number, length) { var str = '' + number; while (str.length < length) { str = '0' + str; } return str; } function makeTimeStamp(date){ var sy, sm, sd, h, m, s, timestamp; sy = date.getFullYear(); sm = date.getMonth() + 1; sd = date.getDate(); h = date.getHours(); m = date.getMinutes(); s = date.getSeconds(); timestamp = sy+"-"+ pad(sm, 2) +"-"+ pad(sd, 2) +" "+ pad(h, 2) +":"+ pad(m, 2) +":"+ pad(s, 2); return timestamp; } function adjustDateToServerDate(date, serverTimezoneOffset){ //date object stores time in the browser's localtime. We need to artificially shift //it to var timezoneOffset = date.getTimezoneOffset()*60*1000; date.setTime(date.getTime() + timezoneOffset + serverTimezoneOffset*1000); /* date object has been shifted to artificial UTC time. Now let's * shift it to the server's timezone */ return date; } function pad(number, length) { var str = '' + number; while (str.length < length) { str = '0' + str; } return str; } function dayClick(date, allDay, jsEvent, view) { var now, today, selected, chosenDate, chosenTime; now = adjustDateToServerDate(new Date(), serverTimezoneOffset); if(view.name === "month") { today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); selected = new Date(date.getFullYear(), date.getMonth(), date.getDate()); } else { today = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes()); selected = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes()); } if(selected >= today) { var addShow = $('.add-button'); //remove the +show button if it exists. if(addShow.length == 1){ var span = $(addShow).parent(); $(span).prev().remove(); $(span).remove(); } // 1 hr var duration = 60 * 60* 1000; var endDateTime = new Date(selected.getTime() + duration); chosenDate = selected.getFullYear() + '-' + pad(selected.getMonth()+1,2) + '-' + pad(selected.getDate(),2); chosenTime = pad(selected.getHours(),2) + ':' + pad(selected.getMinutes(),2); var endDateFormat = endDateTime.getFullYear() + '-' + pad(endDateTime.getMonth()+1,2) + '-' + pad(endDateTime.getDate(),2); var endTimeFormat = pad(endDateTime.getHours(),2) + ':' + pad(endDateTime.getMinutes(),2); $("#add_show_start_date").val(chosenDate); $("#add_show_end_date_no_repeat").val(endDateFormat); $("#add_show_end_date").datepicker("option", "minDate", endDateFormat); $("#add_show_end_date").val(endDateFormat); $("#add_show_start_time").val(chosenTime); $("#add_show_end_time").val(endTimeFormat); $("#add_show_duration").val('1h'); $("#schedule-show-when").show(); openAddShowForm(); } } function viewDisplay( view ) { if(view.name === 'agendaDay' || view.name === 'agendaWeek') { var calendarEl = this; var select = $('