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/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 4c0d9188..0216d529 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -256,14 +256,14 @@ class TagsController < ApplicationController # 获取有某类对象的tag总数 def get_tags_size - @issues_tags_num = Issue.tag_counts.size - @projects_tags_num = Project.tag_counts.size - @users_tags_num = User.tag_counts.size - @bids_tags_num = Bid.tag_counts.size - forum_tags_num = Forum.tag_counts.size - attachment_tags_num = Attachment.tag_counts.size - @open_source_projects_num = OpenSourceProject.tag_counts.size - @contests_tags_num = Contest.tag_counts.size + @issues_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Issue").count + @projects_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Project").count + @users_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"User").count + @bids_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Bid").count + forum_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Forum").count + attachment_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Attachment").count + @open_source_projects_num = ActsAsTaggableOn::Tagging.where(taggable_type:"OpenSourceProject").count + @contests_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Contest").count return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @contests_tags_num, @open_source_projects_num end 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('