From c7eaadb4b2fd1cec905bfc0b0ca33b4f7ae50e71 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Fri, 24 Feb 2017 13:43:32 +0100 Subject: [PATCH] Show comment boxes for all annotations at the clicked point --- .../legislation_annotatable.js.coffee | 17 ++- .../stylesheets/legislation_process.scss | 16 +-- .../legislation/annotations_controller.rb | 2 +- .../annotations/_comments_box.html.erb | 118 +++++++++--------- .../annotations/_comments_box_form.js.erb | 15 +++ .../legislation/annotations/_form.html.erb | 54 ++++---- .../legislation/annotations/comments.js.erb | 18 +-- .../annotations/new_comment.js.erb | 3 + .../draft_versions/_comments_panel.html.erb | 10 +- 9 files changed, 137 insertions(+), 116 deletions(-) create mode 100644 app/views/legislation/annotations/_comments_box_form.js.erb create mode 100644 app/views/legislation/annotations/new_comment.js.erb diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index d843d4629..521b61f34 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -37,7 +37,9 @@ App.LegislationAnnotatable = return renderAnnotationComments: (event) -> - $('#comments-box').css({top: event.offset - $('.calc-comments').offset().top}) + if event.offset + $("#comments-box").css({top: event.offset - $('.calc-comments').offset().top}) + if App.LegislationAnnotatable.isMobile() return @@ -58,17 +60,30 @@ App.LegislationAnnotatable = $('[data-annotation-id]').removeClass('current-annotation') target = $(this) + + parents = target.parents('.annotator-hl') + parents_ids = parents.map (_, elem) -> + $(elem).data("annotation-id") + annotation_id = target.data('annotation-id') $('[data-annotation-id="'+annotation_id+'"]').addClass('current-annotation') + $('#comments-box').html('') App.LegislationAllegations.show_comments() $("#comments-box").show() + $.event.trigger type: "renderLegislationAnnotation" annotation_id: target.data("annotation-id") annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url") offset: target.offset()["top"] + parents_ids.each (i, pid) -> + $.event.trigger + type: "renderLegislationAnnotation" + annotation_id: pid + annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url") + isMobile: () -> return window.innerWidth <= 652 diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 0b53115d6..35426e852 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -827,14 +827,18 @@ $epigraph-line-height: rem-calc(22); display: none; } + #comments-box { + position: absolute; + top: 230px; + } + .comment-box { width: 375px; padding: 1rem; background: #F9F9F9; border: 1px solid $border; display: block; - position: absolute; - top: 230px; + margin-bottom: 2rem; .button { font-size: $small-font-size; @@ -986,14 +990,6 @@ $epigraph-line-height: rem-calc(22); } } - .comment-box:nth-child(4) { - top: 838px; - } - - .comment-box:nth-child(5) { - top: 2035px; - } - .draft-panel { background: #E5E5E5; border-left: 1px solid #D4D4D4; diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index bda36dd4d..e0fdebbf2 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -73,7 +73,7 @@ class Legislation::AnnotationsController < ApplicationController end respond_to do |format| - format.js { render :comments } + format.js { render :new_comment } end end diff --git a/app/views/legislation/annotations/_comments_box.html.erb b/app/views/legislation/annotations/_comments_box.html.erb index f699308d5..4553bdf0d 100644 --- a/app/views/legislation/annotations/_comments_box.html.erb +++ b/app/views/legislation/annotations/_comments_box.html.erb @@ -1,70 +1,72 @@ -
- -
<%= t('legislation.annotations.comments.comments_count', count: annotation.comments.roots.count) %>
- <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> - - <% end %> -
-
- <% annotation.comments.roots.sort_by_most_voted.limit(Legislation::Annotation::COMMENTS_PAGE_SIZE).each do |comment| %> -
-
-

<%= truncate comment.body, length: 250 %>

-
-
-
- <% if comment.body.length > 250 %> -
- <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> - <%= t('legislation.annotations.comments.see_complete') %> +
+
+ +
<%= t('legislation.annotations.comments.comments_count', count: annotation.comments.roots.count) %>
+ <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> + + <% end %> +
+
+ <% annotation.comments.roots.sort_by_most_voted.limit(Legislation::Annotation::COMMENTS_PAGE_SIZE).each do |comment| %> +
+
+

<%= truncate comment.body, length: 250 %>

