calendar/app/controllers/calendars_controller.rb

82 lines
1.7 KiB
Ruby
Raw Normal View History

2014-12-16 11:40:15 +00:00
class CalendarsController < ApplicationController
# GET /events
# GET /events.json
def index
{
"extras" => {
"page_id" => OrbitHelper.params[:page_id]
}
}
end
def show
params = OrbitHelper.params
event = Event.find(params[:uid])
{
"page_id" => params[:page_id],
"event_date" => event.start.strftime("%Y-%m-%d")
}
end
2015-06-01 08:03:45 +00:00
def widget
part = OrbitHelper.get_current_widget
2015-06-03 09:38:31 +00:00
2015-06-01 08:03:45 +00:00
{
2015-06-03 09:38:31 +00:00
"extras" => {
"subpart-id" => part.id.to_s,
"more_url" => OrbitHelper.widget_more_url
}
2015-06-01 08:03:45 +00:00
}
end
2014-12-16 11:40:15 +00:00
def events
page = Page.find_by(:page_id => params[:page_id]) rescue nil
events =[]
if !page.nil?
if params[:start].present? && params[:end].present?
sdt = Time.at(params[:start].to_i)
edt = Time.at(params[:end].to_i)
events = Event.monthly_event(sdt,edt)
2014-12-16 11:40:15 +00:00
end
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: events.to_json }
end
end
def agenda
if !params[:subpart_id].nil?
subpartid = params[:subpart_id]
widget = SubPart.find(subpartid)
calendar_types = widget.custom_array_field
else
calendar_types = []
end
if params[:unix_start].present? && params[:unix_end].present?
agenda_start = Time.at(params[:unix_start].to_i).to_s
agenda_end = Time.at(params[:unix_end].to_i).to_s
if !calendar_types.blank?
events = Event.where(:calendar_type_id.in => calendar_types).agenda_events(agenda_start,agenda_end)
2014-12-16 11:40:15 +00:00
else
events = Event.agenda_events(agenda_start,agenda_end)
2014-12-16 11:40:15 +00:00
end
end
render json: {"events" => events}.to_json({"frontend" => true})
2014-12-16 11:40:15 +00:00
end
end