引用资源支持多页选择
This commit is contained in:
parent
590a2480ba
commit
c85e1401f0
|
@ -522,6 +522,7 @@ class UsersController < ApplicationController
|
|||
@atta_count = @attachments.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@seleted_resources = session[:seleted_resource_ids].nil? ? [] : session[:seleted_resource_ids]
|
||||
#@curse_attachments_all = @all_attachments[@offset, @limit]
|
||||
@attachments = paginateHelper @attachments,7
|
||||
respond_to do |format|
|
||||
|
@ -555,6 +556,7 @@ class UsersController < ApplicationController
|
|||
@atta_count = @attachments.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@seleted_resources = session[:seleted_resource_ids].nil? ? [] : session[:seleted_resource_ids]
|
||||
#@curse_attachments_all = @all_attachments[@offset, @limit]
|
||||
@attachments = paginateHelper @attachments,7
|
||||
respond_to do |format|
|
||||
|
@ -586,6 +588,7 @@ class UsersController < ApplicationController
|
|||
@atta_count = @attachments.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@seleted_resources = session[:seleted_resource_ids].nil? ? [] : session[:seleted_resource_ids]
|
||||
#@curse_attachments_all = @all_attachments[@offset, @limit]
|
||||
@attachments = paginateHelper @attachments,7
|
||||
respond_to do |format|
|
||||
|
@ -596,8 +599,8 @@ class UsersController < ApplicationController
|
|||
#将资源批量引入
|
||||
def import_resources_to_homework
|
||||
@attachments = []
|
||||
unless params[:checkbox1].nil? || params[:checkbox1].blank?
|
||||
params[:checkbox1].each do |id|
|
||||
unless session[:seleted_resource_ids].nil? || session[:seleted_resource_ids].blank?
|
||||
session[:seleted_resource_ids].each do |id|
|
||||
atta = Attachment.find(id)
|
||||
att_copy = atta.copy
|
||||
att_copy.container_id = nil
|
||||
|
@ -608,11 +611,23 @@ class UsersController < ApplicationController
|
|||
@attachments << att_copy
|
||||
end
|
||||
end
|
||||
session[:seleted_resource_ids] = [] #保存后清空
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
# ajax 用session保存选择的资源id
|
||||
def store_selected_resource
|
||||
session[:seleted_resource_ids] = [] if session[:seleted_resource_ids].nil?
|
||||
if params[:save] == 'y'
|
||||
session[:seleted_resource_ids] << params[:res_id]
|
||||
else
|
||||
session[:seleted_resource_ids].delete( params[:res_id])
|
||||
end
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
|
||||
include CoursesHelper
|
||||
def user_courses
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
<% if attachments.nil? || attachments.empty? %>
|
||||
<!--<p class="nodata">-->
|
||||
<!--<%#= l(:label_no_data) %>-->
|
||||
<!--</p>-->
|
||||
<% else %>
|
||||
<% attachments.each do |attach| %>
|
||||
<ul class="resourcesList">
|
||||
<li class="resourcesListCheckbox fl">
|
||||
<input name="checkbox1[]" type="checkbox" onclick="store_seleted_resource($(this));" <%=seleted_resources.include?(attach.id.to_s) ? 'checked':'' %> value="<%= attach.id%>" class="resourcesCheckbox" />
|
||||
</li>
|
||||
<li class="resourcesListName fl">
|
||||
<!--<a href="javascript:void(0);" class="resourcesBlack"><%#=truncate(attach.filename,:length=>18)%></a>-->
|
||||
<%= link_to truncate(attach.filename,:length=>30), download_named_attachment_path(attach.id, attach.filename),
|
||||
:title => attach.filename,:class=>'resourcesBlack'%>
|
||||
</li>
|
||||
<li class="resourcesListSize fl"><%= number_to_human_size(attach.filesize) %></li>
|
||||
<li class="resourcesListType fl"><%= get_resource_type(attach.container_type)%></li>
|
||||
<li class="resourcesListUploader fl"><%=User.find(attach.author_id).realname.blank? ? User.find(attach.author_id).nickname : User.find(attach.author_id).realname %></li>
|
||||
<li style="display: none"><%= attach.author_id %></li>
|
||||
<li class="resourcesListTime fl"><%= format_date(attach.created_on) %></li>
|
||||
<li style="display: none"><%= attach.id %></li>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% end %>
|
|
@ -51,7 +51,7 @@
|
|||
<%= form_tag(import_resources_to_homework_user_path(user),:method => 'post',:remote=>'true') do %>
|
||||
<input type="hidden" name="homework_id" value="<%= homework_id%>"/>
|
||||
<div style="height: 300px" id="user_ref_resources">
|
||||
<%= render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments} %>
|
||||
<%= render :partial => 'homework_ref_resources_list' ,:locals=>{ :attachments => @attachments,:seleted_resources=>seleted_resources} %>
|
||||
</div>
|
||||
<div >
|
||||
<ul class="wlist" id="resource_ref_pages" style="margin-top: 5px;margin-right: 20px">
|
||||
|
|
|
@ -7,6 +7,20 @@
|
|||
homework_description_editor.html("");
|
||||
$("#homework_editor").toggle();
|
||||
}
|
||||
|
||||
// 点击 checkbox选中引用的资源的时候,保存该资源的id到session里去
|
||||
function store_seleted_resource(dom){
|
||||
console.log(dom.attr('checked'))
|
||||
if(dom.attr('checked') == 'checked' ){
|
||||
$.get(
|
||||
'<%= store_selected_resource_user_path %>'+'?save=y&res_id='+dom.val()
|
||||
)
|
||||
}else {
|
||||
$.get(
|
||||
'<%= store_selected_resource_user_path %>'+'?save=n&res_id='+dom.val()
|
||||
)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<div class="homepageRightBanner mb10">
|
||||
<div class="NewsBannerName">作业</div>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'users/show_user_resource',:locals => {:user => @user,:homework_id=>@homework_id}) %>');
|
||||
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'users/show_user_resource',:locals => {:user => @user,:homework_id=>@homework_id,:seleted_resources=>@seleted_resources}) %>');
|
||||
showModal('ajax-modal', '730px');
|
||||
$('#ajax-modal').css('height','500px').css("width","730px");
|
||||
$('#ajax-modal').siblings().remove();
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
$("#user_ref_resources").html('<%= escape_javascript(render :partial => 'resources_list',:locals=>{:attachments => @attachments})%>');
|
||||
$("#user_ref_resources").html('<%= escape_javascript(render :partial => 'homework_ref_resources_list',:locals=>{:attachments => @attachments,:seleted_resources=>@seleted_resources})%>');
|
||||
$("#resource_ref_pages").html('<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
|
|
@ -1,2 +1,2 @@
|
|||
$("#user_ref_resources").html('<%= escape_javascript(render :partial => 'resources_list',:locals=>{:attachments => @attachments})%>');
|
||||
$("#user_ref_resources").html('<%= escape_javascript(render :partial => 'homework_ref_resources_list',:locals=>{:attachments => @attachments,:seleted_resources=>@seleted_resources})%>');
|
||||
$("#resource_ref_pages").html('<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
|
|
@ -386,6 +386,7 @@ RedmineApp::Application.routes.draw do
|
|||
get 'user_resource_type'
|
||||
get 'user_ref_resource_search'
|
||||
post 'import_resources_to_homework'
|
||||
get 'store_selected_resource'
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue