Commit 619178e31e0aa7ccb14ee46f5fd96d226e5a5102

Authored by Leandro Nunes dos Santos
2 parents 254da568 59c7467a

Merge branch 'ActionItem2562' into ActionItem2520

app/controllers/public/comment_controller.rb
@@ -154,7 +154,7 @@ class CommentController < ApplicationController @@ -154,7 +154,7 @@ class CommentController < ApplicationController
154 render :json => { 154 render :json => {
155 :ok => false, 155 :ok => false,
156 :render_target => 'form', 156 :render_target => 'form',
157 - :html => render_to_string(:partial => 'comment_form', :object => @comment, :locals => {:comment => @comment, :display_link => false, :edition_mode => true}) 157 + :html => render_to_string(:partial => 'comment_form', :object => @comment, :locals => {:comment => @comment, :display_link => false, :edition_mode => true, :show_form => true})
158 } 158 }
159 end 159 end
160 end 160 end
app/views/comment/_comment_form.rhtml
@@ -10,8 +10,8 @@ @@ -10,8 +10,8 @@
10 if (d.hasClass('closed')) { 10 if (d.hasClass('closed')) {
11 d.removeClass('closed'); 11 d.removeClass('closed');
12 d.addClass('opened'); 12 d.addClass('opened');
13 - d.find('input[name=comment[title]], textarea').val('');  
14 - d.find('.comment_form input[name=comment[<%= focus_on %>]]').focus(); 13 + d.find('input[name=\'comment[title]\'], textarea').val('');
  14 + d.find('.comment_form input[name=\'comment[<%= focus_on %>]\']').focus();
15 }"> 15 }">
16 <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %> 16 <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %>
17 </h4> 17 </h4>
@@ -61,10 +61,7 @@ function check_captcha(button, confirm_action) { @@ -61,10 +61,7 @@ function check_captcha(button, confirm_action) {
61 61
62 <% remote_form_for(:comment, comment, :url => {:profile => profile.identifier, :controller => 'comment', :action => (edition_mode ? 'update' : 'create'), :id => (edition_mode ? comment.id : @page.id)}, :html => { :class => 'comment_form' } ) do |f| %> 62 <% remote_form_for(:comment, comment, :url => {:profile => profile.identifier, :controller => 'comment', :action => (edition_mode ? 'update' : 'create'), :id => (edition_mode ? comment.id : @page.id)}, :html => { :class => 'comment_form' } ) do |f| %>
63 63
64 - <% if comment && comment.errors.any? %>  
65 - <%= error_messages_for :comment %>  
66 - <script type="text/javascript">jQuery(function() { document.location.href = "<%= comment.reply_of_id.nil? ? '#page-comment-form' : '#comment-' + comment.reply_of_id.to_s %>"; });</script>  
67 - <% end %> 64 + <%= error_messages_for :comment %>
68 65
69 <%= hidden_field_tag(:confirm, 'false') %> 66 <%= hidden_field_tag(:confirm, 'false') %>
70 67
plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb
@@ -27,7 +27,7 @@ class RequireAuthToCommentPlugin &lt; Noosfero::Plugin @@ -27,7 +27,7 @@ class RequireAuthToCommentPlugin &lt; Noosfero::Plugin
27 end 27 end
28 28
29 def js_files 29 def js_files
30 - ['hide_comment_form.js'] 30 + ['hide_comment_form.js', 'jquery.livequery.min.js']
31 end 31 end
32 32
33 def body_beginning 33 def body_beginning
plugins/require_auth_to_comment/public/hide_comment_form.js
1 (function($) { 1 (function($) {
2 $(window).bind('userDataLoaded', function(event, data) { 2 $(window).bind('userDataLoaded', function(event, data) {
3 if (data.login || $('meta[name=profile.allow_unauthenticated_comments]').length > 0) { 3 if (data.login || $('meta[name=profile.allow_unauthenticated_comments]').length > 0) {
4 - $('.post-comment-button').show();  
5 - $('#page-comment-form').show();  
6 - $('.comment-footer').show(); 4 + $('.post-comment-button').livequery(function() {
  5 + $(this).show();
  6 + });
  7 + $('.page-comment-form').livequery(function() {
  8 + $(this).show();
  9 + });
  10 + $('.comment-footer').livequery(function() {
  11 + $(this).show();
  12 + });
7 } 13 }
8 }); 14 });
9 })(jQuery); 15 })(jQuery);
plugins/require_auth_to_comment/public/style.css
1 -.post-comment-button, #page-comment-form, .comment-footer { 1 +.post-comment-button, .page-comment-form, .comment-footer {
2 display: none; 2 display: none;
3 } 3 }
public/javascripts/application.js
@@ -752,7 +752,9 @@ function save_comment(button) { @@ -752,7 +752,9 @@ function save_comment(button) {
752 752
753 } else if(data.render_target == 'form') { 753 } else if(data.render_target == 'form') {
754 //Comment with errors 754 //Comment with errors
755 - $(button).parents('.page-comment-form').html(data.html); 755 + var page_comment_form = $(button).parents('.page-comment-form');
  756 + $.scrollTo(page_comment_form);
  757 + page_comment_form.html(data.html);
756 758
757 } else if($('#' + data.render_target).size() > 0) { 759 } else if($('#' + data.render_target).size() > 0) {
758 //Comment of reply 760 //Comment of reply
@@ -768,6 +770,7 @@ function save_comment(button) { @@ -768,6 +770,7 @@ function save_comment(button) {
768 }); 770 });
769 771
770 form.find('.errorExplanation').remove(); 772 form.find('.errorExplanation').remove();
  773 + $.colorbox.close();
771 774
772 } 775 }
773 776
@@ -784,7 +787,6 @@ function save_comment(button) { @@ -784,7 +787,6 @@ function save_comment(button) {
784 display_notice(data.msg); 787 display_notice(data.msg);
785 } 788 }
786 789
787 - $.colorbox.close();  
788 close_loading(); 790 close_loading();
789 post_comment_box.removeClass('opened'); 791 post_comment_box.removeClass('opened');
790 post_comment_box.addClass('closed'); 792 post_comment_box.addClass('closed');