添加功能<用户搜索的问题>

Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
alan 2014-11-04 17:06:16 +08:00
parent 495c4db43e
commit 1d76d559dd
5 changed files with 26 additions and 6 deletions

View File

@ -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'

View File

@ -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
}

View File

@ -8,8 +8,10 @@
alert("搜索条件不能为空");
return;
}
$("#search_user_form").submit();
}
</script>
<div class="top-content">
@ -21,8 +23,12 @@
<td rowspan="2">
</td>
<td rowspan="2" >
<div class="project-search" style="float: right">
<%= text_field_tag 'name', params[:name], :size => 30 %>
<div class="project-search" style="float: right">
<label for="user_browse_label"><%= l(:label_user_search_type) %></label>
<%= select "search_by", "id",
{ l(:label_search_by_login) => "0", l(:label_search_by_name) => "1", l(:label_search_by_email) => "2" },
:size => 20 %>
<%= text_field_tag 'name', params[:name], :size => 30 %>
<input type="button" class="enterprise" value="<%= l(:label_search) %>" onclick="searchUser();"/>
<%#= submit_tag l(:label_search), :class => "enterprise", :name => nil %>
</div>

View File

@ -19,7 +19,11 @@
<td rowspan="2">
</td>
<td rowspan="2" >
<div class="project-search" style="float: right">
<div class="project-search" style="float: right">
<label for="user_browse_label"><%= l(:label_user_search_type) %></label>
<%= select "search_by", "id",
{ l(:label_search_by_login) => "0", l(:label_search_by_name) => "1", l(:label_search_by_email) => "2" },
:size => 20 %>
<%= text_field_tag 'name', params[:name], :size => 30 %>
<input type="button" class="enterprise" value="<%= l(:label_search) %>" onclick="searchUser();"/>
<%#= submit_tag l(:label_search), :class => "enterprise", :name => nil %>

View File

@ -852,6 +852,10 @@ zh:
label_roadmap_due_in: "截止日期到 %{value}"
label_roadmap_overdue: "%{value} 延期"
label_roadmap_no_issues: 该版本没有问题
label_user_search_type: 搜索类型
label_search_by_login: 昵称
label_search_by_name: 名字
label_search_by_email: 邮箱
label_search: 搜索
label_result_plural: 结果
label_all_words: 所有单词