diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 86a20d3eb..dc60b24a1 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -53,7 +53,7 @@ class FilesController < ApplicationController def create container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) - attachments = Attachment.attach_files(container, params[:attachments]) + attachments = Attachment.attach_filesex(container, params[:attachments],params[:attachment_type]) render_attachment_warning_if_needed(container) if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 792a1776d..f0533e052 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -261,6 +261,12 @@ class Attachment < ActiveRecord::Base result end + def self.attach_filesex(obj, attachments,attachment_type) + result = obj.save_attachmentsex(attachments, User.current,attachment_type) + obj.attach_saved_attachments + result + end + def self.latest_attach(attachments, filename) attachments.sort_by(&:created_on).reverse.detect { |att| att.filename.downcase == filename.downcase diff --git a/app/models/project.rb b/app/models/project.rb index e0cc27b3b..827ed0990 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -38,8 +38,7 @@ class Project < ActiveRecord::Base :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})" has_many :users, :through => :members has_many :principals, :through => :member_principals, :source => :principal - - has_many :enabled_modules, :dependent => :delete_all + has_many :enabled_modules, :dependent => :delete_all has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" has_many :issues, :dependent => :destroy, :include => [:status, :tracker] has_many :issue_changes, :through => :issues, :source => :journals @@ -159,8 +158,12 @@ class Project < ActiveRecord::Base def new_course self.where('project_type = ?', 1) end - - + + # 获取项目的资源类型列表 + def attachmenttypes + @attachmenttypes = Attachmentstype.find(:all, :conditions => ["#{Attachmentstype.table_name}.typeId= ?",self.attachmenttype ]) + end + # 项目留言 added by fq def self.add_jour(user, notes) project = Project.find('trustie') @@ -726,7 +729,8 @@ class Project < ActiveRecord::Base 'custom_fields', 'tracker_ids', 'issue_custom_field_ids', - 'project_type' + 'project_type', + 'attachmenttype' diff --git a/app/views/files/_new.html.erb b/app/views/files/_new.html.erb index ac5dce466..fcb916e3b 100644 --- a/app/views/files/_new.html.erb +++ b/app/views/files/_new.html.erb @@ -1,5 +1,6 @@
+ <%= select_tag "attachment_type", content_tag('option', '') + + options_from_collection_for_select(attachmenttypes, "id", + "typeName") %> +
+ <% end %> +<%= render :partial => 'attachments/form' %>