Commit bff5794ad3ab600c22cc295416b65e0229e1073a
1 parent
1ed7d9c3
Exists in
master
and in
29 other branches
fixing comment creation/reply bugs
Showing
3 changed files
with
46 additions
and
27 deletions
Show diff stats
app/views/comment/_comment_form.rhtml
@@ -3,9 +3,6 @@ | @@ -3,9 +3,6 @@ | ||
3 | 3 | ||
4 | <% focus_on = logged_in? ? 'title' : 'name' %> | 4 | <% focus_on = logged_in? ? 'title' : 'name' %> |
5 | 5 | ||
6 | -<div class="post_comment_box <%= ((defined? show_form) && show_form) ? 'opened' : 'closed' %>"> | ||
7 | - | ||
8 | -<%= link_to(_('Post a comment'), '#', :class => 'display-comment-form') if display_link %> | ||
9 | 6 | ||
10 | <% if !edition_mode && !pass_without_comment_captcha? %> | 7 | <% if !edition_mode && !pass_without_comment_captcha? %> |
11 | <div id="recaptcha-container" style="display: none"> | 8 | <div id="recaptcha-container" style="display: none"> |
@@ -49,11 +46,17 @@ function check_captcha(button, confirm_action) { | @@ -49,11 +46,17 @@ function check_captcha(button, confirm_action) { | ||
49 | } | 46 | } |
50 | </script> | 47 | </script> |
51 | 48 | ||
52 | -<% 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| %> | ||
53 | - | 49 | +<% if @comment && @comment.errors.any? %> |
54 | <%= error_messages_for :comment %> | 50 | <%= error_messages_for :comment %> |
51 | + <script type="text/javascript">jQuery(function() { document.location.href = '#page-comment-form'; });</script> | ||
52 | +<% end %> | ||
55 | 53 | ||
56 | - <%= hidden_field_tag(:confirm, 'false') %> | 54 | +<% @form_div ||= 'closed' %> |
55 | + | ||
56 | +<div class="post_comment_box <%= ((defined? show_form) && show_form) ? 'opened' : 'closed' %> <%= @form_div %>"> | ||
57 | + | ||
58 | + <%= link_to(_('Post a comment'), '#', :class => 'display-comment-form') if display_link && @comment.reply_of_id.blank? %> | ||
59 | +<% 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| %> | ||
57 | 60 | ||
58 | <%= required_fields_message %> | 61 | <%= required_fields_message %> |
59 | 62 | ||
@@ -74,13 +77,18 @@ function check_captcha(button, confirm_action) { | @@ -74,13 +77,18 @@ function check_captcha(button, confirm_action) { | ||
74 | 77 | ||
75 | <%= labelled_form_field(_('Title'), f.text_field(:title)) %> | 78 | <%= labelled_form_field(_('Title'), f.text_field(:title)) %> |
76 | <%= required labelled_form_field(_('Enter your comment'), f.text_area(:body, :rows => 5)) %> | 79 | <%= required labelled_form_field(_('Enter your comment'), f.text_area(:body, :rows => 5)) %> |
80 | + | ||
81 | + <%= hidden_field_tag(:confirm, 'false') %> | ||
82 | + <%= hidden_field_tag(:view, params[:view])%> | ||
77 | <%= f.hidden_field(:reply_of_id) %> | 83 | <%= f.hidden_field(:reply_of_id) %> |
78 | 84 | ||
79 | <% button_bar do %> | 85 | <% button_bar do %> |
80 | - <%= submit_button('add', _('Post comment'), :onclick => "if(check_captcha(this)) { save_comment(this) } else { check_captcha(this, save_comment)};return false;") %> | ||
81 | - <% if !edition_mode %> | ||
82 | - <%= button :cancel, _('Cancel'), '', :id => 'cancel-comment' %> | ||
83 | - <% end %> | 86 | + <%= submit_button('add', _('Post comment'), :onclick => "if(check_captcha(this)) { save_comment(this) } else { check_captcha(this, save_comment)};return false;") %> |
87 | + <% if !edition_mode %> | ||
88 | + <%= button :cancel, _('Cancel'), '', :id => 'cancel-comment' %> | ||
89 | + <% else %> | ||
90 | + <%= button :cancel, _('Cancel'), '#', :onclick => "jQuery.colorbox.close();" %> | ||
91 | + <% end %> | ||
84 | <% end %> | 92 | <% end %> |
85 | <% end %> | 93 | <% end %> |
86 | 94 |
public/javascripts/application.js
@@ -718,14 +718,15 @@ function add_comment_reply_form(button, comment_id) { | @@ -718,14 +718,15 @@ function add_comment_reply_form(button, comment_id) { | ||
718 | f = comments_div.find('.comment_form').first().clone(); | 718 | f = comments_div.find('.comment_form').first().clone(); |
719 | f.find('.errorExplanation').remove(); | 719 | f.find('.errorExplanation').remove(); |
720 | f.append('<input type="hidden" name="comment[reply_of_id]" value="' + comment_id + '" />'); | 720 | f.append('<input type="hidden" name="comment[reply_of_id]" value="' + comment_id + '" />'); |
721 | - container.append(f); | 721 | + container.append('<div class="page-comment-form"></div>'); |
722 | + container.find('.page-comment-form').append(f); | ||
722 | } | 723 | } |
723 | if (container.hasClass('closed')) { | 724 | if (container.hasClass('closed')) { |
724 | container.removeClass('closed'); | 725 | container.removeClass('closed'); |
725 | container.addClass('opened'); | 726 | container.addClass('opened'); |
726 | container.find('.comment_form input[type=text]:visible:first').focus(); | 727 | container.find('.comment_form input[type=text]:visible:first').focus(); |
727 | } | 728 | } |
728 | - container.addClass('page-comment-form'); | 729 | + jQuery('.display-comment-form').hide(); |
729 | return f; | 730 | return f; |
730 | } | 731 | } |
731 | 732 |
public/javascripts/comment_form.js
1 | +jQuery('.display-comment-form').unbind(); | ||
1 | jQuery('.display-comment-form').click(function(){ | 2 | jQuery('.display-comment-form').click(function(){ |
2 | - toggleBox(jQuery(this).parents('.post_comment_box')); | 3 | + var $button = jQuery(this); |
4 | + toggleBox($button.parents('.post_comment_box')); | ||
3 | jQuery('.display-comment-form').hide(); | 5 | jQuery('.display-comment-form').hide(); |
4 | - jQuery('form.comment_form input').first().focus(); | 6 | + $button.closest('.page-comment-form').find('input').first().focus(); |
5 | return false; | 7 | return false; |
6 | }); | 8 | }); |
7 | 9 | ||
10 | +jQuery('#cancel-comment').die(); | ||
8 | jQuery('#cancel-comment').live("click", function(){ | 11 | jQuery('#cancel-comment').live("click", function(){ |
9 | - toggleBox(jQuery(this).parents('.post_comment_box')); | ||
10 | - jQuery('.display-comment-form').show(); | 12 | + var $button = jQuery(this); |
13 | + toggleBox($button.parents('.post_comment_box')); | ||
14 | + show_display_comment_button(); | ||
15 | + var page_comment_form = $button.parents('.page-comment-form'); | ||
16 | + page_comment_form.find('.errorExplanation').remove(); | ||
11 | return false; | 17 | return false; |
12 | -}) | 18 | +}); |
13 | 19 | ||
14 | function toggleBox(div){ | 20 | function toggleBox(div){ |
15 | if(div.hasClass('opened')) { | 21 | if(div.hasClass('opened')) { |
@@ -25,9 +31,10 @@ function save_comment(button) { | @@ -25,9 +31,10 @@ function save_comment(button) { | ||
25 | var $ = jQuery; | 31 | var $ = jQuery; |
26 | open_loading(DEFAULT_LOADING_MESSAGE); | 32 | open_loading(DEFAULT_LOADING_MESSAGE); |
27 | var $button = $(button); | 33 | var $button = $(button); |
28 | - var form = $(button).parents("form"); | ||
29 | - var post_comment_box = $(button).parents('.post_comment_box'); | 34 | + var form = $button.parents("form"); |
35 | + var post_comment_box = $button.parents('.post_comment_box'); | ||
30 | var comment_div = $button.parents('.comments'); | 36 | var comment_div = $button.parents('.comments'); |
37 | + var page_comment_form = $button.parents('.page-comment-form'); | ||
31 | $button.addClass('comment-button-loading'); | 38 | $button.addClass('comment-button-loading'); |
32 | $.post(form.attr("action"), form.serialize(), function(data) { | 39 | $.post(form.attr("action"), form.serialize(), function(data) { |
33 | 40 | ||
@@ -36,20 +43,19 @@ function save_comment(button) { | @@ -36,20 +43,19 @@ function save_comment(button) { | ||
36 | form.find("input[type='text']").add('textarea').each(function() { | 43 | form.find("input[type='text']").add('textarea').each(function() { |
37 | this.value = ''; | 44 | this.value = ''; |
38 | }); | 45 | }); |
39 | - form.find('.errorExplanation').remove(); | ||
40 | - | 46 | + page_comment_form.find('.errorExplanation').remove(); |
47 | + show_display_comment_button(); | ||
41 | } else if(data.render_target == 'form') { | 48 | } else if(data.render_target == 'form') { |
42 | //Comment with errors | 49 | //Comment with errors |
43 | - var page_comment_form = $(button).parents('.page-comment-form'); | ||
44 | $.scrollTo(page_comment_form); | 50 | $.scrollTo(page_comment_form); |
45 | page_comment_form.html(data.html); | 51 | page_comment_form.html(data.html); |
46 | - | 52 | + $('.display-comment-form').hide(); |
47 | } else if($('#' + data.render_target).size() > 0) { | 53 | } else if($('#' + data.render_target).size() > 0) { |
48 | //Comment of reply | 54 | //Comment of reply |
49 | $('#'+ data.render_target).replaceWith(data.html); | 55 | $('#'+ data.render_target).replaceWith(data.html); |
50 | $('#' + data.render_target).effect("highlight", {}, 3000); | 56 | $('#' + data.render_target).effect("highlight", {}, 3000); |
51 | $.colorbox.close(); | 57 | $.colorbox.close(); |
52 | - | 58 | + show_display_comment_button(); |
53 | } else { | 59 | } else { |
54 | //New comment of article | 60 | //New comment of article |
55 | comment_div.find('.article-comments-list').append(data.html); | 61 | comment_div.find('.article-comments-list').append(data.html); |
@@ -58,9 +64,9 @@ function save_comment(button) { | @@ -58,9 +64,9 @@ function save_comment(button) { | ||
58 | this.value = ''; | 64 | this.value = ''; |
59 | }); | 65 | }); |
60 | 66 | ||
61 | - form.find('.errorExplanation').remove(); | 67 | + page_comment_form.find('.errorExplanation').remove(); |
62 | $.colorbox.close(); | 68 | $.colorbox.close(); |
63 | - | 69 | + show_display_comment_button(); |
64 | } | 70 | } |
65 | 71 | ||
66 | comment_div.find('.comment-count').add('#article-header .comment-count').each(function() { | 72 | comment_div.find('.comment-count').add('#article-header .comment-count').each(function() { |
@@ -78,8 +84,12 @@ function save_comment(button) { | @@ -78,8 +84,12 @@ function save_comment(button) { | ||
78 | 84 | ||
79 | close_loading(); | 85 | close_loading(); |
80 | toggleBox($button.closest('.post_comment_box')); | 86 | toggleBox($button.closest('.post_comment_box')); |
81 | - $('.display-comment-form').show(); | ||
82 | $button.removeClass('comment-button-loading'); | 87 | $button.removeClass('comment-button-loading'); |
83 | $button.enable(); | 88 | $button.enable(); |
84 | }, 'json'); | 89 | }, 'json'); |
85 | } | 90 | } |
91 | + | ||
92 | +function show_display_comment_button() { | ||
93 | + if(jQuery('.post_comment_box.opened').length==0) | ||
94 | + jQuery('.display-comment-form').show(); | ||
95 | +} |