diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 939705c51..19c081b54 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -53,8 +53,8 @@ //= require cocoon //= require legislation //= require legislation_allegations -//= require legislation_annotatable //= require custom +//= require legislation_annotatable var initialize_modules = function() { App.Comments.initialize(); diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index 6c880b3a9..50903021a 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -1,7 +1,6 @@ // Overrides and adds customized javascripts in this file -// Read more on documentation: +// Read more on documentation: // * English: https://github.com/consul/consul/blob/master/CUSTOMIZE_EN.md#javascript // * Spanish: https://github.com/consul/consul/blob/master/CUSTOMIZE_ES.md#javascript // -// diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index f1df2927a..dd861c6ef 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -19,7 +19,23 @@ App.LegislationAnnotatable = annotation_url: $(event.target).closest(".legislation-annotatable").data("legislation-annotatable-base-url") offset: $(event.target).offset()["top"] + customShow: (position) -> + $(@element).html '' + # Clean comments section and open it + $('#comments-box').html '' + App.LegislationAllegations.show_comments() + annotation_url = $('[data-legislation-annotatable-base-url]').data('legislation-annotatable-base-url') + $.ajax( + method: 'GET' + url: annotation_url + '/annotations/new' + dataType: 'script').done (-> + $('#new_annotation #annotation_quote').val(@annotation.quote) + $('#new_annotation #annotation_ranges').val(JSON.stringify(@annotation.ranges)) + ).bind(this) + + editorExtension: (editor) -> + editor.show = App.LegislationAnnotatable.customShow scrollToAnchor: -> annotationsLoaded: (annotations) -> @@ -62,7 +78,11 @@ App.LegislationAnnotatable = ann["legislation_draft_version_id"] = ann_id ann.permissions = ann.permissions || {} ann.permissions.admin = [] - .include(annotator.ui.main, { element: this, viewerExtensions: [App.LegislationAnnotatable.viewerExtension] }) + .include(annotator.ui.main, { + element: this, + viewerExtensions: [App.LegislationAnnotatable.viewerExtension], + editorExtensions: [App.LegislationAnnotatable.editorExtension] + }) .include(App.LegislationAnnotatable.scrollToAnchor) .include(annotator.storage.http, { prefix: base_url, urls: { search: "/annotations/search" } }) diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index f1c4e4401..861eb9d14 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -2,6 +2,7 @@ class Legislation::AnnotationsController < ApplicationController skip_before_action :verify_authenticity_token before_action :authenticate_user!, only: [:create] + before_action :convert_ranges_parameters, only: [:create] load_and_authorize_resource :process load_and_authorize_resource :draft_version, through: :process @@ -44,6 +45,13 @@ class Legislation::AnnotationsController < ApplicationController @annotation = Legislation::Annotation.find(params[:annotation_id]) end + def new + respond_to do |format| + format.js + end + end + + private def annotation_params @@ -58,4 +66,11 @@ class Legislation::AnnotationsController < ApplicationController "legislation_draft_version_id": @draft_version.id end + def convert_ranges_parameters + if params[:annotation] && params[:annotation][:ranges] + params[:annotation][:ranges] = JSON.parse(params[:annotation][:ranges]) + end + rescue JSON::ParserError + end + end diff --git a/app/views/legislation/annotations/_form.html.erb b/app/views/legislation/annotations/_form.html.erb new file mode 100644 index 000000000..81605e648 --- /dev/null +++ b/app/views/legislation/annotations/_form.html.erb @@ -0,0 +1,31 @@ +