Class: Caboose::CalendarsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

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

Instance Method Details

#admin_addObject

POST /admin/calendars



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/caboose/calendars_controller.rb', line 51

def admin_add
  return unless user_is_allowed('calendars', 'edit')
  
  resp = StdClass.new      
  calendar = Calendar.new
  calendar.name = params[:name]
  calendar.site_id = @site.id
  
  if calendar.name.nil? || calendar.name.strip.length == 0
    resp.error = "Please enter a calendar name."
  else
    calendar.save
    resp.redirect = "/admin/calendars/#{calendar.id}"
  end
  render :json => resp
end

#admin_deleteObject

DELETE /admin/calendars/:id



69
70
71
72
73
74
# File 'app/controllers/caboose/calendars_controller.rb', line 69

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

#admin_editObject

GET /admin/calendars/:id



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

def admin_edit
  return unless user_is_allowed('calendars', 'edit')
  @calendar = Calendar.find(params[:id])
  
  @d = params[:d] ? DateTime.iso8601(params[:d]) : DateTime.now
  @d = @d - (@d.strftime('%-d').to_i-1)      
  
  render :layout => 'caboose/admin'
end

#admin_indexObject

GET /admin/calendars



12
13
14
15
16
17
18
# File 'app/controllers/caboose/calendars_controller.rb', line 12

def admin_index
  return if !user_is_allowed('calendars', 'view')
  render :file => 'caboose/extras/error_invalid_site' and return if @site.nil?
              
  @calendars = Calendar.where(:site_id => @site.id).reorder(:name).all
  render :layout => 'caboose/admin'      
end

#admin_updateObject

PUT /admin/calendars/:id



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/caboose/calendars_controller.rb', line 32

def admin_update
  return unless user_is_allowed('calendars', 'edit')
  
  resp = StdClass.new({'attributes' => {}})
  calendar = Calendar.find(params[:id])
  
  save = true      
  params.each do |name, value|
    case name
      when 'name'         then calendar.name         = value
      when 'description'  then calendar.description  = value          
    end
  end

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

#before_actionObject



7
8
9
# File 'app/controllers/caboose/calendars_controller.rb', line 7

def before_action
  @page = Page.page_with_uri(request.host_with_port, '/admin')
end