Use comments component for legislation annotations and questions
This commit is contained in:
@@ -1,12 +1,4 @@
|
||||
module CommentsHelper
|
||||
def comment_tree_title_text(commentable)
|
||||
if commentable.class == Legislation::Question
|
||||
t("legislation.questions.comments.comments_title")
|
||||
else
|
||||
t("comments_helper.comments_title")
|
||||
end
|
||||
end
|
||||
|
||||
def leave_comment_text(commentable)
|
||||
if commentable.class == Legislation::Question
|
||||
t("legislation.questions.comments.form.leave_comment")
|
||||
|
||||
@@ -4,25 +4,8 @@
|
||||
<section class="expanded comments">
|
||||
<div class="row">
|
||||
<div id="comments" class="small-12 column">
|
||||
<% if display_comments_count %>
|
||||
<h2>
|
||||
<%= comment_tree_title_text(commentable) %>
|
||||
<span class="js-comments-count">(<%= commentable.comments_count %>)</span>
|
||||
</h2>
|
||||
<% end %>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<% if comments_closed_for_commentable?(commentable) %>
|
||||
<br>
|
||||
<div data-alert class="callout primary">
|
||||
<%= comments_closed_text(commentable) %>
|
||||
</div>
|
||||
<% elsif require_verified_resident_for_commentable?(commentable, current_user) %>
|
||||
<br>
|
||||
<div data-alert class="callout primary">
|
||||
<%= sanitize(t("comments.verified_only", verify_account: link_to_verify_account)) %>
|
||||
</div>
|
||||
<% elsif !valuation || can?(:comment_valuation, commentable) %>
|
||||
<% if !valuation || can?(:comment_valuation, commentable) %>
|
||||
<%= render "comments/form", { commentable: commentable,
|
||||
parent_id: nil,
|
||||
valuation: valuation } %>
|
||||
|
||||
@@ -1,35 +1,47 @@
|
||||
<% valuation = local_assigns.fetch(:valuation, false) %>
|
||||
<% cache [locale_and_user_status, parent_id, commentable_cache_key(commentable), valuation] do %>
|
||||
<% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
|
||||
<div id="js-comment-form-<%= css_id %>" class="comment-form">
|
||||
<%= form_for Comment.new, remote: true, html: { id: "new_comment_#{css_id}" } do |f| %>
|
||||
<%= f.text_area :body,
|
||||
id: "comment-body-#{css_id}",
|
||||
maxlength: Comment.body_max_length,
|
||||
label: leave_comment_text(commentable) %>
|
||||
<% if comments_closed_for_commentable?(commentable) %>
|
||||
<br>
|
||||
<div data-alert class="callout primary">
|
||||
<%= comments_closed_text(commentable) %>
|
||||
</div>
|
||||
<% elsif require_verified_resident_for_commentable?(commentable, current_user) %>
|
||||
<br>
|
||||
<div data-alert class="callout primary">
|
||||
<%= sanitize(t("comments.verified_only", verify_account: link_to_verify_account)) %>
|
||||
</div>
|
||||
<% else %>
|
||||
<% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
|
||||
<div id="js-comment-form-<%= css_id %>" class="comment-form">
|
||||
<%= form_for Comment.new, remote: true, html: { id: "new_comment_#{css_id}" } do |f| %>
|
||||
<%= f.text_area :body,
|
||||
id: "comment-body-#{css_id}",
|
||||
maxlength: Comment.body_max_length,
|
||||
label: leave_comment_text(commentable) %>
|
||||
|
||||
<%= f.hidden_field :commentable_type, value: commentable.class.name, id: "comment_commentable_type_#{css_id}" %>
|
||||
<%= f.hidden_field :commentable_id, value: commentable.id, id: "comment_commentable_id_#{css_id}" %>
|
||||
<%= f.hidden_field :parent_id, value: parent_id, id: "comment_parent_id_#{css_id}" %>
|
||||
<%= f.hidden_field :valuation, value: valuation, id: "comment_valuation_#{css_id}" %>
|
||||
<%= f.hidden_field :commentable_type, value: commentable.class.name, id: "comment_commentable_type_#{css_id}" %>
|
||||
<%= f.hidden_field :commentable_id, value: commentable.id, id: "comment_commentable_id_#{css_id}" %>
|
||||
<%= f.hidden_field :parent_id, value: parent_id, id: "comment_parent_id_#{css_id}" %>
|
||||
<%= f.hidden_field :valuation, value: valuation, id: "comment_valuation_#{css_id}" %>
|
||||
|
||||
<%= f.submit comment_button_text(parent_id, commentable), class: "button", id: "publish_comment_#{css_id}" %>
|
||||
<%= f.submit comment_button_text(parent_id, commentable), class: "button", id: "publish_comment_#{css_id}" %>
|
||||
|
||||
<% if can? :comment_as_moderator, commentable %>
|
||||
<div class="float-right">
|
||||
<%= f.check_box :as_moderator,
|
||||
label: t("comments.form.comment_as_moderator"),
|
||||
id: "comment-as-moderator-#{css_id}" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if can? :comment_as_administrator, commentable %>
|
||||
<div class="float-right">
|
||||
<%= f.check_box :as_administrator,
|
||||
label: t("comments.form.comment_as_admin"),
|
||||
id: "comment-as-administrator-#{css_id}" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if can? :comment_as_moderator, commentable %>
|
||||
<div class="float-right">
|
||||
<%= f.check_box :as_moderator,
|
||||
label: t("comments.form.comment_as_moderator"),
|
||||
id: "comment-as-moderator-#{css_id}" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if can? :comment_as_administrator, commentable %>
|
||||
<div class="float-right">
|
||||
<%= f.check_box :as_administrator,
|
||||
label: t("comments.form.comment_as_admin"),
|
||||
id: "comment-as-administrator-#{css_id}" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -43,8 +43,12 @@
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<%= render "/comments/comment_tree", comment_tree: @comment_tree,
|
||||
display_comments_count: true %>
|
||||
<%= render Shared::CommentsComponent.new(@annotation, @comment_tree) do %>
|
||||
<h2>
|
||||
<%= t("comments_helper.comments_title") %>
|
||||
<span class="js-comments-count">(<%= @annotation.comments_count %>)</span>
|
||||
</h2>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -41,7 +41,10 @@
|
||||
<%= render "/shared/social_share", title: @question.title, url: legislation_process_question_url(@question.process, @question) %>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<%= render "/comments/comment_tree", comment_tree: @comment_tree,
|
||||
display_comments_count: true %>
|
||||
<%= render Shared::CommentsComponent.new(@question, @comment_tree) do %>
|
||||
<h2>
|
||||
<%= t("legislation.questions.comments.comments_title") %>
|
||||
<span class="js-comments-count">(<%= @question.comments_count %>)</span>
|
||||
</h2>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
<h2><%= t("valuation.budget_investments.valuation_comments") %></h2>
|
||||
<% unless @comment_tree.nil? %>
|
||||
<%= render "/comments/comment_tree", comment_tree: @comment_tree,
|
||||
display_comments_count: false,
|
||||
valuation: true %>
|
||||
<%= render "/comments/comment_tree", comment_tree: @comment_tree, valuation: true %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user