From 753746f833b28d2c624227ddb16a8b5b6b6aba4c Mon Sep 17 00:00:00 2001 From: nwb Date: Fri, 9 May 2014 15:45:21 +0800 Subject: [PATCH] =?UTF-8?q?1.=E9=A1=B9=E7=9B=AE=E6=B7=BB=E5=8A=A0=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E5=88=86=E7=B1=BB=202.=E4=BF=AE=E6=94=B9=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=96=B0=E5=8F=82=E6=95=B0=203.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 2 +- app/models/attachment.rb | 6 ++++++ app/models/project.rb | 14 +++++++++----- app/views/files/_new.html.erb | 9 +++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) 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 @@

<%=l(:label_attachment_new)%>

<% versions = project.versions.sort %> +<% attachmenttypes = project.attachmenttypes %> <%= error_messages_for 'attachment' %> <%= form_tag(project_files_path(project), :multipart => true, :class => "tabular") do %>
@@ -10,6 +11,14 @@ options_from_collection_for_select(versions, "id", "name") %>

<% end %> + <% if attachmenttypes.any? %> +

+ <%= select_tag "attachment_type", content_tag('option', '') + + options_from_collection_for_select(attachmenttypes, "id", + "typeName") %> +

+ <% end %> +

<%= render :partial => 'attachments/form' %>

<%= submit_tag l(:button_add) %>