From 046c021c0c40b489b2afaff72fa629dc8b3dfbfd Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Sat, 14 Jan 2017 16:06:45 +0100 Subject: [PATCH] Complete create comment details --- .../legislation_annotatable.js.coffee | 27 ++++++++++--------- .../legislation/annotations/_form.html.erb | 24 +++++++++++------ .../legislation/annotations/comments.js.erb | 2 +- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index f1e2d50d2..4baa1a725 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -17,8 +17,6 @@ App.LegislationAnnotatable = return highlight: (colour) -> - range = undefined - sel = undefined if window.getSelection # IE9 and non-IE try @@ -39,7 +37,7 @@ App.LegislationAnnotatable = return renderAnnotationComments: (event) -> - $('.comment-box').offset(top: event.offset) + $('#comments-box').css({top: event.offset - $('.calc-comments').offset().top}) $.ajax method: "GET" url: event.annotation_url + "/annotations/" + event.annotation_id + "/comments" @@ -75,18 +73,23 @@ App.LegislationAnnotatable = dataType: 'script').done (-> $('#new_legislation_annotation #legislation_annotation_quote').val(@annotation.quote) $('#new_legislation_annotation #legislation_annotation_ranges').val(JSON.stringify(@annotation.ranges)) - $('#comments-box').css({top: $('.annotator-adder').position().top}) + $('#comments-box').css({top: position.top - $('.calc-comments').offset().top}) App.LegislationAnnotatable.highlight('#7fff9a') $('#comments-box textarea').focus() $("#new_legislation_annotation").on("ajax:complete", (e, data, status, xhr) -> - App.LegislationAnnotatable.remove_highlight() - $("#comments-box").html("").hide(); + if data.status == 200 + App.LegislationAnnotatable.remove_highlight() + $("#comments-box").html("").hide() + $.ajax + method: "GET" + url: annotation_url + "/annotations/" + data.responseJSON.id + "/comments" + dataType: 'script' + else + $(e.target).find('label').addClass('error') + $('' + data.responseJSON[0] + '').insertAfter($(e.target).find('textarea')) return true - ).on("ajax:error", (e, data, status, xhr) -> - console.log(data) - return false ) return ).bind(this) @@ -108,9 +111,9 @@ App.LegislationAnnotatable = offset: el.offset()["top"] initialize: -> - $(document).on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments) - $(document).on('click', '[data-annotation-id]', App.LegislationAnnotatable.onClick) - $(document).on('click', '[data-cancel-annotation]', (e) -> + $(document).off("renderLegislationAnnotation").on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments) + $(document).off('click', '[data-annotation-id]').on('click', '[data-annotation-id]', App.LegislationAnnotatable.onClick) + $(document).off('click', '[data-cancel-annotation]').on('click', '[data-cancel-annotation]', (e) -> e.preventDefault() $('#comments-box').html('') $('#comments-box').hide() diff --git a/app/views/legislation/annotations/_form.html.erb b/app/views/legislation/annotations/_form.html.erb index 7fa52cd5a..317a712c8 100644 --- a/app/views/legislation/annotations/_form.html.erb +++ b/app/views/legislation/annotations/_form.html.erb @@ -8,16 +8,24 @@
- <%= form_for Legislation::Annotation.new, url: legislation_process_draft_version_annotations_path(@process, @draft_version), remote: true do |f| %> - <%= f.text_area :text %> + <% if 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' %> -
+
+ <%= 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 %> + <%= f.hidden_field :quote %> + <%= f.hidden_field :ranges %> + <% end %> + <% else %> +
+ <%= t("debates.show.login_to_comment", + signin: link_to(t("votes.signin"), new_user_session_path), + signup: link_to(t("votes.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 6ee83560e..75d8f35a0 100644 --- a/app/views/legislation/annotations/comments.js.erb +++ b/app/views/legislation/annotations/comments.js.erb @@ -1,2 +1,2 @@ -$("#comments-box").html("<%= j render('comments_box', annotation: @annotation) %>"); +$("#comments-box").html("<%= j render('comments_box', annotation: @annotation) %>").show();