app/controllers/calagator/events_controller.rb in calagator-1.0.0.rc2 vs app/controllers/calagator/events_controller.rb in calagator-1.0.0.rc3

- old
+ new

@@ -10,20 +10,13 @@ before_filter :find_and_redirect_if_locked, :only => [:edit, :update, :destroy] # GET /events # GET /events.xml def index - @start_date = date_or_default_for(:start) - @end_date = date_or_default_for(:end) - - query = Event.non_duplicates.ordered_by_ui_field(params[:order]).includes(:venue, :tags) - @events = params[:date] ? - query.within_dates(@start_date, @end_date) : - query.future - - @perform_caching = params[:order].blank? && params[:date].blank? - + @browse = Event::Browse.new(params) + @events = @browse.events + @browse.errors.each { |error| append_flash :failure, error } render_events @events end # GET /events/1 # GET /events/1.xml @@ -96,16 +89,16 @@ # GET /events/search def search @search = Event::Search.new(params) - flash[:failure] = @search.failure_message - return redirect_to root_path if @search.hard_failure? - # setting @events so that we can reuse the index atom builder @events = @search.events + flash[:failure] = @search.failure_message + return redirect_to root_path if @search.hard_failure? + render_events(@events) end def clone @event = Event::Cloner.clone(Event.find(params[:id])) @@ -117,11 +110,11 @@ def render_event(event) respond_to do |format| format.html # show.html.erb format.xml { render :xml => event.to_xml(root: "events", :include => :venue) } - format.json { render :json => event.to_json(:include => :venue), :callback => params[:callback] } + format.json { render :json => event.to_json(:include => :venue) } format.ics { render :ics => [event] } end end # Render +events+ for a particular format. @@ -130,34 +123,11 @@ format.html # *.html.erb format.kml # *.kml.erb format.ics { render :ics => events || Event.future.non_duplicates } format.atom { render :template => 'calagator/events/index' } format.xml { render :xml => events.to_xml(root: "events", :include => :venue) } - format.json { render :json => events.to_json(:include => :venue), :callback => params[:callback] } + format.json { render :json => events.to_json(:include => :venue) } end - end - - # Return the default start date. - def default_start_date - Time.zone.today - end - - # Return the default end date. - def default_end_date - Time.zone.today + 3.months - end - - # Return a date parsed from user arguments or a default date. The +kind+ - # is a value like :start, which refers to the `params[:date][+kind+]` value. - # If there's an error, set an error message to flash. - def date_or_default_for(kind) - default = send("default_#{kind}_date") - return default unless params[:date].present? - - Date.parse(params[:date][kind]) - rescue NoMethodError, ArgumentError, TypeError - append_flash :failure, "Can't filter by an invalid #{kind} date." - default end def find_and_redirect_if_locked @event = Event.find(params[:id]) if @event.locked?