From 284e6ba20aa295a485502caaac69f8ac4aefc927 Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 13 May 2014 15:49:14 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=95=B0=E6=8D=AE=202.=E4=BF=AE=E6=94=B9=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=B5=84=E6=BA=90=E8=A7=86=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment.rb | 24 +++++++++ app/models/attachmentstype.rb | 7 +++ app/models/project.rb | 8 +++ app/views/files/_show_all_attachment.html.erb | 5 +- app/views/files/_sort_by_attachtypel.html.erb | 5 +- app/views/files/index.html.erb | 46 ++++++++++++----- config/environment.rb | 1 + config/locales/en.yml | 5 +- config/locales/zh.yml | 3 +- .../20140508030039_create_attachmentstypes.rb | 6 +++ db/schema.rb | 50 ++++++++++++++++++- 11 files changed, 142 insertions(+), 18 deletions(-) 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) %>