YaleSTC/shifts

View on GitHub
app/views/repeating_events/update.js.rjs

Summary

Maintainability
Test Coverage
rerender_start_date = Date.parse(params[:rerender_date]).previous_sunday
page.remove "#tooltip"

if @repeating_event.is_set_of_timeslots? and !params[:calendar]
  #TODO: clean this up. for now, this is just copied to make the partial work.
  @period_start = params[:date] ? Date.parse(params[:date]).previous_sunday : Date.today.previous_sunday
  @dept_start_hour = current_department.department_config.schedule_start / 60
  @dept_end_hour = current_department.department_config.schedule_end / 60
  @hours_per_day = (@dept_end_hour - @dept_start_hour)
  @block_length = current_department.department_config.time_increment
  @blocks_per_hour = 60/@block_length.to_f
  @blocks_per_day = @hours_per_day * @blocks_per_hour
  @hidden_timeslots = []
  
  @repeating_event.locations.each do |location|
    page.replace_html "location#{location.id}", partial: "time_slots/location", object: location
    page << "initialize('#location#{location.id}');" 
  end
else
  #rerender all days until the end of the week
  rerender_start_date.wday.upto(6) do |n|
    if @repeating_event.days.include?(n.day_of_week)
      current_date = rerender_start_date + n.days
      page.replace_html current_date.strftime("%Y-%m-%d"), partial: (params[:calendar] ? "calendars/schedule/day" : "shifts/schedule/day"), object: current_date.to_date
      page << "initialize('##{current_date.strftime("%Y-%m-%d")}');" 
    end
  end
end

# display alert
ajax_alert(page, "event(s) updated");