diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7e6e3d04a..5357c43ce 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -374,7 +374,7 @@ class UsersController < ApplicationController "show_changesets" => true } scope = User.logged.status(@status) - scope = scope.like(params[:name]) if params[:name].present? + scope = scope.like(params[:name],params[:search_by][:id]) if params[:name].present? @user_count = scope.count @user_pages = Paginator.new @user_count, @limit, params['page'] @user_base_tag = params[:id] ? 'base_users':'users_base' diff --git a/app/models/user.rb b/app/models/user.rb index 1e6c21c71..93356f58c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -198,13 +198,19 @@ class User < Principal } scope :sorted, lambda { order(*User.fields_for_order_statement)} - scope :like, lambda {|arg| + scope :like, lambda {|arg, type| if arg.blank? where(nil) else pattern = "%#{arg.to_s.strip.downcase}%" #where(" LOWER(concat(lastname, firstname)) LIKE :p ", :p => pattern) - where(" LOWER(login) LIKE :p ", :p => pattern) + if type == "0" + where(" LOWER(login) LIKE :p ", :p => pattern) + elsif type == "1" + where(" LOWER(concat(lastname, firstname)) LIKE :p ", :p => pattern) + else + where(" LOWER(mail) LIKE :p ", :p => pattern) + end end } diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 25c1c15c8..65e1bf2f5 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -8,8 +8,10 @@ alert("搜索条件不能为空"); return; } + $("#search_user_form").submit(); } +
@@ -21,8 +23,12 @@ -