登陆后的搜索

This commit is contained in:
lizanle 2015-08-25 18:59:45 +08:00
parent bedc364275
commit 70e9d75cc6
8 changed files with 51 additions and 17 deletions

View File

@ -113,7 +113,8 @@ class CoursesController < ApplicationController
courses = Course.visible.where("LOWER(name) like '%#{params[:name].to_s.downcase}%'") courses = Course.visible.where("LOWER(name) like '%#{params[:name].to_s.downcase}%'")
@courses = paginateHelper courses,10 @courses = paginateHelper courses,10
end end
@name = params[:name]
@type = 'courses'
respond_to do |format| respond_to do |format|
format.html { format.html {
render :layout => 'course_base' render :layout => 'course_base'

View File

@ -93,7 +93,8 @@ class ProjectsController < ApplicationController
@project_count = Project.project_entities.visible.like(params[:name]).page(params[:page]).count @project_count = Project.project_entities.visible.like(params[:name]).page(params[:page]).count
@project_pages = Paginator.new @project_count, @limit, params['page'] @project_pages = Paginator.new @project_count, @limit, params['page']
@name = params[:name]
@type = 'projects'
respond_to do |format| respond_to do |format|
format.html { format.html {
render :layout => 'base' render :layout => 'base'

View File

@ -453,6 +453,8 @@ class UsersController < ApplicationController
end end
@users = scope.offset(@offset).limit(limit).all.reverse @users = scope.offset(@offset).limit(limit).all.reverse
end end
@name = params[:name]
@type = 'users'
respond_to do |format| respond_to do |format|
format.html { format.html {
@groups = Group.all.sort @groups = Group.all.sort

View File

@ -17,24 +17,40 @@
</li> </li>
</ul> </ul>
</div> </div>
<script>
<% type = type%>
$(document).ready(function (){
if('<%= type %>' != null && '<%= type %>' == 'courses' ){
$('input:radio[value="courses"]').attr('checked','checked');
}
if('<%= type %>' != null && '<%= type %>' == 'projects' ){
$('input:radio[value="projects"]').attr('checked','checked');
}
if('<%= type %>' != null && '<%= type %>' == 'users' ){
$('input:radio[value="users"]').attr('checked','checked');
}
});
</script>
<div class="fl" id="navHomepageSearch"> <div class="fl" id="navHomepageSearch">
<form class="navHomepageSearchBox"> <!--<form class="navHomepageSearchBox">-->
<input type="text" name="navHomepageSearch" class="navHomepageSearchInput" /> <% name = name%>
<a href="javascript:void(0);" class="homepageSearchIcon"></a>
</form>
<%= form_tag({controller: :welcome, action: :search },:class=>'navHomepageSearchBox', method: :get) do %>
<input type="text" name="q" value="<%= name.nil? ? "" : name%>" class="navHomepageSearchInput" />
<input type="hidden" name="search_type" id="type" value=""/>
<a href="javascript:void(0);" class="homepageSearchIcon" onclick="$('#type').val($('input[type=radio]:checked').val());$(this).parent().submit();"></a>
<% end %>
<div class="navSearchTypeBox" id="navHomepageSearchType"> <div class="navSearchTypeBox" id="navHomepageSearchType">
<div class="fl mr15 mt8"> <div class="fl mr15 mt8">
<input type="radio" value="课程" name="navSearchType" checked/> <input type="radio" value="courses" name="search_type" checked/>
课程 课程
</div> </div>
<div class="fl mr15 mt8"> <div class="fl mr15 mt8">
<input type="radio" value="项目" name="navSearchType" /> <input type="radio" value="projects" name="search_type" />
项目 项目
</div> </div>
<div class="fl mr15 mt8"> <div class="fl mr15 mt8">
<input type="radio" value="用户" name="navSearchType" /> <input type="radio" value="users" name="search_type" />
用户 用户
</div> </div>
<div id="navSearchAlert" class="fr mr10"> <div id="navSearchAlert" class="fr mr10">

View File

@ -18,11 +18,25 @@
// alert(3) // alert(3)
$(doc).parent().submit(); $(doc).parent().submit();
} }
<% type = type%>
$(document).ready(function (){
if('<%= type %>' != null && '<%= type %>' == 'courses' ){
$('input:radio[value="courses"]').attr('checked','checked');
}
if('<%= type %>' != null && '<%= type %>' == 'projects' ){
$('input:radio[value="projects"]').attr('checked','checked');
}
if('<%= type %>' != null && '<%= type %>' == 'users' ){
$('input:radio[value="users"]').attr('checked','checked');
}
});
</script> </script>
<div class="fl" id="navHomepageSearch"> <div class="fl" id="navHomepageSearch">
<!--<form class="navHomepageSearchBox">--> <!--<form class="navHomepageSearchBox">-->
<% name = name%>
<%= form_tag({controller: :welcome, action: :search },:class=>'navHomepageSearchBox', method: :get) do %> <%= form_tag({controller: :welcome, action: :search },:class=>'navHomepageSearchBox', method: :get) do %>
<input type="text" name="q" class="navHomepageSearchInput"/> <input type="text" name="q" value="<%= name.nil? ? "" : name%>" class="navHomepageSearchInput"/>
<input type="hidden" name="search_type" id="type" value=""/> <input type="hidden" name="search_type" id="type" value=""/>
<a href="javascript:void(0);" class="homepageSearchIcon" onclick="$('#type').val($('input[type=radio]:checked').val());$(this).parent().submit();"></a> <a href="javascript:void(0);" class="homepageSearchIcon" onclick="$('#type').val($('input[type=radio]:checked').val());$(this).parent().submit();"></a>
<% end %> <% end %>

View File

@ -24,9 +24,9 @@
<div class="cl"></div> <div class="cl"></div>
<div class="navContainer mb10"> <div class="navContainer mb10">
<% if User.current.logged? %> <% if User.current.logged? %>
<%= render :partial => 'layouts/logined_header' %> <%= render :partial => 'layouts/logined_header',:locals=>{:name=>@name,:type=>@type} %>
<% else%> <% else%>
<%= render :partial => 'layouts/unlogin_header' %> <%= render :partial => 'layouts/unlogin_header',:locals=>{:name=>@name,:type=>@type} %>
<% end%> <% end%>
</div> </div>
<div class="cl"></div> <div class="cl"></div>

View File

@ -27,9 +27,9 @@
<div class="cl"></div> <div class="cl"></div>
<div class="navContainer mb10"> <div class="navContainer mb10">
<% if User.current.logged? %> <% if User.current.logged? %>
<%= render :partial => 'layouts/logined_header' %> <%= render :partial => 'layouts/logined_header' ,:locals=>{:name=>@name,:type=>@type}%>
<% else%> <% else%>
<%= render :partial => 'layouts/unlogin_header' %> <%= render :partial => 'layouts/unlogin_header' ,:locals=>{:name=>@name,:type=>@type}%>
<% end%> <% end%>
</div> </div>
<div class="cl"></div> <div class="cl"></div>

View File

@ -22,9 +22,9 @@
<div class="cl"></div> <div class="cl"></div>
<div class="navContainer mb10"> <div class="navContainer mb10">
<% if User.current.logged? %> <% if User.current.logged? %>
<%= render :partial => 'layouts/logined_header' %> <%= render :partial => 'layouts/logined_header',:locals=>{:name=>@name,:type=>@type} %>
<% else%> <% else%>
<%= render :partial => 'layouts/unlogin_header' %> <%= render :partial => 'layouts/unlogin_header',:locals=>{:name=>@name,:type=>@type} %>
<% end%> <% end%>
</div> </div>
<div class="cl"></div> <div class="cl"></div>