diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 67d47dc26..d94615791 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2236,6 +2236,69 @@ class UsersController < ApplicationController end end + # 内容导入到对象中 + def import_into_container + # attachments = Attachment.where("id in (#{params[:checkbox1].join(',')})") + # if params[:mul_type] == "Project" + # + # elsif params[:mul_type] == "Course" + # Attachment.create(:container_id => params[:mul_id], :container_type => "Course", :name => attachment.name) + # elsif params[:mul_type] == "SubfieldFile" + # end + + unless params[:checkbox1].blank? + send_ids = params[:checkbox1] + # mul_id为当前课程id、项目id、组织id的多种形态 + mul_id = params[:mul_id] + if params[:mul_type] == "Course" + mul_container = Course.find(mul_id) + elsif params[:mul_type] == "Project" + mul_container = Project.find(mul_id) + elsif params[:mul_type] == "SubfieldFile" + mul_container = OrgSubfield.find(mul_id) + end + send_ids.each do |send_id| + ori = Attachment.find_by_id(send_id) + # 如果该附件已经存课程中,则只更新附件创建时间 + mul_container.attachments.each do |att| + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break + end + end + next if @exist + attach_copied_obj = ori.copy + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = mul_container + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.is_public = 0 + attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from + 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 + if params[:mul_type] == "Course" + respond_to do |format| + redirect_to course_files_url(mul_container) + end + elsif params[:mul_type] == "Project" + respond_to do |format| + redirect_to project_files_url(mul_container) + end + elsif params[:mul_type] == "SubfieldFile" + respond_to do |format| + redirect_to org_subfield_files_url(mul_container) + end + end + + end + # 根据资源关键字进行搜索 def resource_search search = "%#{params[:search].strip.downcase}%" diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index 545680505..4a62c94aa 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -94,7 +94,7 @@ <%= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite" %> <% if is_course_teacher(User.current,@course) || (@course.publish_resource==1 && User.current.member_of_course?(@course) ) %> - <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :course => true), :class => "blue-btn fr mr5", :remote => true) %> + <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %> <% end %> <% end %> diff --git a/app/views/files/_project_file.html.erb b/app/views/files/_project_file.html.erb index 0725d9270..98b9ad514 100644 --- a/app/views/files/_project_file.html.erb +++ b/app/views/files/_project_file.html.erb @@ -66,7 +66,7 @@ <% if User.current.member_of?(@project) %> - <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :project => true), :class => "blue-btn fr mr5", :remote => true) %> + <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :project_id => @project.id), :class => "blue-btn fr mr5", :remote => true) %> <% end %> <% end %> diff --git a/app/views/files/_subfield_files.html.erb b/app/views/files/_subfield_files.html.erb index 3e98b2ee5..2a8756c47 100644 --- a/app/views/files/_subfield_files.html.erb +++ b/app/views/files/_subfield_files.html.erb @@ -42,7 +42,7 @@ <%= submit_tag "栏目内搜索", :class => "blueBtn mr5 fl",:style => 'width:72px;',:name => "inorg_subfield",:id => "inorg_subfield", :onmouseover => "presscss('inorg_subfield')",:onmouseout =>"buttoncss()" %> <%= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %> - <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :subfield_file => true), :class => "blue-btn fr mr5", :remote => true) %> + <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :subfield_file_id => @org_subfield.id), :class => "blue-btn fr mr5", :remote => true) %> <%#= link_to "上传资源",subfield_upload_file_org_subfield_files_path(@org_subfield.id, :in_org => 1),:method => "post",:class=>"blueBtn fr mr5",:remote => true %> <% end %> diff --git a/app/views/users/_import_resource_info.html.erb b/app/views/users/_import_resource_info.html.erb index dd82e9485..270f0956b 100644 --- a/app/views/users/_import_resource_info.html.erb +++ b/app/views/users/_import_resource_info.html.erb @@ -20,6 +20,7 @@ <% end %>
+
- <% @attachments.each do |attach| %> + <%= 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"}), + :remote => true , :method => 'post', :id => 'resource_import_container_form') do %> + <% @attachments.each do |attach| %> + <% end %> <% end %>
-
选用
-
取消
+
选用
+
取消
+