导入添加自动搜索

This commit is contained in:
huang 2016-03-16 17:06:11 +08:00
parent e8e9688644
commit 0a881f14e8
5 changed files with 69 additions and 51 deletions

View File

@ -2544,7 +2544,11 @@ class UsersController < ApplicationController
end
def import_resources_search
search = "%#{params[:search].strip.downcase}%"
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
@score = @b_sort == "desc" ? "asc" : "desc"
@user = User.current
@switch_search = params[:name].nil? ? " " : params[:name]
search = "%#{@switch_search.strip.downcase}%"
# 别人的资源库是没有权限去看的
if User.current.id.to_i != params[:id].to_i
render_403
@ -2567,10 +2571,10 @@ class UsersController < ApplicationController
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
@offset ||= @atta_pages.offset
#@curse_attachments_all = @all_attachments[@offset, @limit]
@attachments = paginateHelper @attachments,10
@attachments = paginateHelper @attachments, 10
respond_to do |format|
format.js
format.html {render :layout => 'new_base'}
# format.html {render :layout => 'new_base'}
end
end

View File

@ -26,11 +26,14 @@
<a href="<%= import_resources_user_path(User.current, :type => '6', :subfield_file_id => params[:subfield_file_id]) %>" id="public_resources_choose" class="subject-choose choose-active fl" data-remote="true">公共资源</a>
<a href="<%= import_resources_user_path(User.current, :type => '1', :subfield_file_id => params[:subfield_file_id]) %>" id="my_resources_choose" class="subject-choose fl" data-remote="true">我的资源</a>
<% end %>
<%#= form_tag( url_for(:controller => 'users', :action => 'import_resources_search', :id => User.current.id, :type => 1),
:remote => true , :method => 'get', :id => 'resource_search_form') do %>
<div id="user_import_resource_search">
<%=render :partial=>'users/user_import_resource_search', :locals => {:type => @type, :search => ''} %>
</div>
<!--<%#= form_tag( url_for(:controller => 'users', :action => 'import_resources_search', :id => User.current.id), :remote => true , :method => 'get', :id => 'resource_search_form') do %>-->
<!--<input type="text" name="search" placeholder="输入资源关键词进行搜索" class="subjectSearch fr" />-->
<%#= hidden_field_tag(:type,type.nil? ? 1 : type) %>
<%# end %>
<!--<%#= hidden_field_tag(:type,type.nil? ? 1 : type) %>-->
<!--<%#= submit_tag '', :class => 'homepageSearchIcon', :onfocus => 'this.blur();', :style => 'border-style:none' %>-->
<!--<%# end %>-->
<div class="cl"></div>
@ -42,25 +45,10 @@
<li class="subjectPublisher fl">上传者</li>
<li class="fl subjectDate">上传时间</li>
</ul>
<%= form_tag( url_for({:controller => 'users', :action => 'import_into_container',
:mul_id => params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id],
:mul_type => params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project"}),
:method => 'post', :id => 'resource_import_container_form') do %>
<% @attachments.each do |attach| %>
<ul class="subjectRow">
<li class="subjectName fl hidden">
<label>
<input name="checkbox1[]" type="checkbox" data-has-history="<%= attach.attachment_histories.count == 0 ? 'N' : 'Y' %>" data-deleteble="<%= User.current.id ==attach.author_id ? 'Y' : 'N' %>" onclick="checkAllBox($(this));" value="<%= attach.id%>" class="mr5" style="vertical-align:middle;" />
<span><%= link_to truncate(attach.filename, :length => 30), download_named_attachment_path(attach.id, attach.filename), :title => attach.filename%></span>
</label>
</li>
<li class="subjectType fl"><%= get_resource_type(attach.container_type)%></li>
<li class="subjectCount fl hidden"><%= number_to_human_size(attach.filesize) %></li>
<li class="subjectPublisher fl"><%=User.find(attach.author_id).realname.blank? ? User.find(attach.author_id).nickname : User.find(attach.author_id).realname %></li>
<li class="fl subjectDate"><%= format_date(attach.created_on) %></li>
</ul>
<% end %>
<% end %>
<div id="import_resource_info_list">
<%= render :partial => 'users/user_import_resource_list',:locals => {:project_id => params[:project_id], :subfield_file_id => params[:subfield_file_id], :course_id => params[:course_id]} %>
</div>
</div>
<div class="courseSendSubmit mr15"><a href="javascript:void(0);" class="sendSourceText" onclick="$('#resource_import_container_form').submit();hideModal()">选用</a></div>

View File

@ -0,0 +1,19 @@
<%= form_tag( url_for({:controller => 'users', :action => 'import_into_container',
:mul_id => project_id.nil? ? (course_id.nil? ? subfield_file_id : course_id) : project_id,
:mul_type => project_id.nil? ? (course_id.nil? ? "SubfieldFile" : "Course") : "Project"}),
:method => 'post', :id => 'resource_import_container_form') do %>
<% @attachments.each do |attach| %>
<ul class="subjectRow">
<li class="subjectName fl hidden">
<label>
<input name="checkbox1[]" type="checkbox" data-has-history="<%= attach.attachment_histories.count == 0 ? 'N' : 'Y' %>" data-deleteble="<%= User.current.id ==attach.author_id ? 'Y' : 'N' %>" onclick="checkAllBox($(this));" value="<%= attach.id%>" class="mr5" style="vertical-align:middle;" />
<span><%= link_to truncate(attach.filename, :length => 30), download_named_attachment_path(attach.id, attach.filename), :title => attach.filename%></span>
</label>
</li>
<li class="subjectType fl"><%= get_resource_type(attach.container_type)%></li>
<li class="subjectCount fl hidden"><%= number_to_human_size(attach.filesize) %></li>
<li class="subjectPublisher fl"><%=User.find(attach.author_id).realname.blank? ? User.find(attach.author_id).nickname : User.find(attach.author_id).realname %></li>
<li class="fl subjectDate"><%= format_date(attach.created_on) %></li>
</ul>
<% end %>
<% end %>

View File

@ -0,0 +1,29 @@
<input type="text" name="search" placeholder="输入资源关键词进行搜索" class="subjectSearch fr" />
<script type="text/javascript">
var lastSearchCondition = '';
var count = 0;
function search_hws(e){
if($(e.target).val().trim() == lastSearchCondition && lastSearchCondition != '')
{
return;
}
lastSearchCondition = $(e.target).val().trim();
$.ajax({
url: '<%= url_for(:controller => 'users', :action => 'import_resources_search', :id => User.current.id) %>'+'?name='+ e.target.value+'&type=<%=type %>',
type:'get'
});
}
function throttle(method,context,e){
clearTimeout(method.tId);
method.tId=setTimeout(function(){
method.call(context,e);
},500);
}
//查询项目
$("input[name='search']").on('input', function (e) {
throttle(search_hws,window,e);
});
</script>

View File

@ -1,25 +1,3 @@
//$("#resources_list").html('<%#= escape_javascript( render :partial => 'users/import_resource_info' ,:locals=>{ :attachments => @attachments, :type => @type})%>');
//$("#pages").html('<%#= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
//$("#res_all_count").html(<%#= @atta_count%>);
//$("#res_count").html(0);
//$("#checkboxAll").attr('checked',false);
<% if params[:project_id] %>
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :project_id => params[:project_id]} ) %>');
<% elsif params[:course_id] %>
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :course_id => params[:course_id]} ) %>');
<% elsif params[:subfield_file_id] %>
$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :subfield_file_id => params[:subfield_file_id]} ) %>');
<% end %>
showModal('ajax-modal', '615px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal()' style='margin-left: 580px;'><img src='/images/bid/close.png' width='26px' height='26px' /></a>");
<% if params[:project_id] %>
$('#ajax-modal').parent().css("top","10%").css("left","34%").css("border","3px solid #269ac9");
<% else %>
$('#ajax-modal').parent().css("top","20%").css("left","42%").css("border","3px solid #269ac9");
<% end %>
$('#ajax-modal').parent().addClass("popbox_polls");
$("#import_resource_info_list").html('<%= escape_javascript( render :partial => 'user_import_resource_list',
:locals => {:user => @user, :type => @type, :project_id => params[:project_id], :subfield_file_id => params[:subfield_file_id], :course_id => params[:course_id]} ) %>');
$("#pages").html('<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');