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 | 3 | |
4 | 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 | 7 | <% if !edition_mode && !pass_without_comment_captcha? %> |
11 | 8 | <div id="recaptcha-container" style="display: none"> |
... | ... | @@ -49,11 +46,17 @@ function check_captcha(button, confirm_action) { |
49 | 46 | } |
50 | 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 | 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 | 61 | <%= required_fields_message %> |
59 | 62 | |
... | ... | @@ -74,13 +77,18 @@ function check_captcha(button, confirm_action) { |
74 | 77 | |
75 | 78 | <%= labelled_form_field(_('Title'), f.text_field(:title)) %> |
76 | 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 | 83 | <%= f.hidden_field(:reply_of_id) %> |
78 | 84 | |
79 | 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 | 92 | <% end %> |
85 | 93 | <% end %> |
86 | 94 | ... | ... |
public/javascripts/application.js
... | ... | @@ -718,14 +718,15 @@ function add_comment_reply_form(button, comment_id) { |
718 | 718 | f = comments_div.find('.comment_form').first().clone(); |
719 | 719 | f.find('.errorExplanation').remove(); |
720 | 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 | 724 | if (container.hasClass('closed')) { |
724 | 725 | container.removeClass('closed'); |
725 | 726 | container.addClass('opened'); |
726 | 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 | 730 | return f; |
730 | 731 | } |
731 | 732 | ... | ... |
public/javascripts/comment_form.js
1 | +jQuery('.display-comment-form').unbind(); | |
1 | 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 | 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 | 7 | return false; |
6 | 8 | }); |
7 | 9 | |
10 | +jQuery('#cancel-comment').die(); | |
8 | 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 | 17 | return false; |
12 | -}) | |
18 | +}); | |
13 | 19 | |
14 | 20 | function toggleBox(div){ |
15 | 21 | if(div.hasClass('opened')) { |
... | ... | @@ -25,9 +31,10 @@ function save_comment(button) { |
25 | 31 | var $ = jQuery; |
26 | 32 | open_loading(DEFAULT_LOADING_MESSAGE); |
27 | 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 | 36 | var comment_div = $button.parents('.comments'); |
37 | + var page_comment_form = $button.parents('.page-comment-form'); | |
31 | 38 | $button.addClass('comment-button-loading'); |
32 | 39 | $.post(form.attr("action"), form.serialize(), function(data) { |
33 | 40 | |
... | ... | @@ -36,20 +43,19 @@ function save_comment(button) { |
36 | 43 | form.find("input[type='text']").add('textarea').each(function() { |
37 | 44 | this.value = ''; |
38 | 45 | }); |
39 | - form.find('.errorExplanation').remove(); | |
40 | - | |
46 | + page_comment_form.find('.errorExplanation').remove(); | |
47 | + show_display_comment_button(); | |
41 | 48 | } else if(data.render_target == 'form') { |
42 | 49 | //Comment with errors |
43 | - var page_comment_form = $(button).parents('.page-comment-form'); | |
44 | 50 | $.scrollTo(page_comment_form); |
45 | 51 | page_comment_form.html(data.html); |
46 | - | |
52 | + $('.display-comment-form').hide(); | |
47 | 53 | } else if($('#' + data.render_target).size() > 0) { |
48 | 54 | //Comment of reply |
49 | 55 | $('#'+ data.render_target).replaceWith(data.html); |
50 | 56 | $('#' + data.render_target).effect("highlight", {}, 3000); |
51 | 57 | $.colorbox.close(); |
52 | - | |
58 | + show_display_comment_button(); | |
53 | 59 | } else { |
54 | 60 | //New comment of article |
55 | 61 | comment_div.find('.article-comments-list').append(data.html); |
... | ... | @@ -58,9 +64,9 @@ function save_comment(button) { |
58 | 64 | this.value = ''; |
59 | 65 | }); |
60 | 66 | |
61 | - form.find('.errorExplanation').remove(); | |
67 | + page_comment_form.find('.errorExplanation').remove(); | |
62 | 68 | $.colorbox.close(); |
63 | - | |
69 | + show_display_comment_button(); | |
64 | 70 | } |
65 | 71 | |
66 | 72 | comment_div.find('.comment-count').add('#article-header .comment-count').each(function() { |
... | ... | @@ -78,8 +84,12 @@ function save_comment(button) { |
78 | 84 | |
79 | 85 | close_loading(); |
80 | 86 | toggleBox($button.closest('.post_comment_box')); |
81 | - $('.display-comment-form').show(); | |
82 | 87 | $button.removeClass('comment-button-loading'); |
83 | 88 | $button.enable(); |
84 | 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 | +} | ... | ... |