diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index b9d072f5a..e196c94c3 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -77,7 +77,8 @@ var initialize_modules = function() { App.MarkdownEditor.initialize(); App.LegislationAllegations.initialize(); App.Legislation.initialize(); - App.LegislationAnnotatable.initialize(); + if ( $(".legislation-annotatable").length ) + App.LegislationAnnotatable.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/legislation_allegations.js.coffee b/app/assets/javascripts/legislation_allegations.js.coffee index e01a8b5d4..14d274243 100644 --- a/app/assets/javascripts/legislation_allegations.js.coffee +++ b/app/assets/javascripts/legislation_allegations.js.coffee @@ -3,6 +3,9 @@ App.LegislationAllegations = toggle_comments: -> $('.draft-allegation').toggleClass('comments-on'); + show_comments: -> + $('.draft-allegation').addClass('comments-on'); + initialize: -> $('.js-toggle-allegations .draft-panel').on click: (e) -> diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index fa5df598a..33803ab43 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -1,7 +1,35 @@ _t = (key) -> new Gettext().gettext(key) App.LegislationAnnotatable = + + renderAnnotationComments: (event) -> + $('.comment-box').offset(top: event.offset) + $.ajax + method: "GET" + url: event.annotation_url + "/annotations/" + event.annotation_id + "/comments" + dataType: 'script' + + viewerExtension: (viewer) -> + viewer._onHighlightMouseover = (event) -> + App.LegislationAllegations.show_comments() + $.event.trigger + type: "renderLegislationAnnotation" + annotation_id: $(event.target).data("annotation-id") + annotation_url: $(event.target).closest(".legislation-annotatable").data("legislation-annotatable-base-url") + offset: $(event.target).offset()["top"] + + + + scrollToAnchor: -> + annotationsLoaded: (annotations) -> + anchor = $(location).attr('hash') + ann_id = anchor.split("-")[-1..] + el = $("span[data-annotation-id='" + ann_id + "']") + $('html,body').animate({scrollTop: el.offset().top}) + initialize: -> + $(document).on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments) + current_user_id = $('html').data('current-user-id') if current_user_id == "" annotator.ui.editor.Editor.template = [ @@ -27,7 +55,8 @@ App.LegislationAnnotatable = ann["legislation_draft_version_id"] = ann_id ann.permissions = ann.permissions || {} ann.permissions.admin = [] - .include(annotator.ui.main, { element: this }) + .include(annotator.ui.main, { element: this, viewerExtensions: [App.LegislationAnnotatable.viewerExtension] }) + .include(App.LegislationAnnotatable.scrollToAnchor) .include(annotator.storage.http, { prefix: base_url, urls: { search: "/annotations/search" } }) app.start().then -> diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index bd6006909..ee63574f5 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -32,6 +32,10 @@ class Legislation::AnnotationsController < ApplicationController render json: annotations_hash.to_json end + def comments + @annotation = Legislation::Annotation.find(params[:annotation_id]) + end + private def annotation_params diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index e29880e95..179c67350 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -15,7 +15,7 @@ module Abilities can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:create], Legislation::Answer - can [:search, :read, :create], Legislation::Annotation + can [:search, :comments, :read, :create], Legislation::Annotation end end end diff --git a/app/views/legislation/annotations/_comments_for.html.erb b/app/views/legislation/annotations/_comments_for.html.erb new file mode 100644 index 000000000..caea782af --- /dev/null +++ b/app/views/legislation/annotations/_comments_for.html.erb @@ -0,0 +1,42 @@ +
<%= comment.body %>
+