From: Jean-Philippe Lang Date: Fri, 25 Nov 2011 22:32:07 +0000 (+0000) Subject: Check attachment size when the user selects a file (#9667). X-Git-Tag: 1.3.0~86 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7ed7d8984ddc30a8db5b55d7fdb5f0cdda6c2efb;p=redmine.git Check attachment size when the user selects a file (#9667). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7926 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb index c14c23aef..33990e8ab 100644 --- a/app/views/attachments/_form.html.erb +++ b/app/views/attachments/_form.html.erb @@ -1,6 +1,7 @@ - <%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil, :class => 'file' -%> + <%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil, :class => 'file', + :onchange => "checkFileSize(this, #{Setting.attachment_max_size.to_i.kilobytes}, '#{escape_javascript(l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)))}');" -%> <%= link_to_function(image_tag('delete.png'), 'removeFileField(this)', :title => (l(:button_delete))) %> diff --git a/config/locales/bg.yml b/config/locales/bg.yml index cbbf1fb49..96e6d73e8 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -1003,3 +1003,4 @@ bg: description_date_range_interval: Изберете диапазон чрез задаване на начална и крайна дати description_date_from: Въведете начална дата description_date_to: Въведете крайна дата + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/bs.yml b/config/locales/bs.yml index 1087e1a26..a3df65633 100644 --- a/config/locales/bs.yml +++ b/config/locales/bs.yml @@ -1019,3 +1019,4 @@ bs: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 3737830ff..06db085fc 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -1008,3 +1008,4 @@ ca: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/cs.yml b/config/locales/cs.yml index 6c8dcc924..7de2e2319 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -1009,3 +1009,4 @@ cs: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/da.yml b/config/locales/da.yml index de532a420..00b74fe53 100644 --- a/config/locales/da.yml +++ b/config/locales/da.yml @@ -1022,3 +1022,4 @@ da: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/de.yml b/config/locales/de.yml index 8dcbb686a..ea60e8057 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1026,3 +1026,4 @@ de: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/el.yml b/config/locales/el.yml index 372830b8e..0fe05a101 100644 --- a/config/locales/el.yml +++ b/config/locales/el.yml @@ -1005,3 +1005,4 @@ el: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/en-GB.yml b/config/locales/en-GB.yml index 7c5844dc4..9e437266e 100644 --- a/config/locales/en-GB.yml +++ b/config/locales/en-GB.yml @@ -1008,3 +1008,4 @@ en-GB: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/en.yml b/config/locales/en.yml index a4f366848..953eece04 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -190,6 +190,7 @@ en: error_workflow_copy_target: 'Please select target tracker(s) and role(s)' error_unable_delete_issue_status: 'Unable to delete issue status' error_unable_to_connect: "Unable to connect (%{value})" + error_attachment_too_big: "This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size})" warning_attachments_not_saved: "%{count} file(s) could not be saved." mail_subject_lost_password: "Your %{value} password" diff --git a/config/locales/es.yml b/config/locales/es.yml index 6d0d19c4b..c61bb8f06 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1042,3 +1042,4 @@ es: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/eu.yml b/config/locales/eu.yml index 010379275..7fe7d1aaf 100644 --- a/config/locales/eu.yml +++ b/config/locales/eu.yml @@ -1009,3 +1009,4 @@ eu: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/fa.yml b/config/locales/fa.yml index db4961b72..5b1e5a2b6 100644 --- a/config/locales/fa.yml +++ b/config/locales/fa.yml @@ -1008,3 +1008,4 @@ fa: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/fi.yml b/config/locales/fi.yml index 970c99f6f..89ad07196 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -1026,3 +1026,4 @@ fi: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/fr.yml b/config/locales/fr.yml index bb347ec7e..579e666c9 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -197,6 +197,7 @@ fr: error_workflow_copy_source: 'Veuillez sélectionner un tracker et/ou un rôle source' error_workflow_copy_target: 'Veuillez sélectionner les trackers et rôles cibles' error_issue_done_ratios_not_updated: L'avancement des demandes n'a pas pu être mis à jour. + error_attachment_too_big: Ce fichier ne peut pas être attaché car il excède la taille maximale autorisée (%{max_size}) warning_attachments_not_saved: "%{count} fichier(s) n'ont pas pu être sauvegardés." diff --git a/config/locales/gl.yml b/config/locales/gl.yml index 4f1347563..1d8d280b8 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -1017,3 +1017,4 @@ gl: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/he.yml b/config/locales/he.yml index 22c1c20e9..faf1a0507 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -1010,3 +1010,4 @@ he: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/hr.yml b/config/locales/hr.yml index a90cd6b4d..8ddd13e96 100644 --- a/config/locales/hr.yml +++ b/config/locales/hr.yml @@ -1012,3 +1012,4 @@ hr: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/hu.yml b/config/locales/hu.yml index ec80dac6b..f43e7b0fc 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -1024,3 +1024,4 @@ description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/id.yml b/config/locales/id.yml index 3895f9318..23b92a7cf 100644 --- a/config/locales/id.yml +++ b/config/locales/id.yml @@ -1013,3 +1013,4 @@ id: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/it.yml b/config/locales/it.yml index 61d6ba4c6..6ff2a49e1 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -1006,3 +1006,4 @@ it: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 55958d26c..78bfd7853 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1035,3 +1035,4 @@ ja: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 7ed420999..15e398f02 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -1057,3 +1057,4 @@ ko: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/lt.yml b/config/locales/lt.yml index 7cd3879a2..9c2e8b2ae 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -1065,3 +1065,4 @@ lt: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/lv.yml b/config/locales/lv.yml index 5be9a3f19..18fc69f6d 100644 --- a/config/locales/lv.yml +++ b/config/locales/lv.yml @@ -1000,3 +1000,4 @@ lv: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/mk.yml b/config/locales/mk.yml index b3ff76b9a..5934541c4 100644 --- a/config/locales/mk.yml +++ b/config/locales/mk.yml @@ -1005,3 +1005,4 @@ mk: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/mn.yml b/config/locales/mn.yml index 16128e4ae..577f058be 100644 --- a/config/locales/mn.yml +++ b/config/locales/mn.yml @@ -1006,3 +1006,4 @@ mn: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/nl.yml b/config/locales/nl.yml index f6bb27d16..5fb7848e6 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -987,3 +987,4 @@ nl: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/no.yml b/config/locales/no.yml index 69bf7490b..a5b36bdba 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -995,3 +995,4 @@ description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 4e53459ad..f255c9bfe 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -1022,3 +1022,4 @@ pl: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 1f14651f4..1115fddb1 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -1026,3 +1026,4 @@ pt-BR: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 2ff204dc6..6faa0f193 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -1010,3 +1010,4 @@ pt: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/ro.yml b/config/locales/ro.yml index c430fe3a8..a742c63c6 100644 --- a/config/locales/ro.yml +++ b/config/locales/ro.yml @@ -998,3 +998,4 @@ ro: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 0a15b80e6..f82f58f36 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -1118,3 +1118,4 @@ ru: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/sk.yml b/config/locales/sk.yml index 628812d12..00922f02e 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -1000,3 +1000,4 @@ sk: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 0b4f060cb..518db6d3a 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -1005,3 +1005,4 @@ sl: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/sr-YU.yml b/config/locales/sr-YU.yml index 662ef51eb..c3e05e810 100644 --- a/config/locales/sr-YU.yml +++ b/config/locales/sr-YU.yml @@ -1005,3 +1005,4 @@ sr-YU: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/sr.yml b/config/locales/sr.yml index 390f24e2e..2c9b0b3d0 100644 --- a/config/locales/sr.yml +++ b/config/locales/sr.yml @@ -1006,3 +1006,4 @@ sr: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/sv.yml b/config/locales/sv.yml index 841da7b15..ebd1c3622 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -1046,3 +1046,4 @@ sv: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/th.yml b/config/locales/th.yml index c625e68bd..70468d497 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -1002,3 +1002,4 @@ th: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/tr.yml b/config/locales/tr.yml index 1bde02b64..e167eb4c5 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -1024,3 +1024,4 @@ tr: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/uk.yml b/config/locales/uk.yml index 3f2643485..81d049899 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -1001,3 +1001,4 @@ uk: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/vi.yml b/config/locales/vi.yml index d766a69e6..fb0a9fb68 100644 --- a/config/locales/vi.yml +++ b/config/locales/vi.yml @@ -1056,3 +1056,4 @@ vi: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index e0e612c6c..ff62b32a0 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -1085,3 +1085,4 @@ description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 410dc84a9..0a9c57fa3 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1007,3 +1007,4 @@ zh: description_all_columns: All Columns button_export: Export label_export_options: "%{export_format} export options" + error_attachment_too_big: This file cannot be uploaded because it exceeds the maximum allowed file size (%{max_size}) diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 230e40b5d..aeade1b1c 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -106,6 +106,18 @@ function removeFileField(el) { } } +function checkFileSize(el, maxSize, message) { + var files = el.files; + if (files) { + for (var i=0; i maxSize) { + alert(message); + el.value = ""; + } + } + } +} + function showTab(name) { var f = $$('div#content .tab-content'); for(var i=0; i