diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 6a62613b..3bfd705f 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -66,6 +66,30 @@ class Attachment < ActiveRecord::Base copy end + #获取资源的后缀类型 + def suffix_type + childArr = self.filename.split('.') + suffix = '*' + if childArr.length > 1 + suffix = childArr[childArr.length-1] + end + suffix + end + + #获取用来显示的后缀名称 + def show_suffix_type + suffix = 'other' + temp = self.suffix_type.downcase + if self.attachmentstype.suffixArr.include?(temp) + suffix = temp + end + suffix + end + + def suffixArr + @@SuffixArr + end + def validate_max_file_size if @temp_file && self.filesize > Setting.attachment_max_size.to_i.kilobytes errors.add(:base, l(:error_attachment_too_big, :max_size => Setting.attachment_max_size.to_i.kilobytes)) diff --git a/app/models/attachmentstype.rb b/app/models/attachmentstype.rb index 54102ee7..6a37cc51 100644 --- a/app/models/attachmentstype.rb +++ b/app/models/attachmentstype.rb @@ -1,4 +1,11 @@ class Attachmentstype < ActiveRecord::Base attr_accessible :typeId, :typeName has_many :attachments, :foreign_key => "attachtype",:primary_key => "id" + + # 当前使用的文件内容分类列表 + @@SuffixArr = ['pdf','zip','doc','docx','rar','txt','jpg','bmp','xls','xlsx'] + + def suffixArr + @@SuffixArr + end end diff --git a/app/models/project.rb b/app/models/project.rb index 007f7e30..3c2956a9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -164,6 +164,14 @@ class Project < ActiveRecord::Base @attachmenttypes = Attachmentstype.find(:all, :conditions => ["#{Attachmentstype.table_name}.typeId= ?",self.attachmenttype ]) end + # 获取资源后缀名列表 + def contenttypes + attachmenttypes + if @attachmenttypes.length >0 + @attachmenttypes.last().suffixArr + end + end + #自定义验证 def validation if !class_period.match([0-9]) diff --git a/app/views/files/_show_all_attachment.html.erb b/app/views/files/_show_all_attachment.html.erb index c65f58cc..57ac897d 100644 --- a/app/views/files/_show_all_attachment.html.erb +++ b/app/views/files/_show_all_attachment.html.erb @@ -1,4 +1,5 @@ <% delete_allowed = User.current.allowed_to?(:manage_files, @project) %> +<% edit_allowed = User.current.allowed_to?(:manage_files, @project) %>