修正上传图片可传非图片文件bug

This commit is contained in:
z9hang 2014-07-10 10:15:20 +08:00
parent 4d75fbfcb8
commit 720c75478a
5 changed files with 32 additions and 2 deletions

View File

@ -45,6 +45,7 @@
<a href="javascript:void(0);" class="btn_addPic" style="text-decoration:none;">
<span><%= l(:button_upload_photo) %></span>
</a>
<!-- :accept => 'image/png,image/gif,image/jpeg', -->
<span class="add_avatar" style="margin-left: -55px;width: 70px">
<%= 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,

View File

@ -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

View File

@ -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 问题

View File

@ -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

View File

@ -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');