+
+
+
+ <% if comment.body.length > 250 %> +
+ <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> + <%= t('legislation.annotations.comments.see_complete') %> + <% end %> +
+ <% end %> +
+ <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation, anchor: "comment_#{comment.id}") do %> + <%= t('legislation.annotations.comments.replies_count', count: comment.children.size) %> <% end %>
- <% end %> -
- <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation, anchor: "comment_#{comment.id}") do %> - <%= t('legislation.annotations.comments.replies_count', count: comment.children.size) %> - <% end %>
-
-
-
- <%= render 'comments/votes', comment: comment %> +
+
+ <%= render 'comments/votes', comment: comment %> +
+ <% end %> +
- <% end %> -
- - +
diff --git a/app/views/legislation/annotations/_comments_box_form.js.erb b/app/views/legislation/annotations/_comments_box_form.js.erb new file mode 100644 index 000000000..a475c54db --- /dev/null +++ b/app/views/legislation/annotations/_comments_box_form.js.erb @@ -0,0 +1,15 @@ +$('#comments-box-<%= annotation.id %> a.publish-comment').on({ + click: function(e) { + e.preventDefault(); + $('a.publish-comment').hide(); + $('#js-comment-form-annotation-<%= annotation.id %>').toggle(); + $('#js-comment-form-annotation-<%= annotation.id %> textarea').focus(); + return; + } +}); + +<% if comment.errors.any? %> + $('#comments-box-<%= @annotation.id %> a.publish-comment').hide(); + $('#js-comment-form-annotation-<%= annotation.id %>').toggle(); + $('#js-comment-form-annotation-<%= annotation.id %> textarea').focus(); +<% end %> diff --git a/app/views/legislation/annotations/_form.html.erb b/app/views/legislation/annotations/_form.html.erb index f0a64e7ac..676991859 100644 --- a/app/views/legislation/annotations/_form.html.erb +++ b/app/views/legislation/annotations/_form.html.erb @@ -1,33 +1,35 @@ -
- -
<%= t('legislation.annotations.comments.comments_count', count: 0) %>
-
+
+
+ +
<%= t('legislation.annotations.comments.comments_count', count: 0) %>
+
-
-
- <% if !@process.open_phase?(:allegations) %> -
- <%= t("legislation.annotations.form.phase_not_open") %> -
- <% elsif user_signed_in? %> - <%= form_for Legislation::Annotation.new, url: legislation_process_draft_version_annotations_path(@process, @draft_version), remote: true do |f| %> - <%= f.text_area :text %> - -
- <%= t('legislation.annotations.comments.cancel') %> - <%= f.submit t('legislation.annotations.comments.publish_comment'), class: 'button strong publish-comment' %> +
+
+ <% if !@process.open_phase?(:allegations) %> +
+ <%= t("legislation.annotations.form.phase_not_open") %>
+ <% elsif user_signed_in? %> + <%= form_for Legislation::Annotation.new, url: legislation_process_draft_version_annotations_path(@process, @draft_version), remote: true do |f| %> + <%= f.text_area :text %> - <%= f.hidden_field :quote %> - <%= f.hidden_field :ranges %> +
+ <%= t('legislation.annotations.comments.cancel') %> + <%= f.submit t('legislation.annotations.comments.publish_comment'), class: 'button strong publish-comment' %> +
+ + <%= f.hidden_field :quote %> + <%= f.hidden_field :ranges %> + <% end %> + <% else %> +
+ <%= 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 %> +
<% end %> - <% else %> -
- <%= 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 %> -
- <% end %> +
diff --git a/app/views/legislation/annotations/comments.js.erb b/app/views/legislation/annotations/comments.js.erb index 8074f6040..d44eff2fd 100644 --- a/app/views/legislation/annotations/comments.js.erb +++ b/app/views/legislation/annotations/comments.js.erb @@ -1,17 +1,3 @@ -$("#comments-box").html("<%= j render('comments_box', annotation: @annotation) %>").show(); +$("#comments-box").append("<%= 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(); - $('#js-comment-form-annotation textarea').focus(); - return; - } -}); - -<% if @comment.errors.any? %> - $('a.publish-comment').hide(); - $('#js-comment-form-annotation').toggle(); - $('#js-comment-form-annotation textarea').focus(); -<% end %> +<%= render 'comments_box_form', comment: @comment, annotation: @annotation %> diff --git a/app/views/legislation/annotations/new_comment.js.erb b/app/views/legislation/annotations/new_comment.js.erb new file mode 100644 index 000000000..1363acec9 --- /dev/null +++ b/app/views/legislation/annotations/new_comment.js.erb @@ -0,0 +1,3 @@ +$("#comments-box-<%= @annotation.id %>").replaceWith("<%= j render('comments_box', annotation: @annotation) %>").show(); + +<%= render 'comments_box_form', comment: @comment, annotation: @annotation %> diff --git a/app/views/legislation/draft_versions/_comments_panel.html.erb b/app/views/legislation/draft_versions/_comments_panel.html.erb index 94523b557..b7f92074c 100644 --- a/app/views/legislation/draft_versions/_comments_panel.html.erb +++ b/app/views/legislation/draft_versions/_comments_panel.html.erb @@ -9,10 +9,12 @@ <%= t('legislation.draft_versions.show.text_comments') %>
-