From 720c75478a1912f3779ab62103a4f534efe617df Mon Sep 17 00:00:00 2001 From: z9hang Date: Thu, 10 Jul 2014 10:15:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=8A=E4=BC=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=8F=AF=E4=BC=A0=E9=9D=9E=E5=9B=BE=E7=89=87=E6=96=87?= =?UTF-8?q?=E4=BB=B6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/avatar/_avatar_form.html.erb | 3 +++ config/configuration.yml | 1 + config/locales/zh.yml | 1 + lib/redmine/configuration.rb | 3 ++- public/javascripts/avatars.js | 26 +++++++++++++++++++++++++- 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/views/avatar/_avatar_form.html.erb b/app/views/avatar/_avatar_form.html.erb index 272397c62..a880f32aa 100644 --- a/app/views/avatar/_avatar_form.html.erb +++ b/app/views/avatar/_avatar_form.html.erb @@ -45,6 +45,7 @@ <%= l(:button_upload_photo) %> + <%= file_field_tag 'avatar[image]', :id => nil, @@ -57,6 +58,8 @@ :max_file_size => Setting.attachment_max_size.to_i.kilobytes, :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, + :file_type => Redmine::Configuration['pic_types'].to_s, + :type_support_message => l(:error_pic_type), :upload_path => upload_avatar_path(:format => 'js'), :description_placeholder => nil ,# l(:label_optional_description) :source_type => source.class.to_s, diff --git a/config/configuration.yml b/config/configuration.yml index a98ea3391..4bdd279aa 100644 --- a/config/configuration.yml +++ b/config/configuration.yml @@ -199,6 +199,7 @@ default: # Maximum number of simultaneous AJAX uploads #max_concurrent_ajax_uploads: 2 + #pic_types: "bmp,jpeg,jpg,png,gif" # specific configuration options for production environment # that overrides the default ones diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 1b3774d65..716889bbc 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1217,6 +1217,7 @@ zh: button_export: 导出 label_export_options: "%{export_format} 导出选项" error_attachment_too_big: 该文件无法上传。超过文件大小限制 (%{max_size}) + error_pic_type: "仅支持如下图片格式:" notice_failed_to_save_time_entries: "无法保存下列所选取的 %{total} 个项目中的 %{count} 工时: %{ids}。" label_x_issues: zero: 0 问题 diff --git a/lib/redmine/configuration.rb b/lib/redmine/configuration.rb index 6723b777e..ba8e91294 100644 --- a/lib/redmine/configuration.rb +++ b/lib/redmine/configuration.rb @@ -21,7 +21,8 @@ module Redmine # Configuration default values @defaults = { 'email_delivery' => nil, - 'max_concurrent_ajax_uploads' => 2 + 'max_concurrent_ajax_uploads' => 2, + 'pic_types' => "bmp,jpeg,jpg,png,gif" } @config = nil diff --git a/public/javascripts/avatars.js b/public/javascripts/avatars.js index 24bc1ee1c..db9a2255e 100644 --- a/public/javascripts/avatars.js +++ b/public/javascripts/avatars.js @@ -140,10 +140,34 @@ function uploadAndAttachFiles(files, inputEl) { if (sizeExceeded) { window.alert(maxFileSizeExceeded); } else { - $.each(files, function() {addFile(inputEl, this, true);}); + uploadAndTypeFiles(files,inputEl); + //$.each(files, function() {addFile(inputEl, this, true);}); } } +function uploadAndTypeFiles(files, inputEl) { + + var enableType = $(inputEl).data('file-type'); + var typeSupportrdMessage = $(inputEl).data('type-support-message'); + if (enableType == null || enableType.trim() == "") + { + $.each(files, function() {addFile(inputEl, this, true);}); + return; + } + var typeSupported = false; + $.each(files, function() { + var a = this.name.split('.'); + var type = a[a.length-1]; + var rs = enableType.indexOf(type); + if(rs >= 0) {typeSupported = true } + }); + if (typeSupported) { + $.each(files, function() {addFile(inputEl, this, true);}); + } else { + window.alert(typeSupportrdMessage + enableType); + } +} + function handleFileDropEvent(e) { $(this).removeClass('fileover');