Skip to content

Commit

Permalink
Fix Uncaught TypeError on notes emails subscribe
Browse files Browse the repository at this point in the history
See #298
  • Loading branch information
jvendetti committed Dec 13, 2023
1 parent 1fb2d56 commit 4856bf9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions app/assets/javascripts/bp_notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,17 @@ function subscribeToNotes(button) {
var subbedVal = (isSubbed == "true") ? "false" : "true";
jQuery("a.subscribe_to_notes").attr("data-bp_is_subbed", subbedVal);

// Change button text
var txt = jQuery("a.subscribe_to_notes span.ui-button-text").html();
var newButtonText = txt.match("Unsubscribe") ? txt.replace("Unsubscribe", "Subscribe") : txt.replace("Subscribe", "Unsubscribe");
jQuery("a.subscribe_to_notes span.ui-button-text").html(newButtonText);
/*
* Update link text.
* Note that there are two links that allow users to subscribe/unsubscribe from notes emails. Given any ontology,
* one link is located on the top-level Notes tab, and the other link is located on the Notes sub-tab on the
* right-hand side of the Classes tab. Both links are handled by the subscriptions controller, and the text of
* both should be updated on success.
*/
const matches = document.querySelectorAll('a.subscribe_to_notes');
matches.forEach(match => {
match.textContent = (subbedVal === 'true') ? 'Unsubscribe from notes emails' : 'Subscribe to notes emails';
});
},
error: function(data) {
jQuery(".notes_subscribe_spinner").hide();
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/notes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ def subscribe_button(ontology_id)
ont = LinkedData::Client::Models::Ontology.find_by_acronym(ontology_id).first
end
subscribed = subscribed_to_ontology?(ont.acronym, user) # application_helper
sub_text = subscribed ? "Unsubscribe" : "Subscribe"
sub_text = subscribed ? "Unsubscribe from" : "Subscribe to"
params = "data-bp_ontology_id='#{ont.acronym}' data-bp_is_subbed='#{subscribed}' data-bp_user_id='#{user.id}'"
rescue
# pass, fallback init done above begin block to scope parameters beyond the begin/rescue block
end
spinner = '<span class="notes_subscribe_spinner" style="display: none;">' + image_tag("spinners/spinner_000000_16px.gif", style: "vertical-align: text-bottom;") + '</span>'
error = "<span style='color: red;' class='notes_sub_error'></span>"
return "<a href='javascript:void(0);' class='subscribe_to_notes link_button' #{params}>#{sub_text} to notes emails</a> #{spinner} #{error}".html_safe
return "<a href='javascript:void(0);' class='subscribe_to_notes link_button' #{params}>#{sub_text} notes emails</a> #{spinner} #{error}".html_safe
end

def delete_button
Expand Down

0 comments on commit 4856bf9

Please sign in to comment.