2014-12-16 11:40:15 +00:00
|
|
|
class Admin::CalendarsController < OrbitAdminController
|
|
|
|
# GET /events
|
|
|
|
# GET /events.json
|
|
|
|
|
|
|
|
def index
|
2014-12-17 09:08:50 +00:00
|
|
|
@events = []
|
2020-08-04 02:37:49 +00:00
|
|
|
tags = @module_app.tags
|
|
|
|
categories = @module_app.categories
|
|
|
|
@filter_fields = {
|
|
|
|
:category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}},
|
|
|
|
:tags=>tags.map{|tag| {:title=>(tag.name.blank? ? " " : tag.name), :id=>tag.id}}
|
|
|
|
}
|
2014-12-16 11:40:15 +00:00
|
|
|
if params[:start].present? && params[:end].present?
|
|
|
|
sdt = Time.at(params[:start].to_i)
|
|
|
|
edt = Time.at(params[:end].to_i)
|
2020-08-04 02:37:49 +00:00
|
|
|
@monthly_events = Event.monthly_event(sdt,edt).with_categories(filters("category"))
|
2020-08-12 13:33:46 +00:00
|
|
|
.with_tags(filters("tag")).convert_front
|
2020-08-04 02:37:49 +00:00
|
|
|
@re = Event.with_categories(filters("category")).with_tags(filters("tag")).recurring_event(sdt,edt)
|
2014-12-17 09:08:50 +00:00
|
|
|
allevents = @monthly_events.inject(@re, :<<)
|
|
|
|
events = allevents.to_json
|
|
|
|
events = JSON.parse(events)
|
|
|
|
events.each_with_index do |e,i|
|
|
|
|
e["can_edit"] = can_edit_or_delete_event?(allevents[i])
|
|
|
|
@events << e
|
|
|
|
end
|
2014-12-16 11:40:15 +00:00
|
|
|
end
|
2020-08-04 02:37:49 +00:00
|
|
|
if request.xhr?
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :partial => "index" }
|
|
|
|
format.json { render json: @events.to_json }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render "index" }
|
|
|
|
format.json { render json: @events.to_json }
|
|
|
|
end
|
2014-12-16 11:40:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /events/1
|
|
|
|
# GET /events/1.json
|
|
|
|
def show
|
|
|
|
@event = Event.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # show.html.erb
|
|
|
|
format.json { render json: @event }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def agenda
|
2014-12-17 10:25:53 +00:00
|
|
|
agenda_start = Time.at(params[:unix_start].to_i).to_s
|
|
|
|
agenda_end = Time.at(params[:unix_end].to_i).to_s
|
2014-12-16 11:40:15 +00:00
|
|
|
@events = Event.agenda_events(agenda_start,agenda_end)
|
|
|
|
# re = Event.recurring_event(Time.at(params[:unix_start].to_i), Time.at(params[:unix_end].to_i))
|
|
|
|
# @events = @events.inject(re, :<<)
|
|
|
|
render :json=>@events.to_json
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /events/new
|
|
|
|
# GET /events/new.json
|
|
|
|
def new
|
|
|
|
@event = Event.new
|
|
|
|
categories = user_authenticated_categories rescue []
|
|
|
|
if categories.first == "all"
|
|
|
|
@categories = CalendarType.all
|
|
|
|
else
|
|
|
|
@categories = CalendarType.where(:category_id.in => categories) rescue []
|
|
|
|
end
|
|
|
|
@end_d_t = params[:endDate]
|
|
|
|
@start_d_t = params[:startDate]
|
|
|
|
@all_day = false;
|
|
|
|
@recurring = false;
|
|
|
|
if params
|
|
|
|
case params[:allDay]
|
|
|
|
when "true"
|
|
|
|
@all_day = true
|
|
|
|
when "false"
|
|
|
|
@all_day = false
|
|
|
|
case params[:recurring]
|
|
|
|
when "true"
|
|
|
|
@recurring = true
|
|
|
|
when "false"
|
|
|
|
@recurring = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
render :layout => false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /events/1/edit
|
|
|
|
def edit
|
|
|
|
@event = Event.find(params[:id])
|
|
|
|
categories = user_authenticated_categories rescue []
|
|
|
|
if categories.first == "all"
|
|
|
|
@categories = CalendarType.all
|
|
|
|
else
|
|
|
|
@categories = CalendarType.where(:category_id.in => categories) rescue []
|
|
|
|
end
|
|
|
|
@end_d_t = @event.end.strftime("%Y/%m/%d %H:%M").to_s
|
|
|
|
@start_d_t = @event.start.strftime("%Y/%m/%d %H:%M").to_s
|
|
|
|
@all_day = @event.all_day
|
|
|
|
@recurring = @event.recurring
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /events
|
|
|
|
# POST /events.json
|
|
|
|
def create
|
2014-12-17 09:08:50 +00:00
|
|
|
p = event_page_params
|
|
|
|
p["create_user_id"] = current_user.id
|
|
|
|
p["update_user_id"] = current_user.id
|
|
|
|
@event = Event.new(p)
|
2014-12-27 11:52:47 +00:00
|
|
|
|
2014-12-16 11:40:15 +00:00
|
|
|
if @event.present? && @event.save
|
2014-12-27 11:52:47 +00:00
|
|
|
e = @event.to_json
|
|
|
|
e = JSON.parse(e)
|
|
|
|
e["can_edit"] = true
|
|
|
|
render json: e.to_json
|
2014-12-16 11:40:15 +00:00
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render action: "new" }
|
|
|
|
format.json { render json: @event.errors, status: :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /events/1
|
|
|
|
# PUT /events/1.json
|
|
|
|
def update
|
|
|
|
@event = Event.find(params[:id])
|
2014-12-17 09:08:50 +00:00
|
|
|
p = event_page_params
|
|
|
|
p["update_user_id"] = current_user.id
|
2020-05-28 11:12:31 +00:00
|
|
|
bulletin = @event.bulletin
|
|
|
|
if !bulletin.nil?
|
|
|
|
bulletin.update_attributes(calendar_start_date: p[:start],calendar_end_date: p[:end],calendar_all_day: p[:all_day],calendar_type_id: p[:calendar_type_id])
|
|
|
|
end
|
2020-08-08 12:33:26 +00:00
|
|
|
if @event.update_attributes!(p)
|
2014-12-27 11:52:47 +00:00
|
|
|
e = @event.to_json
|
|
|
|
e = JSON.parse(e)
|
|
|
|
e["can_edit"] = true
|
|
|
|
render json: e.to_json
|
2014-12-16 11:40:15 +00:00
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render action: "edit" }
|
|
|
|
format.json { render json: @event.errors, status: :unprocessable_entity }
|
|
|
|
#format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /events/1
|
|
|
|
# DELETE /events/1.json
|
|
|
|
def destroy
|
|
|
|
@event = Event.find(params[:id])
|
2020-05-28 11:12:31 +00:00
|
|
|
bulletin = @event.bulletin
|
|
|
|
if !bulletin.nil?
|
|
|
|
bulletin.update_attributes(event_id: nil,add_to_calendar: '0')
|
|
|
|
end
|
2014-12-16 11:40:15 +00:00
|
|
|
@event.destroy
|
|
|
|
render :json => {"success"=>true}.to_json
|
|
|
|
# respond_to do |format|
|
|
|
|
# format.html { redirect_to events }
|
|
|
|
# format.json { head :no_content }
|
|
|
|
# end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def event_page_params
|
|
|
|
params.require(:event).permit!
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_or_delete_event?(obj)
|
|
|
|
create_user = obj.create_user_id.to_s rescue nil
|
|
|
|
if @user_authenticated_categories.first == "all"
|
|
|
|
return true
|
|
|
|
elsif @current_user_is_sub_manager && !create_user.nil?
|
|
|
|
create_user == current_user.id.to_s
|
|
|
|
else
|
|
|
|
@user_authenticated_categories.include?obj.calendar_type.category_id rescue (current_user.is_manager?(@module_app) rescue false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|