Class: Spud::Admin::UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/spud/admin/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/spud/admin/users_controller.rb', line 37

def create
  status = 500
  @user = SpudUser.new(params[:spud_user],:as => :admin)

  if @user.save
    status = 200
    flash[:notice] = "User created successfully"
  else
    flash[:error] = "There was an error while saving the user."
  end

  respond_with @user,:location => spud_admin_users_url do |format|
    format.js { render :status => status, :json => @user.to_json }
    format.html {
      if status == 200
        redirect_to spud_admin_users_url()
      else
        render :action => "new"
      end
    }
  end
end

#destroyObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/spud/admin/users_controller.rb', line 83

def destroy
  status = 500
  if @user.destroy
    status = 200
    flash[:notice] = "User removed."
  else
    flash[:error] = "There was an error removing the user"
  end

  respond_to do |format|
    format.js { render :text => nil,:status => status }
    format.html {redirect_to spud_admin_users_url()}
  end
end

#editObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/spud/admin/users_controller.rb', line 60

def edit
  Spud::Core.admin_applications.each do |application|
    permission = @user.spud_admin_permissions.select {|perm| perm.name == application[:name]}
    if permission.blank?
      @user.spud_admin_permissions.new(:name => application[:name],:access => @user.super_admin)
    end
  end
  respond_to do |format|
    format.js { render :partial => "edit"}
    format.html { render }
  end
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/spud/admin/users_controller.rb', line 9

def index
  sort_order = "login asc"
  if sort_column
    if sort_column == 'first_name'
      sort_order = "first_name #{sort_direction}, last_name #{sort_direction}"
    else
      sort_order = "#{sort_column} #{sort_direction}"
    end
  end
  @users = SpudUser.order(sort_order).paginate :page => params[:page]
  respond_with @users
end

#newObject



27
28
29
30
31
32
33
34
35
# File 'app/controllers/spud/admin/users_controller.rb', line 27

def new
  @user = SpudUser.new
  Spud::Core.admin_applications.each do |application|
    @user.spud_admin_permissions.new(:name => application[:name],:access => false)
  end
  respond_with @user do |format|
    format.js { render :partial => "new"}
  end
end

#showObject



22
23
24
25
# File 'app/controllers/spud/admin/users_controller.rb', line 22

def show
   add_breadcrumb @user.full_name, :spud_admin_user_path
  respond_with @user
end

#updateObject



73
74
75
76
77
78
79
80
81
# File 'app/controllers/spud/admin/users_controller.rb', line 73

def update
  if @user.update_attributes(params[:spud_user], :as => :admin)
    flash[:notice] = "User saved successfully."
    redirect_to spud_admin_users_url()
  else
    flash[:error] = "There was an error while saving the user."
    render :action => "edit"
  end
end