YaleSTC/shifts

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

Summary

Maintainability
Test Coverage
rerender_start_date = Date.parse( params[:delete_after_date].nil? ? params[:rerender_date] : params[:delete_after_date] ).previous_sunday

page.remove "#tooltip"

#rerender all days until the end of the week
if @locations
  #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 = []
  
  @locations.each do |location|
    page.replace_html "location#{location.id}", partial: "time_slots/location", object: location
    page << "initialize('#location#{location.id}');" 
  end
else
  rerender_start_date.wday.upto(7) do |n|
    if @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) destroyed");