Commit 1ed7d9c38fa74dbb38c61eedc1fcd6b00a1b3a4f
1 parent
8f42e790
Exists in
master
and in
29 other branches
fixing creation of comment
Showing
4 changed files
with
75 additions
and
82 deletions
Show diff stats
app/views/comment/_comment_form.rhtml
@@ -5,17 +5,7 @@ | @@ -5,17 +5,7 @@ | ||
5 | 5 | ||
6 | <div class="post_comment_box <%= ((defined? show_form) && show_form) ? 'opened' : 'closed' %>"> | 6 | <div class="post_comment_box <%= ((defined? show_form) && show_form) ? 'opened' : 'closed' %>"> |
7 | 7 | ||
8 | -<% if display_link %> | ||
9 | - <h4 onclick="var d = jQuery(this).parent('.post_comment_box'); | ||
10 | - if (d.hasClass('closed')) { | ||
11 | - d.removeClass('closed'); | ||
12 | - d.addClass('opened'); | ||
13 | - d.find('input[name=\'comment[title]\'], textarea').val(''); | ||
14 | - d.find('.comment_form input[name=\'comment[<%= focus_on %>]\']').focus(); | ||
15 | - }"> | ||
16 | - <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %> | ||
17 | - </h4> | ||
18 | -<% end %> | 8 | +<%= link_to(_('Post a comment'), '#', :class => 'display-comment-form') if display_link %> |
19 | 9 | ||
20 | <% if !edition_mode && !pass_without_comment_captcha? %> | 10 | <% if !edition_mode && !pass_without_comment_captcha? %> |
21 | <div id="recaptcha-container" style="display: none"> | 11 | <div id="recaptcha-container" style="display: none"> |
@@ -88,10 +78,14 @@ function check_captcha(button, confirm_action) { | @@ -88,10 +78,14 @@ function check_captcha(button, confirm_action) { | ||
88 | 78 | ||
89 | <% button_bar do %> | 79 | <% button_bar do %> |
90 | <%= submit_button('add', _('Post comment'), :onclick => "if(check_captcha(this)) { save_comment(this) } else { check_captcha(this, save_comment)};return false;") %> | 80 | <%= submit_button('add', _('Post comment'), :onclick => "if(check_captcha(this)) { save_comment(this) } else { check_captcha(this, save_comment)};return false;") %> |
91 | - <%= button_to_function :cancel, _('Cancel'), "jQuery.colorbox.close();f=jQuery(this).parents('.post_comment_box'); f.removeClass('opened'); f.addClass('closed'); return false" %> | 81 | + <% if !edition_mode %> |
82 | + <%= button :cancel, _('Cancel'), '', :id => 'cancel-comment' %> | ||
83 | + <% end %> | ||
92 | <% end %> | 84 | <% end %> |
93 | <% end %> | 85 | <% end %> |
94 | 86 | ||
95 | 87 | ||
96 | </div><!-- end class="post_comment_box" --> | 88 | </div><!-- end class="post_comment_box" --> |
97 | </div><!-- end class="page-comment-form" --> | 89 | </div><!-- end class="page-comment-form" --> |
90 | + | ||
91 | +<%= javascript_include_tag 'comment_form'%> |
app/views/content_viewer/view_page.rhtml
@@ -95,7 +95,7 @@ | @@ -95,7 +95,7 @@ | ||
95 | <% end %> | 95 | <% end %> |
96 | 96 | ||
97 | <% if @page.accept_comments? && @comments_count > 1 %> | 97 | <% if @page.accept_comments? && @comments_count > 1 %> |
98 | - <%= link_to(_('Post a comment'), '#', :class => 'display-comment-form', :id => 'top-post-comment-button') %> | 98 | + <%= link_to(_('Post a comment'), '#', :class => 'display-comment-form', :id => 'top-post-comment-button', :onclick => "jQuery('#page-comment-form .display-comment-form').first().click();") %> |
99 | <% end %> | 99 | <% end %> |
100 | 100 | ||
101 | <ul class="article-comments-list"> | 101 | <ul class="article-comments-list"> |
public/javascripts/application.js
@@ -754,69 +754,6 @@ function update_comment_count(element, new_count) { | @@ -754,69 +754,6 @@ function update_comment_count(element, new_count) { | ||
754 | 754 | ||
755 | } | 755 | } |
756 | 756 | ||
757 | -function save_comment(button) { | ||
758 | - var $ = jQuery; | ||
759 | - open_loading(DEFAULT_LOADING_MESSAGE); | ||
760 | - var $button = $(button); | ||
761 | - var form = $(button).parents("form"); | ||
762 | - var post_comment_box = $(button).parents('.post_comment_box'); | ||
763 | - var comment_div = $button.parents('.comments'); | ||
764 | - $button.addClass('comment-button-loading'); | ||
765 | - $.post(form.attr("action"), form.serialize(), function(data) { | ||
766 | - | ||
767 | - if(data.render_target == null) { | ||
768 | - //Comment for approval | ||
769 | - form.find("input[type='text']").add('textarea').each(function() { | ||
770 | - this.value = ''; | ||
771 | - }); | ||
772 | - form.find('.errorExplanation').remove(); | ||
773 | - | ||
774 | - } else if(data.render_target == 'form') { | ||
775 | - //Comment with errors | ||
776 | - var page_comment_form = $(button).parents('.page-comment-form'); | ||
777 | - $.scrollTo(page_comment_form); | ||
778 | - page_comment_form.html(data.html); | ||
779 | - | ||
780 | - } else if($('#' + data.render_target).size() > 0) { | ||
781 | - //Comment of reply | ||
782 | - $('#'+ data.render_target).replaceWith(data.html); | ||
783 | - $('#' + data.render_target).effect("highlight", {}, 3000); | ||
784 | - $.colorbox.close(); | ||
785 | - | ||
786 | - } else { | ||
787 | - //New comment of article | ||
788 | - comment_div.find('.article-comments-list').append(data.html); | ||
789 | - | ||
790 | - form.find("input[type='text']").add('textarea').each(function() { | ||
791 | - this.value = ''; | ||
792 | - }); | ||
793 | - | ||
794 | - form.find('.errorExplanation').remove(); | ||
795 | - $.colorbox.close(); | ||
796 | - | ||
797 | - } | ||
798 | - | ||
799 | - comment_div.find('.comment-count').add('#article-header .comment-count').each(function() { | ||
800 | - var count = parseInt($(this).html()); | ||
801 | - update_comment_count($(this), count + 1); | ||
802 | - }); | ||
803 | - | ||
804 | - if(jQuery('#recaptcha_response_field').val()){ | ||
805 | - Recaptcha.reload(); | ||
806 | - } | ||
807 | - | ||
808 | - if(data.msg != null) { | ||
809 | - display_notice(data.msg); | ||
810 | - } | ||
811 | - | ||
812 | - close_loading(); | ||
813 | - post_comment_box.removeClass('opened'); | ||
814 | - post_comment_box.addClass('closed'); | ||
815 | - $button.removeClass('comment-button-loading'); | ||
816 | - $button.enable(); | ||
817 | - }, 'json'); | ||
818 | -} | ||
819 | - | ||
820 | function remove_comment(button, url, msg) { | 757 | function remove_comment(button, url, msg) { |
821 | var $ = jQuery; | 758 | var $ = jQuery; |
822 | var $button = $(button); | 759 | var $button = $(button); |
public/javascripts/comment_form.js
1 | jQuery('.display-comment-form').click(function(){ | 1 | jQuery('.display-comment-form').click(function(){ |
2 | - toggleBox('.post_comment_box'); | 2 | + toggleBox(jQuery(this).parents('.post_comment_box')); |
3 | jQuery('.display-comment-form').hide(); | 3 | jQuery('.display-comment-form').hide(); |
4 | jQuery('form.comment_form input').first().focus(); | 4 | jQuery('form.comment_form input').first().focus(); |
5 | return false; | 5 | return false; |
6 | }); | 6 | }); |
7 | 7 | ||
8 | -jQuery('#cancel-comment').click(function(){ | ||
9 | - toggleBox('.post_comment_box'); | 8 | +jQuery('#cancel-comment').live("click", function(){ |
9 | + toggleBox(jQuery(this).parents('.post_comment_box')); | ||
10 | jQuery('.display-comment-form').show(); | 10 | jQuery('.display-comment-form').show(); |
11 | - return false | 11 | + return false; |
12 | }) | 12 | }) |
13 | 13 | ||
14 | -function toggleBox(div_selector){ | ||
15 | - div = jQuery(div_selector); | 14 | +function toggleBox(div){ |
16 | if(div.hasClass('opened')) { | 15 | if(div.hasClass('opened')) { |
17 | div.removeClass('opened'); | 16 | div.removeClass('opened'); |
18 | div.addClass('closed'); | 17 | div.addClass('closed'); |
@@ -21,3 +20,66 @@ function toggleBox(div_selector){ | @@ -21,3 +20,66 @@ function toggleBox(div_selector){ | ||
21 | div.addClass('opened'); | 20 | div.addClass('opened'); |
22 | } | 21 | } |
23 | } | 22 | } |
23 | + | ||
24 | +function save_comment(button) { | ||
25 | + var $ = jQuery; | ||
26 | + open_loading(DEFAULT_LOADING_MESSAGE); | ||
27 | + var $button = $(button); | ||
28 | + var form = $(button).parents("form"); | ||
29 | + var post_comment_box = $(button).parents('.post_comment_box'); | ||
30 | + var comment_div = $button.parents('.comments'); | ||
31 | + $button.addClass('comment-button-loading'); | ||
32 | + $.post(form.attr("action"), form.serialize(), function(data) { | ||
33 | + | ||
34 | + if(data.render_target == null) { | ||
35 | + //Comment for approval | ||
36 | + form.find("input[type='text']").add('textarea').each(function() { | ||
37 | + this.value = ''; | ||
38 | + }); | ||
39 | + form.find('.errorExplanation').remove(); | ||
40 | + | ||
41 | + } else if(data.render_target == 'form') { | ||
42 | + //Comment with errors | ||
43 | + var page_comment_form = $(button).parents('.page-comment-form'); | ||
44 | + $.scrollTo(page_comment_form); | ||
45 | + page_comment_form.html(data.html); | ||
46 | + | ||
47 | + } else if($('#' + data.render_target).size() > 0) { | ||
48 | + //Comment of reply | ||
49 | + $('#'+ data.render_target).replaceWith(data.html); | ||
50 | + $('#' + data.render_target).effect("highlight", {}, 3000); | ||
51 | + $.colorbox.close(); | ||
52 | + | ||
53 | + } else { | ||
54 | + //New comment of article | ||
55 | + comment_div.find('.article-comments-list').append(data.html); | ||
56 | + | ||
57 | + form.find("input[type='text']").add('textarea').each(function() { | ||
58 | + this.value = ''; | ||
59 | + }); | ||
60 | + | ||
61 | + form.find('.errorExplanation').remove(); | ||
62 | + $.colorbox.close(); | ||
63 | + | ||
64 | + } | ||
65 | + | ||
66 | + comment_div.find('.comment-count').add('#article-header .comment-count').each(function() { | ||
67 | + var count = parseInt($(this).html()); | ||
68 | + update_comment_count($(this), count + 1); | ||
69 | + }); | ||
70 | + | ||
71 | + if(jQuery('#recaptcha_response_field').val()){ | ||
72 | + Recaptcha.reload(); | ||
73 | + } | ||
74 | + | ||
75 | + if(data.msg != null) { | ||
76 | + display_notice(data.msg); | ||
77 | + } | ||
78 | + | ||
79 | + close_loading(); | ||
80 | + toggleBox($button.closest('.post_comment_box')); | ||
81 | + $('.display-comment-form').show(); | ||
82 | + $button.removeClass('comment-button-loading'); | ||
83 | + $button.enable(); | ||
84 | + }, 'json'); | ||
85 | +} |