var Calendar = function(dom,page_id,event_date=''){ c = this; this.title = $("#current_title"); this.calendar = $(dom); this.nextBtn = $("#next_month_btn"); this.prevBtn = $("#prev_month_btn"); this.todayBtn = $("#today_btn"); this.modeBtns = $(".calendar_mode button"); this.refreshBtn = $("#refresh_btn"); this.dialog = new EventDialog(c); this.loading = $('#calendar-loading'); this.agenda_space = $("#calendar_agenda"); this.currentView = "month"; this.page_id = page_id; this.navigation = $("#navigation"); this.rangeSelection = $("#range_selection"); var agendaView = new AgendaView(c); var loadeventsonviewchange = false; this.initialize = function(){ if (event_date != ''){ var event_dates = event_date.split("-"); var date = new Date(Date.UTC(event_dates[0],event_dates[1],event_dates[2])); }else{ var date = new Date(); } // var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); var dview = (c.currentView == "agenda" ? "month" : c.currentView); c.calendar.fullCalendar({ editable: false, selectable: false, events: "/xhr/calendars/events?page_id="+c.page_id+"&locale="+I18n.locale, header: false, default: dview, height: $("body").height() - 141, loading: function(bool) { if (bool) c.loading.css("left",($(window).width()/2 - 60) + "px").show(); else c.loading.hide(); }, windowResize : function(view){ view.setHeight($("body").height() - 141); c.calendar.fullCalendar("refetchEvents"); }, viewDisplay: function(view) { c.title.html(view.title); }, eventClick: function(calEvent, e, view) { c.dialog.dismiss(); c.dialog.inflate(calEvent); c.dialog.show({"x":e.originalEvent.clientX,"y":e.originalEvent.clientY}); } }); if (event_date != ''){ c.calendar.fullCalendar('gotoDate', y, (m - 1), d); } c.nextBtn.click(function(){ c.dialog.dismiss(); c.calendar.fullCalendar('next'); }); c.prevBtn.click(function(){ c.dialog.dismiss(); c.calendar.fullCalendar('prev'); }); c.todayBtn.click(function(){ c.dialog.dismiss(); c.calendar.fullCalendar('today'); }); c.modeBtns.click(function(){ c.dialog.dismiss(); toggleViews($(this).data("mode")); }); c.refreshBtn.click(function(){ c.dialog.dismiss(); if(c.currentView == "agenda") agendaView.refresh(); else c.calendar.fullCalendar("refetchEvents"); }); var toggleViews = function(view){ c.modeBtns.removeClass("active"); c.modeBtns.each(function(){ if ($(this).data("mode") == view) $(this).addClass("active"); }) if(view != "agenda"){ if(c.currentView == "agenda"){ // $("#sec1").addClass("span3").removeClass("span7"); $("#sec2").show(); // $("#sec3").addClass("span4").removeClass("span5"); agendaView.hide(); } c.calendar.fullCalendar('changeView',view); }else{ // $("#sec1").addClass("span7").removeClass("span3"); $("#sec2").hide(); // $("#sec3").addClass("span5").removeClass("span4"); agendaView.inflate(); } c.currentView = view; if(loadeventsonviewchange){ c.calendar.fullCalendar("refetchEvents"); loadeventsonviewchange = false; } } if(c.currentView == "agenda"){toggleViews("agenda");loadeventsonviewchange = true;} } this.renderEvent = function(eventStick){ if(eventStick.recurring == true) c.calendar.fullCalendar("refetchEvents"); else c.calendar.fullCalendar("renderEvent",eventStick); } $(document).ready(function() { c.initialize(); }); } var EventDialog = function(calendar,event){ _t = this; var event_quick_view = null; var template = ""; var _this_event = null; var month_names = ["Jan","Feb","March","April","May","June","July","Aug","Sep","Oct","Nov","Dec"]; this.inflate = function(_event){ if(!_event) throw new UserException("EventStick can't be null!"); _this_event = _event; var start_time = "", end_time = "", time_string = null; if(_event.allDay) { start_time = $.fullCalendar.formatDate(_event._start,"MMM dd, yyyy"); if(_event._end) end_time = $.fullCalendar.formatDate(_event._end,"MMM dd, yyyy"); time_string = (_event._start === _event._end || !_event._end ? "

" + start_time + "

" : " " + start_time + " " + end_time + ""); } else { var sh = _event._start.getHours() > 12 ? _event._start.getHours() - 12 : _event._start.getHours(), eh = _event._end.getHours() > 12 ? _event._end.getHours() - 12 : _event._end.getHours(), sm = _event._start.getMinutes() < 10 ? '0' + _event._start.getMinutes() : _event._start.getMinutes(), em = _event._end.getMinutes() < 10 ? '0' + _event._end.getMinutes() : _event._end.getMinutes(), stime = _event._start.getHours() > 12 ? sh + ':' + sm + " PM" : sh + ':' + sm + " AM", etime = _event._end.getHours() > 12 ? eh + ':' + em + " PM" : eh + ':' + em + " AM", same = (_event._start.getDate() == _event._end.getDate() && _event._start.getMonth() == _event._end.getMonth() && _event._start.getFullYear() == _event._end.getFullYear()); start_time = month_names[_event._start.getMonth()] + " " + _event._start.getDate() + ", " + _event._start.getFullYear(); end_time = month_names[_event._end.getMonth()] + " " + _event._end.getDate() + ", " + _event._end.getFullYear(); time_string = (same ? "

" + start_time + "

" + stime + " " + etime : "

" + start_time + "" + stime + "

" + end_time + "" + etime + "

"); } event_quick_view = $(''); template = '