Class: Admin::Muck::AccessCodeRequestsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/muck/access_code_requests_controller.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/admin/muck/access_code_requests_controller.rb', line 59

def destroy
  @access_code_request = AccessCodeRequest.find(params[:id])
  @success = @access_code_request.destroy
  respond_to do |format|
    format.html { redirect_to admin_access_code_requests_path }
    format.js do
      if @success
        render :template => 'admin/access_code_requests/destroy', :layout => false
      else
        output_admin_messages
      end
    end
  end
end

#editObject



27
28
29
30
# File 'app/controllers/admin/muck/access_code_requests_controller.rb', line 27

def edit
  @access_code_request = AccessCodeRequest.find(params[:id])
  render :template => "admin/access_code_requests/edit", :layout => false
end

#indexObject



3
4
5
6
7
8
9
10
11
12
# File 'app/controllers/admin/muck/access_code_requests_controller.rb', line 3

def index
  if params[:fullfilled]
    @title = translate('muck.users.fullfilled_access_code_requests')
    @access_code_requests = AccessCodeRequest.fullfilled.by_newest.paginate(:page => @page, :per_page => @per_page)
  else
    @title = translate('muck.users.unfullfilled_access_code_requests')
    @access_code_requests = AccessCodeRequest.unfullfilled.by_newest.paginate(:page => @page, :per_page => @per_page)
  end
  render :template => 'admin/access_code_requests/index'
end

#searchObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/admin/muck/access_code_requests_controller.rb', line 14

def search
  @is_search = true
  query = "%#{params[:query]}%"
  if params[:fullfilled]
    @access_code_requests = AccessCodeRequest.where("name LIKE ? OR email LIKE ?", query, query).fullfilled.by_newest.paginate(:page => @page, :per_page => @per_page)
  else
    @access_code_requests = AccessCodeRequest.where("name LIKE ? OR email LIKE ?", query, query).unfullfilled.by_newest.paginate(:page => @page, :per_page => @per_page)
  end
  respond_to do |format|
    format.html { render :template => 'admin/access_code_requests/index' }
  end
end

#send_codeObject



32
33
34
35
36
37
38
# File 'app/controllers/admin/muck/access_code_requests_controller.rb', line 32

def send_code
  @subject ||= params[:subject]
  @message ||= params[:message]
  @expires_at = 1.year.from_now
  @access_code_request = AccessCodeRequest.find(params[:id])
  render :template => "admin/access_code_requests/send_code", :layout => false
end

#updateObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/admin/muck/access_code_requests_controller.rb', line 40

def update
  @access_code_request = AccessCodeRequest.find(params[:id])
  if params[:send_access_code]
    @success = @access_code_request.send_access_code(params[:subject], params[:message], params[:expires_at])
  else
    @success = @access_code_request.update_attributes(params[:access_code_request])
  end
  
  if @success
    ajax_update_access_code_request
  else
    output_admin_messages(@access_code_request)
  end
  
rescue => ex
  flash[:error] = ex.to_s
  output_admin_messages
end