From 7061d70f22c8ee2ea0279b3068ab770efffa0bed Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 23 Feb 2017 16:04:30 +0100 Subject: [PATCH] Avoid loading annotations twice when creating new one --- app/assets/javascripts/legislation_annotatable.js.coffee | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index 16d5d94b2..9714482d6 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -101,6 +101,7 @@ App.LegislationAnnotatable = $('#comments-box textarea').focus() $("#new_legislation_annotation").on("ajax:complete", (e, data, status, xhr) -> + App.LegislationAnnotatable.app.destroy() if data.status == 200 App.LegislationAnnotatable.remove_highlight() $("#comments-box").html("").hide() @@ -152,7 +153,7 @@ App.LegislationAnnotatable = ann_id = $this.data("legislation-draft-version-id") base_url = $this.data("legislation-annotatable-base-url") - app = new annotator.App() + App.LegislationAnnotatable.app = new annotator.App() .include -> beforeAnnotationCreated: (ann) -> ann["legislation_draft_version_id"] = ann_id @@ -166,9 +167,9 @@ App.LegislationAnnotatable = .include(App.LegislationAnnotatable.scrollToAnchor) .include(annotator.storage.http, { prefix: base_url, urls: { search: "/annotations/search" } }) - app.start().then -> - app.ident.identity = current_user_id + App.LegislationAnnotatable.app.start().then -> + App.LegislationAnnotatable.app.ident.identity = current_user_id options = {} options["legislation_draft_version_id"] = ann_id - app.annotations.load(options) + App.LegislationAnnotatable.app.annotations.load(options)