Class: UsersController

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

Overview

Copyright © 2008-2013 Michael Dvorkin and contributors.

Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php


Instance Method Summary collapse

Instance Method Details

#auto_completeObject



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/controllers/users_controller.rb', line 112

def auto_complete
  @query = params[:term] || ''
  @users = User.my(current_user).text_search(@query).limit(10).order(:first_name, :last_name)

  respond_to do |format|
    format.json do
      results = @users.map do |a|
        helpers.j(a.full_name + " (@" + a.username + ")")
      end
      render json: results
    end
  end
end

#avatarObject

GET /users/1/avatar GET /users/1/avatar.js




43
44
45
# File 'app/controllers/users_controller.rb', line 43

def avatar
  respond_with(@user)
end

#change_passwordObject

PUT /users/1/change_password PUT /users/1/change_password.js




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

def change_password
  if @user.valid_password?(params[:current_password])
    if params[:user][:password].blank?
      flash[:notice] = t(:msg_password_not_changed)
    else
      @user.password = params[:user][:password]
      @user.password_confirmation = params[:user][:password_confirmation]
      @user.save
      flash[:notice] = t(:msg_password_changed)
    end
  else
    @user.errors.add(:current_password, t(:msg_invalid_password))
  end

  respond_with(@user)
end

#editObject

GET /users/1/edit.js




27
28
29
# File 'app/controllers/users_controller.rb', line 27

def edit
  respond_with(@user)
end

#opportunities_overviewObject

GET /users/opportunities_overview




107
108
109
110
# File 'app/controllers/users_controller.rb', line 107

def opportunities_overview
  @users_with_opportunities = User.have_assigned_opportunities.order(:first_name)
  @unassigned_opportunities = Opportunity.my(current_user).unassigned.pipeline.order(:stage).includes(:account, :user, :tags)
end

#passwordObject

GET /users/1/password GET /users/1/password.js




74
75
76
# File 'app/controllers/users_controller.rb', line 74

def password
  respond_with(@user)
end

#redrawObject

GET /users/1/redraw




100
101
102
103
# File 'app/controllers/users_controller.rb', line 100

def redraw
  current_user.preference[:locale] = params[:locale]
  render js: %(window.location.href = "#{user_path(current_user)}";)
end

#showObject

GET /users/1 GET /users/1.js




20
21
22
23
# File 'app/controllers/users_controller.rb', line 20

def show
  @user = current_user if params[:id].nil?
  respond_with(@user)
end

#updateObject

PUT /users/1 PUT /users/1.js




34
35
36
37
38
# File 'app/controllers/users_controller.rb', line 34

def update
  @user.update(user_params)
  flash[:notice] = t(:msg_user_updated)
  respond_with(@user)
end

#upload_avatarObject

PUT /users/1/upload_avatar PUT /users/1/upload_avatar.js




50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/users_controller.rb', line 50

def upload_avatar
  if params[:gravatar]
    @user.avatar = nil
    @user.save
    render
  else
    if params[:avatar]
      @avatar = Avatar.create(avatar_params)
      if @avatar.valid?
        @user.avatar = @avatar
      else
        @user.avatar.errors.clear
        @user.avatar.errors.add(:image, t(:msg_bad_image_file))
      end
    end
    responds_to_parent do
      render
    end
  end
end