Commit d54a2cd178a2bae27ee911f2cab5c8079b3dc7c7
1 parent
b1e38748
Exists in
staging
and in
13 other branches
comment_paragraph: load comment form only when clicked
Showing
4 changed files
with
30 additions
and
3 deletions
Show diff stats
plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb
1 | -class CommentParagraphPluginProfileController < ProfileController | |
1 | +class CommentParagraphPluginProfileController < CommentController | |
2 | 2 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
3 | 3 | |
4 | 4 | def view_comments |
... | ... | @@ -11,4 +11,14 @@ class CommentParagraphPluginProfileController < ProfileController |
11 | 11 | render :partial => 'comment/comment.html.erb', :collection => @comments |
12 | 12 | end |
13 | 13 | |
14 | + def comment_form | |
15 | + @page = profile.articles.find(params[:article_id]) | |
16 | + render :partial => 'comment/comment_form', :locals => { | |
17 | + :comment => Comment.new, | |
18 | + :display_link => true, | |
19 | + :cancel_triggers_hide => true, | |
20 | + :paragraph_uuid => params[:paragraph_uuid] | |
21 | + } | |
22 | + end | |
23 | + | |
14 | 24 | end | ... | ... |
plugins/comment_paragraph/public/comment_paragraph_macro.js
... | ... | @@ -80,6 +80,12 @@ jQuery(document).ready(function($) { |
80 | 80 | container.find('.display-comment-form').show(); |
81 | 81 | } |
82 | 82 | }); |
83 | + var formDiv = container.find('.side-comment .post_comment_box'); | |
84 | + if(formDiv.find('.page-comment-form').length==0) { | |
85 | + $.ajax(formDiv.data('comment_paragraph_form_url')).done(function(data) { | |
86 | + formDiv.append(data); | |
87 | + }); | |
88 | + } | |
83 | 89 | }); |
84 | 90 | |
85 | 91 | ... | ... |
plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb
... | ... | @@ -10,6 +10,9 @@ class CommentParagraphPluginProfileControllerTest < ActionController::TestCase |
10 | 10 | @profile = create_user('testuser').person |
11 | 11 | @article = profile.articles.build(:name => 'test') |
12 | 12 | @article.save! |
13 | + @environment = Environment.default | |
14 | + @environment.enabled_plugins = ['CommentParagraphPlugin'] | |
15 | + @environment.save! | |
13 | 16 | end |
14 | 17 | attr_reader :article, :profile |
15 | 18 | |
... | ... | @@ -39,4 +42,12 @@ class CommentParagraphPluginProfileControllerTest < ActionController::TestCase |
39 | 42 | assert_match /d comment/, @response.body |
40 | 43 | end |
41 | 44 | |
45 | + should 'load the comment form for a paragraph' do | |
46 | + login_as('testuser') | |
47 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :paragraph_uuid => 0) | |
48 | + xhr :get, :comment_form, :profile => @profile.identifier, :article_id => article.id, :paragraph_uuid => 0 | |
49 | + assert_select ".page-comment-form" | |
50 | + assert_select "#comment_paragraph_uuid[value=?]", '0' | |
51 | + end | |
52 | + | |
42 | 53 | end | ... | ... |
plugins/comment_paragraph/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb
... | ... | @@ -11,14 +11,14 @@ |
11 | 11 | </div> |
12 | 12 | |
13 | 13 | <% load_comments_url = url_for({:profile => profile_identifier, :controller => 'comment_paragraph_plugin_profile', :action => 'view_comments', :paragraph_uuid => paragraph_uuid, :article_id => article_id}) %> |
14 | + <% load_comment_form_url = url_for({:profile => profile_identifier, :controller => 'comment_paragraph_plugin_profile', :action => 'comment_form', :paragraph_uuid => paragraph_uuid, :article_id => article_id}) %> | |
14 | 15 | |
15 | 16 | <div class="side-comment" data-comment_paragraph_url="<%= load_comments_url %>"> |
16 | 17 | <div class="article-comments-list"> |
17 | 18 | <div class="loading"></div> |
18 | 19 | </div> |
19 | 20 | <div class ="article-comments-list-more"></div> |
20 | - <div class='post_comment_box closed'> | |
21 | - <%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :paragraph_uuid => paragraph_uuid}%> | |
21 | + <div class='post_comment_box closed' data-comment_paragraph_form_url="<%= load_comment_form_url %>"> | |
22 | 22 | </div> |
23 | 23 | </div> |
24 | 24 | </div> | ... | ... |