diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 055c59f06..5252e5884 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/views/users/_homework_ref_resources_list.html.erb b/app/views/users/_homework_ref_resources_list.html.erb new file mode 100644 index 000000000..356e412e7 --- /dev/null +++ b/app/views/users/_homework_ref_resources_list.html.erb @@ -0,0 +1,25 @@ + +<% if attachments.nil? || attachments.empty? %> + + + +<% else %> + <% attachments.each do |attach| %> + + <% end %> +<% end %> diff --git a/app/views/users/_show_user_resource.html.erb b/app/views/users/_show_user_resource.html.erb index 855f30071..6d985687c 100644 --- a/app/views/users/_show_user_resource.html.erb +++ b/app/views/users/_show_user_resource.html.erb @@ -51,7 +51,7 @@ <%= form_tag(import_resources_to_homework_user_path(user),:method => 'post',:remote=>'true') do %>
- <%= render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments} %> + <%= render :partial => 'homework_ref_resources_list' ,:locals=>{ :attachments => @attachments,:seleted_resources=>seleted_resources} %>