diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index 777dec7..f6dc9ea 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -51,8 +51,10 @@ class ContentViewerController < PublicController @comment = Comment.new(params[:comment]) @comment.author = user if logged_in? @comment.article = @page - if @comment.save! + if @comment.save @comment = nil # clear the comment form + else + @form_div = 'opened' end end diff --git a/app/views/content_viewer/_comment_form.rhtml b/app/views/content_viewer/_comment_form.rhtml index 77b1254..56a12c6 100644 --- a/app/views/content_viewer/_comment_form.rhtml +++ b/app/views/content_viewer/_comment_form.rhtml @@ -4,16 +4,20 @@ <% focus_on = logged_in? ? 'title' : 'name' %> +<%= error_messages_for :comment %> + +<% @form_div ||= 'closed' %> +
" + onclick="f=$(<%= comment_form_id %>); this.className = this.className.replace(/closed/,'opened'); f.commit.focus(); f['comment[<%= focus_on %>]'].focus(); this.onclick=null">

<%= _('Post a comment') %>

-<% form_tag( {}, { :id => comment_form_id, :style => 'display:none' } ) do %> +<% form_tag( {}, { :id => comment_form_id } ) do %> <% unless logged_in? %> diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index 965d19a..6b19eba 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -26,6 +26,9 @@ stylesheet_import( "controller_"+ @controller.controller_name(), :themed_source => true ) %> + <%# FIXME: for unknow reason the @import url(.../article.css) above dont work for class .post_comment_box.opened/closed %> + <%= stylesheet_link_tag 'article' %> + <%# FIXME %> <%= stylesheet_link_tag '/designs/templates/default/stylesheets/style.css' %> <%= stylesheet_link_tag '/designs/icons/default/style.css' %> diff --git a/public/stylesheets/article.css b/public/stylesheets/article.css index 800ae36..2c4425c 100644 --- a/public/stylesheets/article.css +++ b/public/stylesheets/article.css @@ -48,3 +48,10 @@ display: none; } +.post_comment_box.closed form { + display: none; +} + +.post_comment_box.opened form { + display: block; +} diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 3456fbe..aff28a2 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -173,4 +173,18 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_tag :tag => 'input', :attributes => { :type => 'text', :name => @controller.icaptcha_field } end + should 'show error messages when make a blank comment' do + login_as @profile.identifier + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') + post :view_page, :profile => @profile.identifier, :page => [ 'myarticle' ], :comment => { :title => '', :body => '' } + assert_tag :tag => 'div', :attributes => { :class => 'errorExplanation', :id => 'errorExplanation' } + end + + should 'show comment form opened on error' do + login_as @profile.identifier + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') + post :view_page, :profile => @profile.identifier, :page => [ 'myarticle' ], :comment => { :title => '', :body => '' } + assert_tag :tag => 'div', :attributes => { :class => 'post_comment_box opened' } + end + end -- libgit2 0.21.2