/** * * Full Calendar callback methods. * */ function scheduleRefetchEvents(json) { if (json.show_error == true) { alert($.i18n._("The show instance doesn't exist anymore!")); } if (json.show_id) { var dialog_id = parseInt($("#add_show_id").val(), 10); //if you've deleted the show you are currently editing, close the add show dialog. if (dialog_id === json.show_id) { $("#add-show-close").click(); } } $("#schedule_calendar").fullCalendar('refetchEvents'); } 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 dayClick(date, allDay, jsEvent, view) { // The show from will be preloaded if the user is admin or program manager. // Hence, if the user if DJ then it won't open anything. if (userType == "S" || userType == "A" || userType == "P") { 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).next().remove(); $(span).remove(); } // get current duration value on the form var duration_string = $.trim($("#add_show_duration").val()); var duration_info = duration_string.split(" "); var duration_h = 0; var duration_m = 0; if (duration_info[0] != null) { duration_h = parseInt(duration_info[0], 10); } if (duration_info[1] != null) { duration_m = parseInt(duration_info[1], 10); } // duration in milisec var duration = (duration_h * 60 * 60 * 1000) + (duration_m * 60 * 1000); var startTime_string; var startTime = 0; // get start time value on the form if (view.name === "month") { startTime_string = $("#add_show_start_time").val(); var startTime_info = startTime_string.split(':'); if (startTime_info.length == 2) { var start_time_temp = (parseInt(startTime_info[0], 10) * 60 * 60 * 1000) + (parseInt(startTime_info[1], 10) * 60 * 1000); if (!isNaN(start_time_temp)) { startTime = start_time_temp; } } } else { // if in day or week view, selected has all the time info as well // so we don't ahve to calculate it explicitly startTime_string = pad(selected.getHours(), 2) + ":" + pad(selected.getMinutes(), 2) startTime = 0 } // calculate endDateTime var endDateTime = new Date(selected.getTime() + startTime + duration); chosenDate = selected.getFullYear() + '-' + pad(selected.getMonth() + 1, 2) + '-' + pad(selected.getDate(), 2); var endDateFormat = endDateTime.getFullYear() + '-' + pad(endDateTime.getMonth() + 1, 2) + '-' + pad(endDateTime.getDate(), 2); //TODO: This should all be refactored into a proper initialize() function for the show form. $("#add_show_start_now-future").attr('checked', 'checked'); $("#add_show_start_now-now").removeProp('disabled'); setupStartTimeWidgets(); //add-show.js $("#add_show_start_date").val(chosenDate); $("#add_show_end_date_no_repeat").val(endDateFormat); $("#add_show_end_date").val(endDateFormat); if (view.name !== "month") { var endTimeString = pad(endDateTime.getHours(), 2) + ":" + pad(endDateTime.getMinutes(), 2); $("#add_show_start_time").val(startTime_string) $("#add_show_end_time").val(endTimeString) } calculateShowColor(); $("#schedule-show-when").show(); openAddShowForm(); makeAddShowButton(); toggleAddShowButton(); } } } function viewDisplay(view) { view_name = view.name; if (view.name === 'agendaDay' || view.name === 'agendaWeek') { var calendarEl = this; var select = $('