Skip to content

Commit

Permalink
Merge pull request #3155 from projecthydra/fix_3153
Browse files Browse the repository at this point in the history
Avoid JS error when there are no admin sets on the page.
  • Loading branch information
hackartisan authored Mar 17, 2017
2 parents e94fd64 + d7c1250 commit 6efa189
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
10 changes: 4 additions & 6 deletions app/assets/javascripts/sufia/editor.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
15 changes: 13 additions & 2 deletions app/assets/javascripts/sufia/editor/admin_set_widget.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand Down

0 comments on commit 6efa189

Please sign in to comment.