diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f62286973..3149b0fb4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -880,7 +880,9 @@ class UsersController < ApplicationController @course = @user.courses .select { |course| @user.allowed_to?(:as_teacher,course)} end + #这里仅仅是传递需要发送的资源id @send_id = params[:send_id] + @send_ids = params[:checkbox1] || params[:send_ids] respond_to do |format| format.js end @@ -894,32 +896,57 @@ class UsersController < ApplicationController else @projects = @user.projects end + #这里仅仅是传递需要发送的资源id @send_id = params[:send_id] + @send_ids = params[:checkbox1] || params[:send_ids] #搜索的时候 和 直接 用表格提交的时候的send_ids respond_to do |format| format.js end end - # 将资源发送到对应的课程 + # 将资源发送到对应的课程,分为发送单个,或者批量发送 def add_exist_file_to_course - send_id = params[:send_id] - course_ids = params[:course_ids] - unless course_ids.nil? - course_ids.each do |id| - ori = Attachment.find_by_id(send_id) - next if ori.blank? - attach_copied_obj = ori.copy - attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 - attach_copied_obj.container = Course.find(id) - attach_copied_obj.created_on = Time.now - attach_copied_obj.author_id = User.current.id - if attach_copied_obj.attachtype == nil - attach_copied_obj.attachtype = 4 + if params[:send_id].present? + send_id = params[:send_id] + ori = Attachment.find_by_id(send_id) + course_ids = params[:course_ids] + unless course_ids.nil? + course_ids.each do |id| + next if ori.blank? + attach_copied_obj = ori.copy + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = Course.find(id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + attach_copied_obj.save + @save_message = attach_copied_obj.errors.full_messages end - attach_copied_obj.save - @save_message = attach_copied_obj.errors.full_messages + end + elsif params[:send_ids].present? + send_ids = params[:send_ids].split(" ") + send_ids.each do |send_id| + ori = Attachment.find_by_id(send_id) + course_ids = params[:course_ids] + unless course_ids.nil? + course_ids.each do |id| + next if ori.blank? + attach_copied_obj = ori.copy + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = Course.find(id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + attach_copied_obj.save + @save_message = attach_copied_obj.errors.full_messages + end + end + end end - end respond_to do |format| format.js end @@ -927,22 +954,45 @@ class UsersController < ApplicationController # 添加资源到对应的项目 def add_exist_file_to_project - send_id = params[:send_id] - project_ids = params[:projects_ids] - ori = Attachment.find_by_id(send_id) - unless project_ids.nil? - project_ids.each do |project_id| - next if ori.blank? - attach_copied_obj = ori.copy - attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 - attach_copied_obj.container = Project.find(project_id) - attach_copied_obj.created_on = Time.now - attach_copied_obj.author_id = User.current.id - if attach_copied_obj.attachtype == nil - attach_copied_obj.attachtype = 1 + if params[:send_id].present? + send_id = params[:send_id] + project_ids = params[:projects_ids] + ori = Attachment.find_by_id(send_id) + unless project_ids.nil? + project_ids.each do |project_id| + next if ori.blank? + attach_copied_obj = ori.copy + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = Project.find(project_id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 1 + end + attach_copied_obj.save end - attach_copied_obj.save end + elsif params[:send_ids].present? + send_ids = params[:send_ids].split(" ") + send_ids.each do |send_id| + project_ids = params[:projects_ids] + ori = Attachment.find_by_id(send_id) + unless project_ids.nil? + project_ids.each do |project_id| + next if ori.blank? + attach_copied_obj = ori.copy + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = Project.find(project_id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 1 + end + attach_copied_obj.save + end + end + end + else end respond_to do |format| diff --git a/app/views/users/_resource_share_for_project_popup.html.erb b/app/views/users/_resource_share_for_project_popup.html.erb index 70191e5f3..9cd744c9a 100644 --- a/app/views/users/_resource_share_for_project_popup.html.erb +++ b/app/views/users/_resource_share_for_project_popup.html.erb @@ -4,7 +4,7 @@
将资源发送至
- @@ -14,7 +14,8 @@
<%= form_tag search_user_project_user_path(user),:method => 'get', :remote=>true,:id=>'search_user_project_form',:class=>'resourcesSearchBox' do %> - <%= hidden_field_tag(:send_id, @send_id) %> + <%= hidden_field_tag(:send_id, send_id) %> + <%= hidden_field_tag(:send_ids, send_ids) %> <%= submit_tag '',:class=>'searchIconPopup',:onfocus=>"this.blur();",:style=>'border-style:none' %> @@ -23,7 +24,8 @@ <%= form_tag add_exist_file_to_project_user_path(user),:remote=>true,:id=>'projects_list_form' %>
- <%= hidden_field_tag(:send_id, @send_id) %> + <%= hidden_field_tag(:send_id, send_id) %> + <%= hidden_field_tag(:send_ids, send_ids) %> <% if !projects.empty? %> <% projects.each do |project| %>
    diff --git a/app/views/users/_resource_share_popup.html.erb b/app/views/users/_resource_share_popup.html.erb index ca85cf262..ea1ada447 100644 --- a/app/views/users/_resource_share_popup.html.erb +++ b/app/views/users/_resource_share_popup.html.erb @@ -4,7 +4,7 @@
    将资源发送至
    - @@ -14,7 +14,8 @@
    <%= form_tag search_user_course_user_path(user),:method => 'get', :remote=>true,:id=>'search_user_course_form',:class=>'resourcesSearchBox' do %> - <%= hidden_field_tag(:send_id, @send_id) %> + <%= hidden_field_tag(:send_id, send_id) %> + <%= hidden_field_tag(:send_ids, send_ids) %> <%= submit_tag '',:class=>'searchIconPopup',:onfocus=>"this.blur();",:style=>'border-style:none' %> @@ -23,7 +24,8 @@ <%= form_tag add_exist_file_to_course_user_path(user),:remote=>true,:id=>'course_list_form' %>
    - <%= hidden_field_tag(:send_id, @send_id) %> + <%= hidden_field_tag(:send_id, send_id) %> + <%= hidden_field_tag(:send_ids, send_ids) %> <% if !courses.empty? %> <% courses.each do |course| %>
      diff --git a/app/views/users/search_user_course.js.erb b/app/views/users/search_user_course.js.erb index e3d4bb2d4..7d880da69 100644 --- a/app/views/users/search_user_course.js.erb +++ b/app/views/users/search_user_course.js.erb @@ -7,5 +7,5 @@ var popupHeight = $(".resourceSharePopup").outerHeight(true); $(".resourceSharePopup").css("marginTop",-popupHeight/2); $("#upload_box").css('left',objLeft).css('top',objTop); -$("#upload_box").html('<%= escape_javascript( render :partial => "resource_share_popup" ,:locals => {:courses=>@course,:user=>@user})%>'); +$("#upload_box").html('<%= escape_javascript( render :partial => "resource_share_popup" ,:locals => {:courses=>@course,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); $("#upload_box").css('display','block'); \ No newline at end of file diff --git a/app/views/users/search_user_project.js.erb b/app/views/users/search_user_project.js.erb index c22e4ad6d..556534560 100644 --- a/app/views/users/search_user_project.js.erb +++ b/app/views/users/search_user_project.js.erb @@ -7,5 +7,5 @@ var popupHeight = $(".resourceSharePopup").outerHeight(true); $(".resourceSharePopup").css("marginTop",-popupHeight/2); $("#upload_box").css('left',objLeft).css('top',objTop); -$("#upload_box").html('<%= escape_javascript( render :partial => "resource_share_for_project_popup" ,:locals => {:projects=>@projects,:user=>@user})%>'); +$("#upload_box").html('<%= escape_javascript( render :partial => "resource_share_for_project_popup" ,:locals => {:projects=>@projects,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); $("#upload_box").css('display','block'); \ No newline at end of file diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 7b173409a..9565f7e38 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -96,8 +96,8 @@ 删除
      选择 0 个资源
      -
      - 发送 +
      + 发送
      @@ -261,9 +261,10 @@ $(".resourcesList").click(function(e) { } ); } - } + + function show_send(){ $("#contextMenu").hide(); document.oncontextmenu = function() {return true;} @@ -282,6 +283,20 @@ $(".resourcesList").click(function(e) { } } + function batch_send(){ + if (lastSendType === '1'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。 + $.ajax({ + type: 'get', + url: '<%= search_user_course_user_path(@user)%>' + '?'+ $("#resources_list_form").serialize() + }); + }else{ + $.ajax({ + type: 'get', + url: '<%= search_user_project_user_path(@user)%>' + '?' + $("#resources_list_form").serialize() + }); + } + } + function preview(){ $("#contextMenu").hide(); document.oncontextmenu = function() {return true;} @@ -375,23 +390,41 @@ $(".resourcesList").click(function(e) { } } - function chooseSendType(){ - sendType = $(".resourcesSendType").val(); - if(sendType === lastSendType){ - return; - }else if(lastSendType != null){ //不是第一次点击的时候 - if(sendType === '1'){ - $.ajax({ - type:'get', - url:'<%= search_user_course_user_path(@user)%>'+'?send_id='+id - }); - }else{ - $.ajax({ - type:'get', - url:'<%= search_user_project_user_path(@user)%>'+'?send_id='+id - }); + //id 发送的id + //发送的id数组 + function chooseSendType(res_id,res_ids){ + + sendType = $(".resourcesSendType").val(); + if (sendType === lastSendType) { + return; + } else if (lastSendType != null) { //不是第一次点击的时候 + if(res_ids == "") {//如果是单个发送 + if (sendType === '1') { + $.ajax({ + type: 'get', + url: '<%= search_user_course_user_path(@user)%>' + '?send_id=' + id + }); + } else { + $.ajax({ + type: 'get', + url: '<%= search_user_project_user_path(@user)%>' + '?send_id=' + id + }); + } + }else{//如果是多个发送 + if (sendType === '1'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。 + $.ajax({ + type: 'get', + url: '<%= search_user_course_user_path(@user)%>' + '?'+ $("#resources_list_form").serialize() + }); + }else{ + $.ajax({ + type: 'get', + url: '<%= search_user_project_user_path(@user)%>' + '?' + $("#resources_list_form").serialize() + }); + } + } } - } + lastSendType = sendType; } diff --git a/public/stylesheets/public_new.css b/public/stylesheets/public_new.css index 8d8186204..235526766 100644 --- a/public/stylesheets/public_new.css +++ b/public/stylesheets/public_new.css @@ -490,7 +490,13 @@ a.resourcesBlack:hover {font-size:12px; color:#000000;} .resourcesListOption {width:710px; height:40px; line-height:40px; vertical-align:middle; margin-left:auto; margin-right:auto; background-color:#f6f6f6;} .resourcesCheckAll {width:20px; height:40px; line-height:40px; text-align:center; vertical-align:middle; float:left;} .resourcesSelectSend {float:right;} +/*.resourcesSelectSendButton {width:75px; height:28px; background-color:#ffffff; line-height:28px; vertical-align:middle; margin-top:5px; margin-right:10px; margin-left:15px; text-align:center; border:1px solid #15bccf; border-radius:5px; float:right;}*/ .resourcesSelectSendButton {width:75px; height:28px; background-color:#ffffff; line-height:28px; vertical-align:middle; margin-top:5px; margin-right:10px; margin-left:15px; text-align:center; border:1px solid #15bccf; border-radius:5px; float:right;} +a.sendButtonBlue {color:#15bccf;} +a.sendButtonBlue:hover {color:#ffffff;} +.resourcesSelectSendButton:hover {background-color:#15bccf;} +.db {display:block;} + .dropdown-menu { position: absolute; top: 100%;