diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 169749a..bb7976c 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -357,7 +357,8 @@ class CmsController < MyProfileController 'title' => item.title, 'url' => item.image? ? item.public_filename(:uploaded) : url_for(item.url), :icon => icon_for_article(item), - :content_type => item.mime_type + :content_type => item.mime_type, + :error => item.errors.any? ? _('%s could not be uploaded') % item.title : nil, } end.to_json end diff --git a/public/javascripts/article.js b/public/javascripts/article.js index 8a761d3..85ba0a1 100644 --- a/public/javascripts/article.js +++ b/public/javascripts/article.js @@ -26,6 +26,10 @@ jQuery(function($) { function insert_items(items, selector) { var html_for_items = ''; $.each(items, function(i, item) { + if (item.error) { + html_for_items += '
  • ' + item.error + '
  • '; + return; + } if (item.content_type && item.content_type.match(/^image/)) { html_for_items += '

  • ' + item.title + '
  • '; } else { diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index a246e95..a9e49ee 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -3406,6 +3406,9 @@ div.with_media_panel .formfield input { max-width: 96px; border: 1px solid #d3d7cf; } +.text-editor-sidebar .media-upload-error { + color: red; +} /* ==> public/stylesheets/controller_contact.css <== */ /*** SELECT CITY ***/ diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 4db6977..e74371e 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1486,7 +1486,7 @@ class CmsControllerTest < Test::Unit::TestCase assert_match /test.txt/, @response.body assert_equal 'application/json', @response.content_type - data = eval(@response.body.gsub('":', '"=>')) + data = parse_json_response assert_equal 'test.txt', data.first['title'] assert_match /\/testinguser\/test.txt$/, data.first['url'] assert_match /text/, data.first['icon'] @@ -1498,17 +1498,19 @@ class CmsControllerTest < Test::Unit::TestCase assert_match 'test.txt', @response.body assert_equal 'application/json', @response.content_type - data = eval(@response.body.gsub('":', '"=>')) + data = parse_json_response assert_equal 'test.txt', data[0]['title'] assert_match /\/testinguser\/test.txt$/, data[0]['url'] assert_match /text/, data[0]['icon'] assert_match /text/, data[0]['content_type'] + assert_nil data[0]['error'] assert_equal 'rails.png', data[1]['title'] assert_no_match /\/public\/articles\/.*\/rails.png$/, data[1]['url'] assert_match /png$/, data[1]['icon'] assert_match /image/, data[1]['content_type'] + assert_nil data[1]['error'] end @@ -1516,4 +1518,29 @@ class CmsControllerTest < Test::Unit::TestCase post :media_upload, :profile => @profile.identifier end + should 'mark unsuccessfull uploads' do + file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('files/rails.png', 'image/png')) + + post :media_upload, :profile => profile.identifier, :media_listing => true, :file1 => fixture_file_upload('files/rails.png', 'image/png'), :file2 => fixture_file_upload('/files/test.txt', 'text/plain') + + assert_equal 'application/json', @response.content_type + data = parse_json_response + + assert_equal 'rails.png', data[0]['title'] + assert_not_nil data[0]['error'] + assert_match /rails.png/, data[0]['error'] + + assert_equal 'test.txt', data[1]['title'] + assert_nil data[1]['error'] + end + + protected + + # FIXME this is to avoid adding an extra dependency for a proper JSON parser. + # For now we are assuming that the JSON is close enough to Ruby and just + # making some adjustments. + def parse_json_response + eval(@response.body.gsub('":', '"=>').gsub('null', 'nil')) + end + end -- libgit2 0.21.2