diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index da8ab164999..e7d1974e595 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -30,7 +30,12 @@ class CalendarsController < ApplicationController return redirect_to(calendar_url_for([@context])) end get_all_pertinent_contexts(true) # passing true has it return groups too. - build_calendar_dates + if params[:event_id] + event = CalendarEvent.find_by_id(params[:event_id]) + event = nil if event && event.start_at.nil? + @active_event_id = event.id if event + end + build_calendar_dates(event) respond_to do |format| format.html do @@ -149,7 +154,7 @@ class CalendarsController < ApplicationController end protected :calendar_events_for_request_format - def build_calendar_dates + def build_calendar_dates(event_to_focus) @today = Time.zone.today if params[:start_day] && params[:end_day] @@ -165,10 +170,16 @@ class CalendarsController < ApplicationController end @current = Date.new(y = @year, m = @month, d = 1) else - @month = params[:month].to_i - @month = !@month || @month == 0 ? @today.month : @month - @year = params[:year].to_i - @year = !@year || @year == 0 ? @today.year : @year + if event_to_focus + use_start = event_to_focus.start_at.in_time_zone + @month = use_start.month + @year = use_start.year + else + @month = params[:month].to_i + @month = !@month || @month == 0 ? @today.month : @month + @year = params[:year].to_i + @year = !@year || @year == 0 ? @today.year : @year + end @first_day = Date.parse(params[:start_day]) if params[:start_day] @last_day = Date.parse(params[:end_day]) if params[:end_day] diff --git a/app/views/calendars/_calendar.html.erb b/app/views/calendars/_calendar.html.erb index 33c2c381ea8..2b9fadf6bb6 100644 --- a/app/views/calendars/_calendar.html.erb +++ b/app/views/calendars/_calendar.html.erb @@ -1,4 +1,5 @@ <% + js_env :CALENDAR => { :ACTIVE_EVENT => @active_event_id } js_bundle :calendar jammit_css :calendar @body_classes << "full-width" diff --git a/public/javascripts/calendar.js b/public/javascripts/calendar.js index 3d533b64237..e2ea9d7d23a 100644 --- a/public/javascripts/calendar.js +++ b/public/javascripts/calendar.js @@ -18,6 +18,7 @@ define([ 'INST' /* INST */, + 'ENV', 'i18n!calendars', 'jquery' /* $ */, 'compiled/userSettings', @@ -38,9 +39,10 @@ define([ 'jqueryui/resizable' /* /\.resizable/ */, 'jqueryui/sortable' /* /\.sortable/ */, 'jqueryui/tabs' /* /\.tabs/ */ -], function(INST, I18n, $, userSettings, calendarMonths) { +], function(INST, ENV, I18n, $, userSettings, calendarMonths) { window.calendar = { + activateEventId: ENV.CALENDAR.ACTIVE_EVENT, viewItem: function(context_string, item_id, item_type) { }, showingUndatedEvents: false, @@ -624,6 +626,15 @@ define([ if($("#" + groupId).length > 0) { $event.showIf($("#" + groupId).attr('checked')); } + + // After loading the data, if have an event to activate and the event was just updated, show it. + if (event.id == calendar.activateEventId && calendar.activateEventId) { + $day = $event.parents(".calendar_day"); + // Remove the ID from being automatically activated on the next data refresh + calendar.activateEventId = null; + showEvent($event, $day); + } + return id; } function refreshCalendarData(cache) { diff --git a/spec/selenium/calendar_spec.rb b/spec/selenium/calendar_spec.rb index f7d09be4a1d..45992ff97dc 100644 --- a/spec/selenium/calendar_spec.rb +++ b/spec/selenium/calendar_spec.rb @@ -211,5 +211,18 @@ describe "calendar" do ff('.mini_calendar_day .day_number')[10].click keep_trying_until { f('.calendar_month .month_name').text.should == f('.mini-cal-month-and-year .month_name').text } end + + it "should open an event dialog on calendar from URL" do + event_title = 'Test Event 123' + start_time = 3.months.ago + end_time = start_time + 1.hour + calendar_event_model(:title => event_title, :start_at => start_time, :end_at => end_time) + + get "/calendar?event_id=#{@event.id}&include_contexts=course_#{@course.id}" + wait_for_ajax_requests + + keep_trying_until { fj(".ui-dialog").should be_displayed } #using fj to bypass selenium cache + fj(".ui-dialog .title").text.should == event_title + end end end