Commit 935ff6bc0bd4318960fa0b0235d54864b228c416

Authored by Leandro Nunes dos Santos
1 parent 7989a4c7

mergin with ActionItem2562

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">
plugins/solr/views/search/.communities.rhtml.swp 0 → 100644
No preview for this file type
plugins/solr/views/search/.people.rhtml.swp 0 → 100644
No preview for this file type
public/javascripts/application.js
@@ -760,69 +760,6 @@ function update_comment_count(element, new_count) { @@ -760,69 +760,6 @@ function update_comment_count(element, new_count) {
760 760
761 } 761 }
762 762
763 -function save_comment(button) {  
764 - var $ = jQuery;  
765 - open_loading(DEFAULT_LOADING_MESSAGE);  
766 - var $button = $(button);  
767 - var form = $(button).parents("form");  
768 - var post_comment_box = $(button).parents('.post_comment_box');  
769 - var comment_div = $button.parents('.comments');  
770 - $button.addClass('comment-button-loading');  
771 - $.post(form.attr("action"), form.serialize(), function(data) {  
772 -  
773 - if(data.render_target == null) {  
774 - //Comment for approval  
775 - form.find("input[type='text']").add('textarea').each(function() {  
776 - this.value = '';  
777 - });  
778 - form.find('.errorExplanation').remove();  
779 -  
780 - } else if(data.render_target == 'form') {  
781 - //Comment with errors  
782 - var page_comment_form = $(button).parents('.page-comment-form');  
783 - $.scrollTo(page_comment_form);  
784 - page_comment_form.html(data.html);  
785 -  
786 - } else if($('#' + data.render_target).size() > 0) {  
787 - //Comment of reply  
788 - $('#'+ data.render_target).replaceWith(data.html);  
789 - $('#' + data.render_target).effect("highlight", {}, 3000);  
790 - $.colorbox.close();  
791 -  
792 - } else {  
793 - //New comment of article  
794 - comment_div.find('.article-comments-list').append(data.html);  
795 -  
796 - form.find("input[type='text']").add('textarea').each(function() {  
797 - this.value = '';  
798 - });  
799 -  
800 - form.find('.errorExplanation').remove();  
801 - $.colorbox.close();  
802 -  
803 - }  
804 -  
805 - comment_div.find('.comment-count').add('#article-header .comment-count').each(function() {  
806 - var count = parseInt($(this).html());  
807 - update_comment_count($(this), count + 1);  
808 - });  
809 -  
810 - if(jQuery('#recaptcha_response_field').val()){  
811 - Recaptcha.reload();  
812 - }  
813 -  
814 - if(data.msg != null) {  
815 - display_notice(data.msg);  
816 - }  
817 -  
818 - close_loading();  
819 - post_comment_box.removeClass('opened');  
820 - post_comment_box.addClass('closed');  
821 - $button.removeClass('comment-button-loading');  
822 - $button.enable();  
823 - }, 'json');  
824 -}  
825 -  
826 function remove_comment(button, url, msg) { 763 function remove_comment(button, url, msg) {
827 var $ = jQuery; 764 var $ = jQuery;
828 var $button = $(button); 765 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 +}