From e7d53f5e16ad2c44bd9461f3c493d0a8e3073811 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Fri, 13 Nov 2015 11:17:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=B5=84=E6=BA=90=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=85=81=E8=AE=B8=E5=A4=9A=E9=80=89tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 54 +++++++++++++++--------- app/views/files/_upload_course_files.erb | 12 +++--- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index dd8dc84c4..cbbf36ea8 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -374,30 +374,29 @@ class FilesController < ApplicationController if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Mailer.run.attachments_added(attachments[:files]) end - - if params[:course_attachment_type] && params[:course_attachment_type] != "5" - case params[:course_attachment_type] - when "1" - tag_name = l(:label_courseware) - when "2" - tag_name = l(:label_software) - when "3" - tag_name = l(:label_media) - when "4" - tag_name = l(:label_code) - when "6" - tag_name = "论文" - else - tag_name = "" + if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) + params[:course_attachment_type].each do |type| + tag_name = get_tag_name_by_type_number type + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end + end end - if !attachments.empty? && attachments[:files] && tag_name != "" - attachments[:files].each do |attachment| - attachment.tag_list.add(tag_name) - attachment.save + else + if params[:course_attachment_type] && params[:course_attachment_type] != "5" + tag_name = get_tag_name_by_type_number params[:course_attachment_type] + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end end end end + # TODO: 临时用 nyan sort_init 'created_on', 'desc' sort_update 'created_on' => "#{Attachment.table_name}.created_on", @@ -424,6 +423,23 @@ class FilesController < ApplicationController end end + def get_tag_name_by_type_number type + case type + when "1" + tag_name = l(:label_courseware) + when "2" + tag_name = l(:label_software) + when "3" + tag_name = l(:label_media) + when "4" + tag_name = l(:label_code) + when "6" + tag_name = "论文" + else + tag_name = "" + end + end + def tag_saveEx @tags = params[:tag_name][:name] @obj_id = params[:object_id] diff --git a/app/views/files/_upload_course_files.erb b/app/views/files/_upload_course_files.erb index f023e8413..86ec79e67 100644 --- a/app/views/files/_upload_course_files.erb +++ b/app/views/files/_upload_course_files.erb @@ -10,12 +10,12 @@