From 931f99c448be8e7e498daf09a1ca497085c6748e Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Thu, 16 Mar 2017 16:43:34 -0500 Subject: [PATCH 1/2] Avoid JS error when there are no admin sets on the page. --- app/assets/javascripts/sufia/editor.es6 | 10 ++++------ .../javascripts/sufia/editor/admin_set_widget.es6 | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/sufia/editor.es6 b/app/assets/javascripts/sufia/editor.es6 index ea6c55a748..82686246c1 100644 --- a/app/assets/javascripts/sufia/editor.es6 +++ b/app/assets/javascripts/sufia/editor.es6 @@ -16,16 +16,14 @@ export default class { // Display the sharing tab if they select an admin set that permits sharing sharingTab() { - if(this.adminSetWidget) { - console.log("admin set selected") + if(this.adminSetWidget && !this.adminSetWidget.isEmpty()) { this.adminSetWidget.on('change', (data) => this.sharingTabVisiblity(data)) - this.sharingTabVisiblity(this.adminSetWidget.data()) + this.sharingTabVisiblity(this.adminSetWidget.isSharing()) } } - sharingTabVisiblity(data) { - console.log("Data " + data["sharing"]) - if (data["sharing"]) + sharingTabVisiblity(visible) { + if (visible) this.sharingTabElement.removeClass('hidden') else this.sharingTabElement.addClass('hidden') diff --git a/app/assets/javascripts/sufia/editor/admin_set_widget.es6 b/app/assets/javascripts/sufia/editor/admin_set_widget.es6 index d6d6f8f5ea..2361df7956 100644 --- a/app/assets/javascripts/sufia/editor/admin_set_widget.es6 +++ b/app/assets/javascripts/sufia/editor/admin_set_widget.es6 @@ -13,16 +13,27 @@ export default class { return this.element.find(":selected").data() } + isEmpty() { + return this.element.children().length === 0 + } + + /** + * returns undefined or true + */ + isSharing() { + return this.data()["sharing"] + } + on(eventName, handler) { switch (eventName) { case "change": - return this.changeHandlers.push(handler); + return this.changeHandlers.push(handler) } } change(data) { for (let fn of this.changeHandlers) { - setTimeout(function() { fn(data) }, 0); + setTimeout(function() { fn(data) }, 0) } } } From d7c1250a5bd7cb3a5ed194298b875071fbb8120d Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Fri, 17 Mar 2017 08:15:32 -0500 Subject: [PATCH 2/2] Trap for another null pointer error --- .../javascripts/sufia/save_work/visibility_component.es6 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/javascripts/sufia/save_work/visibility_component.es6 b/app/assets/javascripts/sufia/save_work/visibility_component.es6 index ce1ca7e5a7..d53fe5ed1c 100644 --- a/app/assets/javascripts/sufia/save_work/visibility_component.es6 +++ b/app/assets/javascripts/sufia/save_work/visibility_component.es6 @@ -43,6 +43,10 @@ export default class VisibilityComponent { limitByAdminSet() { if(this.adminSetWidget) { this.adminSetWidget.on('change', (data) => this.restrictToVisibility(data)) + if (this.adminSetWidget.isEmpty()) { + console.error("No data was passed from the admin set. Perhaps there are no selectable options?") + return + } this.restrictToVisibility(this.adminSetWidget.data()) } }