Class: Caboose::EventsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose/events_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_index, #admin_json, #admin_json_single, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in

Instance Method Details

#admin_addObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/caboose/events_controller.rb', line 40

def admin_add
  return unless user_is_allowed('calendars', 'edit')
  resp = StdClass.new      
  event = CalendarEvent.new
  event.calendar_id = params[:calendar_id]
  event.name = params[:name]
  event.begin_date = DateTime.parse("#{params[:begin_date]}T10:00:00-05:00") 
  event.end_date   = DateTime.parse("#{params[:begin_date]}T10:00:00-05:00")      
  event.all_day = false
  event.published = false
  event.url_label = "More Information"
  event.save
  resp.redirect = "/admin/calendars/#{event.calendar_id}/events/#{event.id}"
  render :json => resp
end

#admin_deleteObject



113
114
115
116
117
118
119
# File 'app/controllers/caboose/events_controller.rb', line 113

def admin_delete
  return unless user_is_allowed('calendars', 'delete')
  cal_id = CalendarEvent.find(params[:id]).calendar_id
  CalendarEvent.find(params[:id]).destroy      
  resp = StdClass.new({ 'redirect' => "/admin/calendars/#{cal_id}" })                  
  render :json => resp
end

#admin_editObject



8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/caboose/events_controller.rb', line 8

def admin_edit
  return unless user_is_allowed('calendars', 'edit')
  @event = CalendarEvent.find(params[:id])
  @event.verify_custom_field_values_exist
  if @event.calendar_event_group_id.nil?
    g = CalendarEventGroup.create
    @event.calendar_event_group_id = g.id
    @event.save
  end
  render :layout => 'caboose/admin'
end

#admin_updateObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/caboose/events_controller.rb', line 57

def admin_update
  return unless user_is_allowed('calendars', 'edit')
  
  resp = StdClass.new({ 'attributes' => {} })
  event = CalendarEvent.find(params[:id])
  
  save = true      
  params.each do |name, value|
    case name
      when 'name'         then event.name         = value
      when 'location'     then event.location     = value
      when 'description'  then event.description  = value
      when 'url'          then event.url  = value
      when 'url_label'          then event.url_label  = value
      when 'published'    then event.published  = value
      when 'all_day'      then event.all_day      = value
      when 'begin_date'              
        t = event.begin_date ? event.begin_date.strftime('%H:%M %z') : '10:00 -0500'
        event.begin_date = DateTime.strptime("#{value} #{t}", '%m/%d/%Y %H:%M %z')                        
      when 'begin_time'
        d = event.begin_date ? event.begin_date.strftime('%Y-%m-%d') : DateTime.now.strftime('%Y-%m-%d')
        event.begin_date = DateTime.strptime("#{d} #{value}", '%Y-%m-%d %I:%M %P')
      when 'end_date'
        t = event.end_date ? event.end_date.strftime('%H:%M %z') : '10:00 -0500'
        event.end_date = DateTime.strptime("#{value} #{t}", '%m/%d/%Y %H:%M %z')
      when 'end_time'
        d = event.end_date ? event.end_date.strftime('%Y-%m-%d') : DateTime.now.strftime('%Y-%m-%d')
        event.end_date = DateTime.strptime("#{d} #{value}", '%Y-%m-%d %I:%M %P')
      when 'repeats'
        g = event.calendar_event_group
        if value == true || value.to_i == 1
          g.date_start = event.begin_date.to_date if g.date_start.nil?
          g.date_end   = event.end_date.to_date   if g.date_end.nil?
          g.save              
        end
        event.repeats = value
    end
  end

  resp.success = save && event.save
  render :json => resp
end

#admin_update_imageObject



102
103
104
105
106
107
108
109
110
# File 'app/controllers/caboose/events_controller.rb', line 102

def admin_update_image
  return if !user_is_allowed('calendars', 'edit')     
  resp = Caboose::StdClass.new
  event = CalendarEvent.find(params[:event_id])
  event.image = params[:image]            
  resp.success = event.save
  resp.attributes = { 'image' => { 'value' => event.image.url(:thumb) }}
  render :text => resp.to_json
end

#showObject



21
22
23
24
25
26
27
28
# File 'app/controllers/caboose/events_controller.rb', line 21

def show
  return if under_construction_or_forwarding_domain?
  @event = CalendarEvent.where(:id => params[:id], :published => true).first
  render :file => "caboose/extras/error404" and return if @event.nil?                 
  @event = Caboose.plugin_hook('event_content', @event)
  @page.title = @event.name
  #    @editmode = !params['edit'].nil? && user.is_allowed('calendars', 'edit') ? true : false  
end