课程、项目首页增加用户姓名、邮箱、昵称等搜索功能

This commit is contained in:
sw 2014-12-30 10:57:39 +08:00
parent 0bce2ae8f3
commit ee1df78f13
4 changed files with 51 additions and 9 deletions

View File

@ -376,8 +376,8 @@ class UsersController < ApplicationController
"show_changesets" => true
}
scope = User.logged.status(@status)
@search_by = params[:search_by] ? params[:search_by][:id] : 0
scope = scope.like(params[:name],"0") if params[:name].present?
@search_by = params[:search_by] ? params[:search_by] :"0"
scope = scope.like(params[:name], @search_by) 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

@ -110,6 +110,7 @@ class WelcomeController < ApplicationController
def search
search_condition = params[:q]
search_type = params[:search_type].to_sym unless search_condition.blank?
search_by = params[:search_by]
if search_type.nil? && params[:contests_search] && params[:name] != ""
search_type = :contests
@ -127,11 +128,11 @@ class WelcomeController < ApplicationController
when :contests
redirect_to contests_url(:name => search_condition)
when :users
redirect_to users_search_url(:name => search_condition)
redirect_to users_search_url(:name => search_condition,:search_by => search_by)
when :users_teacher
redirect_to users_search_url(:name => search_condition, :role => :teacher)
redirect_to users_search_url(:name => search_condition, :search_by => search_by, :role => :teacher)
when :users_student
redirect_to users_search_url(:name => search_condition, :role => :student)
redirect_to users_search_url(:name => search_condition, :search_by => search_by, :role => :student)
else
#redirect_to home_path, :alert => l(:label_sumbit_empty)
(redirect_to home_url, :notice => l(:label_sumbit_empty);return) #if params[:name].blank?

View File

@ -3,8 +3,6 @@
(select_option << ['项目', 'projects']) if project_type == Project::ProjectType_project
(select_option << ['课程', 'courses']) if project_type == Project::ProjectType_course
select_option << ['用户', 'users']
#select_option << ['教师', 'users_teacher'],
#select_option << ['学生', 'users_student']
%>
<style type="text/css">
form #q, form #search_type{
@ -37,6 +35,29 @@ form #search_type{
text-indent: 0.01px;
text-overflow: '';
}
form #search_by
{
font-size: 13px;
color: #363739;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 0px;
border-top-left-radius: 0px;
border-left: 1px outset #83A9A9;
margin-left: -6px;
-webkit-appearance: none;
-moz-appearance: none;
text-indent: 0.01px;
text-overflow: '';
-moz-box-sizing: border-box;
box-sizing: border-box;
display: inline-block;
padding: 5px;
height: 33px;
display: none;
}
.search_widget{
display:inline-block;
border-radius: 5px;
@ -46,11 +67,31 @@ form #search_type{
}
<%#完了把上面东西放到 .css 里%>
</style>
<script type="text/javascript">
function searchTypeChange()
{
if($("#search_type").val() == "users")
{
$("#search_by").show();
}
else
{
$("#search_by").hide();
}
}
function searchByChange()
{
$("#search_by_input").val($("#search_by").val());
}
</script>
<%= form_tag({controller: :welcome, action: :search }, method: :get) do %>
<div class="project-search" style="float: right">
<div class='search_widget'>
<%= text_field_tag :q, nil, placeholder:'请输入要搜索的关键字', :size => 27 %>
<%= select_tag(:search_type, options_for_select(select_option) ) %>
<input type="text" name="search_by_input" hidden="hidden;" id="search_by_input" value="0">
<%= select_tag(:search_type, options_for_select(select_option), :onchange => "searchTypeChange();" ) %>
<%= select_tag(:search_by,options_for_select([["昵称","0"],["姓名","1"],["邮箱","2"]]), :onchange => "searchByChange();" ) %>
</div>
<%#= hidden_field_tag 'project_type', project_type %>
<%= submit_tag l(:label_search), :class => "enterprise", :name => nil %>

View File

@ -73,7 +73,7 @@
<% end %>
</div>
<div class="search-bar" id="search-bar">
<%= render :partial => "search_course", :locals => {:project_type => Project::ProjectType_course} %>
<%= render :partial => "search_project", :locals => {:project_type => Project::ProjectType_course} %>
</div>
<div style="clear: both;"></div>
</div>