Class: EventsController

Inherits:
EventCalendar::ApplicationController show all
Includes:
EventsHelper
Defined in:
app/controllers/events_controller.rb

Instance Method Summary collapse

Methods included from EventsHelper

#event_abbrev_date, #event_details_link, #event_one_liner, #event_type_css_class, #event_type_label, #event_type_legend

Instance Method Details

#createObject

POST /events POST /events.xml



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/controllers/events_controller.rb', line 122

def create
  @event = Event.new(params[:event])
  @event.adjust_to_utc = true
  respond_to do |format|
    if @event.save
      flash[:notice] = 'Event was successfully created.'
      format.html { redirect_to(event_path(@event)) }
      format.xml  { render :xml => @event, :status => :created, :location => @event }
    else
      flash.now[:notice] = @event.errors.full_messages
      format.html { render :action => "new" }
      format.xml  { render :xml => @event.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /events/1 DELETE /events/1.xml



158
159
160
161
162
163
164
165
166
# File 'app/controllers/events_controller.rb', line 158

def destroy
  @event = Event.find(params[:id])
  @event.destroy
  
  respond_to do |format|
    format.html { redirect_to(events_path) }
    format.xml  { head :ok }
  end
end

#editObject

GET /events/1/edit



115
116
117
118
# File 'app/controllers/events_controller.rb', line 115

def edit
  @event = Event.find(params[:id])
  Time.zone = @event.timezone
end

#indexObject

GET /events GET /events.xml



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/events_controller.rb', line 60

def index
  @event_types = Event.event_types
  if params[:start] && params[:end]
    @events = Event.between(Time.at(params[:start].to_i), Time.at(params[:end].to_i))
    unless params[:event_type].blank?
      @events = @events.where(:event_type => params[:event_type])
    end
  else
    @past_events = Event.past.order("start_on ASC")
    @current_events = Event.current.order("start_on ASC")
    unless params[:event_type].blank?
      @past_events = @past_events.where(:event_type => params[:event_type])
      @current_events = @current_events.where(:event_type => params[:event_type])
    end
  end

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @events }
    format.js { render :json => events_to_json }
  end
end

#newObject

GET /events/new GET /events/new.xml



105
106
107
108
109
110
111
112
# File 'app/controllers/events_controller.rb', line 105

def new
  @event = Event.new
  @event.start_time = Time.local(Date.current.year, Date.current.month, Date.current.day, 06, 00)
  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @event }
  end
end

#searchObject



83
84
85
86
87
88
# File 'app/controllers/events_controller.rb', line 83

def search
  @events = Event.search(params[:q], {
    # :narrow_fields => params[:fields] ? params[:fields].keys : nil
  }).paginate :page => params[:page]
  @link = Link.new
end

#showObject

GET /events/1 GET /events/1.xml



92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/events_controller.rb', line 92

def show
  # @event = Event.find(params[:id], :include => :file_attachments)
  @event = Event.find(params[:id])
  @link = @event.links.build
  
  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @event }
  end
end

#updateObject

PUT /events/1 PUT /events/1.xml



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'app/controllers/events_controller.rb', line 140

def update
  @event = Event.find(params[:id])
  @event.adjust_to_utc = true
  respond_to do |format|
    if @event.update_attributes(params[:event])
      flash[:notice] = 'Event was successfully updated.'
      format.html { redirect_to(@event) }
      format.xml  { head :ok }
    else
      flash.now[:notice] = @event.errors.full_messages
      format.html { render :action => "edit" }
      format.xml  { render :xml => @event.errors, :status => :unprocessable_entity }
    end
  end
end