diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 5dbb4f2b..af96d9c6 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -197,6 +197,35 @@ class AttachmentsController < ApplicationController end end + def add_exist_file_to_course + class_id = params[:class_id] + attachments = params[:attachment][:attach] + + obj = Course.find_by_id(class_id) + attachments.collect do |attach_id| + ori = Attachment.find_by_id(attach_id) + next if ori.blank? + attach_copied_obj = ori.copy + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = obj + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + @obj = obj + @save_flag = attach_copied_obj.save + @save_message = attach_copied_obj.errors.full_messages + end + + respond_to do |format| + format.js + end + rescue NoMethodError + @save_flag = false + @save_message = [] << l(:error_attachment_empty) + respond_to do |format| + format.js + end + end + private def find_project @attachment = Attachment.find(params[:id]) diff --git a/app/views/attachments/add_exist_file_to_course.js.erb b/app/views/attachments/add_exist_file_to_course.js.erb new file mode 100644 index 00000000..58e5690e --- /dev/null +++ b/app/views/attachments/add_exist_file_to_course.js.erb @@ -0,0 +1,17 @@ +<% if @save_flag %> + window.location.reload(); +<% else %> + // alert('添加文件失败:\n<%=@save_message[0]%>'); + $('#ajax-modal').html('