2014-12-16 11:40:15 +00:00
|
|
|
class CalendarsController < ApplicationController
|
|
|
|
# GET /events
|
|
|
|
# GET /events.json
|
2020-08-15 13:42:57 +00:00
|
|
|
include ActionView::Helpers::AssetTagHelper
|
2014-12-16 11:40:15 +00:00
|
|
|
|
|
|
|
def index
|
2020-08-15 13:42:57 +00:00
|
|
|
page = Page.where(page_id: OrbitHelper.params[:page_id]).first
|
2020-08-15 13:51:32 +00:00
|
|
|
style_file = page.layout=='index3' ? '/assets/calendar_widget2' : '/assets/calendar_widget1'
|
2014-12-16 11:40:15 +00:00
|
|
|
{
|
|
|
|
"extras" => {
|
2020-08-15 13:42:57 +00:00
|
|
|
"page_id" => OrbitHelper.params[:page_id],
|
|
|
|
'widget_title' => page.name,
|
|
|
|
'calendar_title' => get_calendar_title,
|
|
|
|
'style_tag' => stylesheet_link_tag(style_file)
|
2014-12-16 11:40:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-09-21 12:04:53 +00:00
|
|
|
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
|
|
|
"extras" => {
|
|
|
|
"subpart-id" => part.id.to_s,
|
2020-08-12 13:33:46 +00:00
|
|
|
"more_url" => OrbitHelper.widget_more_url,
|
|
|
|
'widget_title' => part.title,
|
|
|
|
'calendar_title' => get_calendar_title
|
2015-06-03 09:38:31 +00:00
|
|
|
}
|
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)
|
2020-08-12 13:33:46 +00:00
|
|
|
events = Event.monthly_event(sdt,edt).convert_front+Event.recurring_event(sdt,edt)
|
2014-12-16 11:40:15 +00:00
|
|
|
end
|
2020-08-08 12:33:26 +00:00
|
|
|
end
|
2014-12-16 11:40:15 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.html.erb
|
|
|
|
format.json { render json: events.to_json }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-15 13:42:57 +00:00
|
|
|
|
|
|
|
def index_agenda
|
|
|
|
I18n.with_locale(params[:locale]||I18n.locale) do
|
|
|
|
if !params[:subpart_id].nil?
|
|
|
|
subpartid = params[:subpart_id]
|
|
|
|
page = Page.where(page_id: subpartid).first
|
|
|
|
calendar_types = page.categories
|
|
|
|
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)
|
|
|
|
else
|
|
|
|
events = Event.agenda_events(agenda_start,agenda_end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i))}.to_json({"frontend" => true})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def agenda
|
2020-08-12 13:33:46 +00:00
|
|
|
I18n.with_locale(params[:locale]||I18n.locale) do
|
|
|
|
if !params[:subpart_id].nil?
|
|
|
|
subpartid = params[:subpart_id]
|
|
|
|
widget = SubPart.find(subpartid)
|
|
|
|
calendar_types = widget.custom_array_field
|
2014-12-16 11:40:15 +00:00
|
|
|
else
|
2020-08-12 13:33:46 +00:00
|
|
|
calendar_types = []
|
2014-12-16 11:40:15 +00:00
|
|
|
end
|
2020-08-12 13:33:46 +00:00
|
|
|
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)
|
|
|
|
else
|
|
|
|
events = Event.agenda_events(agenda_start,agenda_end)
|
|
|
|
end
|
|
|
|
end
|
2020-08-13 08:51:04 +00:00
|
|
|
render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i))}.to_json({"frontend" => true})
|
2015-06-02 09:22:51 +00:00
|
|
|
end
|
2020-08-12 13:33:46 +00:00
|
|
|
end
|
|
|
|
def get_calendar_title(now_date=nil)
|
|
|
|
now_date = Time.now if now_date.nil?
|
|
|
|
month_name = I18n.locale.to_s=='zh_tw' ? now_date.month : I18n.t("calendar.month_name.#{now_date.month}")
|
|
|
|
I18n.t("calendar.calendar_title",year: now_date.year,month: month_name)
|
2014-12-16 11:40:15 +00:00
|
|
|
end
|
2015-06-02 09:22:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|