diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c4a46abc1..3de491421 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/courses/_course_activity.html.erb b/app/views/courses/_course_activity.html.erb index e2e1dcfc2..44b72868d 100644 --- a/app/views/courses/_course_activity.html.erb +++ b/app/views/courses/_course_activity.html.erb @@ -94,7 +94,7 @@ $('#reply_content_<%= activity.id %> a').colorbox({rel:'nofollow', close: "关闭", returnFocus: false}); }); - <% if activity %> + <% if activity && activity.course_act%> <% act = activity.course_act %> <% case activity.course_act_type.to_s %> <% when 'HomeworkCommon' %> diff --git a/app/views/student_work/new.html.erb b/app/views/student_work/new.html.erb index c7f1d45c4..09544d004 100644 --- a/app/views/student_work/new.html.erb +++ b/app/views/student_work/new.html.erb @@ -21,6 +21,19 @@ ""); $('#ajax-modal').parent().css("top","30%").css("left","20%").css("position","fixed"); } + + // 点击 checkbox选中引用的资源的时候,保存该资源的id到session里去 + function store_seleted_resource(dom){ + if(dom.attr('checked') == 'checked' ){ + $.get( + '<%= store_selected_resource_user_path(User.current) %>'+'?save=y&res_id='+dom.val() + ) + }else { + $.get( + '<%= store_selected_resource_user_path(User.current) %>'+'?save=n&res_id='+dom.val() + ) + } + }
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} %>