Add form to publish a new first level comment from the comments box

This commit is contained in:
Amaia Castro
2017-01-18 16:39:06 +01:00
parent 35d2c54b4e
commit 1af047089f
6 changed files with 58 additions and 6 deletions

View File

@@ -4,7 +4,7 @@ App.Legislation =
$('#js-toggle-debate').on
click: ->
$('#debate-show').toggle()
$('#js-toggle-small-debate').on
click: ->
$('#debate-show').toggle()

View File

@@ -1,7 +1,7 @@
class Legislation::AnnotationsController < ApplicationController
skip_before_action :verify_authenticity_token
before_action :authenticate_user!, only: [:create]
before_action :authenticate_user!, only: [:create, :new_comment]
before_action :convert_ranges_parameters, only: [:create]
load_and_authorize_resource :process
@@ -43,6 +43,7 @@ class Legislation::AnnotationsController < ApplicationController
def comments
@annotation = Legislation::Annotation.find(params[:annotation_id])
@comment = @annotation.comments.new
end
def new
@@ -51,6 +52,19 @@ class Legislation::AnnotationsController < ApplicationController
end
end
def new_comment
@draft_version = Legislation::DraftVersion.find(params[:draft_version_id])
@annotation = @draft_version.annotations.find(params[:annotation_id])
@comment = @annotation.comments.new(body: params[:comment][:body], user: current_user)
if @comment.save
@comment = @annotation.comments.new
end
respond_to do |format|
format.js { render :comments }
end
end
private
def annotation_params

View File

@@ -20,7 +20,7 @@ module Abilities
can [:read, :changes, :go_to_version], Legislation::DraftVersion
can [:read], Legislation::Question
can [:create], Legislation::Answer
can [:search, :comments, :read, :create], Legislation::Annotation
can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation
end
end
end

View File

@@ -1,12 +1,12 @@
<div class="comment-header">
<span class="icon-comment" aria-hidden="true"></span>
<div class="comment-number"><%= t('legislation.annotations.comments.comments_count', count: annotation.comments_count) %></div>
<div class="comment-number"><%= t('legislation.annotations.comments.comments_count', count: annotation.comments.roots.count) %></div>
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %>
<span class="icon-expand" aria-hidden="true"></span>
<% end %>
</div>
<div class="comments-wrapper">
<% annotation.comments.roots.limit(5).each do |comment| %>
<% annotation.comments.roots.sort_by_newest.limit(Legislation::Annotation::COMMENTS_PAGE_SIZE).each do |comment| %>
<div class="comment">
<div class="comment-text">
<p><%= truncate comment.body, length: 250 %></p>
@@ -36,11 +36,39 @@
<% end %>
</div>
<div class="comment-footer">
<% if annotation.comments.roots.count > Legislation::Annotation::COMMENTS_PAGE_SIZE %>
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation), class: "button strong" do %>
<%= t('legislation.annotations.comments.see_all') %>
<% end %>
<% end %>
<a class="button strong publish-comment" title="Publicar comentario" href="#">Publicar comentario</a>
<% if @process.open_phase?(:allegations) %>
<a class="button strong publish-comment" title="Publicar comentario" href="#">Publicar comentario</a>
<% end %>
<% if @process.open_phase?(:allegations) %>
<% if user_signed_in? %>
<% css_id = parent_or_commentable_dom_id(nil, annotation) %>
<div id="js-comment-form-annotation" style="display:none" class="comment-form">
<%= form_for @comment, url: legislation_process_draft_version_annotation_new_comment_path(annotation.draft_version.process, annotation.draft_version, annotation), remote: true do |f| %>
<%= label_tag "comment-body-#{css_id}", leave_comment_text(annotation) %>
<%= f.text_area :body, id: "comment-body-#{css_id}", maxlength: Comment.body_max_length, label: false %>
<%= f.hidden_field :commentable_type, value: "Legislation::Annotation" %>
<%= f.hidden_field :commentable_id, value: annotation.id %>
<%= f.hidden_field :parent_id, value: nil %>
<%= f.submit comment_button_text(nil, annotation), class: "button" %>
<% end %>
</div>
<% else %>
<div data-alert class="callout primary">
<%= t("legislation.annotations.form.login_to_comment",
signin: link_to(t("legislation.annotations.form.signin"), new_user_session_path),
signup: link_to(t("legislation.annotations.form.signup"), new_user_registration_path)).html_safe %>
</div>
<% end %>
<% end %>
</div>

View File

@@ -1,2 +1,11 @@
$("#comments-box").html("<%= j render('comments_box', annotation: @annotation) %>").show();
$('a.publish-comment').on({
click: function(e) {
e.preventDefault();
$('a.publish-comment').hide();
$('#js-comment-form-annotation').toggle();
return;
}
});

View File

@@ -114,6 +114,7 @@ Rails.application.routes.draw do
resources :annotations do
get :search, on: :collection
get :comments
post :new_comment
end
end
end