Class: Caboose::EventGroupsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_edit, #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_deleteObject



40
41
42
43
44
45
46
47
# File 'app/controllers/caboose/event_groups_controller.rb', line 40

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

#admin_frequency_optionsObject



60
61
62
63
# File 'app/controllers/caboose/event_groups_controller.rb', line 60

def admin_frequency_options
  arr = (1..30).collect{ |i| { 'value' => i, 'text' => i }}
  render :json => arr        
end

#admin_optionsObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/caboose/event_groups_controller.rb', line 74

def admin_options
  options = []
  case params[:field]
    when 'period'
      options = [
        { 'value' => CalendarEventGroup::PERIOD_DAY   , 'text' => CalendarEventGroup::PERIOD_DAY   },
        { 'value' => CalendarEventGroup::PERIOD_WEEK  , 'text' => CalendarEventGroup::PERIOD_WEEK  },
        { 'value' => CalendarEventGroup::PERIOD_MONTH , 'text' => CalendarEventGroup::PERIOD_MONTH },
        { 'value' => CalendarEventGroup::PERIOD_YEAR  , 'text' => CalendarEventGroup::PERIOD_YEAR  },
      ]
    when 'frequency'
      options = (1..30).collect{ |i| { 'value' => i, 'text' => i }}
    when 'repeat-by'
      options = [
        { 'value' => CalendarEventGroup::REPEAT_BY_DAY_OF_MONTH , 'text' => 'same day of the month' },
        { 'value' => CalendarEventGroup::REPEAT_BY_DAY_OF_WEEK  , 'text' => 'same day of the week' },        
      ]
  end      
  render :json => options
end

#admin_period_optionsObject



50
51
52
53
54
55
56
57
# File 'app/controllers/caboose/event_groups_controller.rb', line 50

def admin_period_options
  render :json => [
    { 'value' => CalendarEventGroup::PERIOD_DAY   , 'text' => CalendarEventGroup::PERIOD_DAY   },
    { 'value' => CalendarEventGroup::PERIOD_WEEK  , 'text' => CalendarEventGroup::PERIOD_WEEK  },
    { 'value' => CalendarEventGroup::PERIOD_MONTH , 'text' => CalendarEventGroup::PERIOD_MONTH },
    { 'value' => CalendarEventGroup::PERIOD_YEAR  , 'text' => CalendarEventGroup::PERIOD_YEAR  },
  ]
end

#admin_repeat_by_optionsObject



66
67
68
69
70
71
# File 'app/controllers/caboose/event_groups_controller.rb', line 66

def admin_repeat_by_options
  render :json => [        
    { 'value' => CalendarEventGroup::REPEAT_BY_DAY_OF_MONTH , 'text' => 'same day of the month' },
    { 'value' => CalendarEventGroup::REPEAT_BY_DAY_OF_WEEK  , 'text' => 'same day of the week' },        
  ]
end

#admin_updateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/caboose/event_groups_controller.rb', line 8

def admin_update
  return unless user_is_allowed('calendars', 'edit')
  
  resp = StdClass.new
  g = CalendarEventGroup.find(params[:id])
  
  save = true      
  params.each do |name, value|
    case name
      when 'frequency'    then g.frequency    = value
      when 'period'       then g.period       = value        
      when 'repeat_by'    then g.repeat_by    = value
      when 'sun'          then g.sun          = value
      when 'mon'          then g.mon          = value
      when 'tue'          then g.tue          = value
      when 'wed'          then g.wed          = value
      when 'thu'          then g.thu          = value
      when 'fri'          then g.fri          = value
      when 'sat'          then g.sat          = value
      when 'date_start'   then g.date_start   = DateTime.strptime(value, '%m/%d/%Y').to_date
      when 'repeat_count' then g.repeat_count = value
      when 'date_end'     then g.date_end     = DateTime.strptime(value, '%m/%d/%Y').to_date                                      
    end
  end
  g.save
  g.create_events

  resp.success = true
  render :json => resp
end