app/views/genres/_favorite_genres_modal.html.haml
.favorite-genres
%h2.lead What are your favorite genres?
%p.subtext We’ll use your favorite genres to improve your recommendations and customize your browsing experience on Hummingbird.
.row
- Genre.default_filterable(current_user).each do |genre|
.large-2.columns.genre-panel
.genre{:class => ("active" if current_user.favorite_genres.include?(genre)), :"data-genre" => genre.slug, :"data-favorite" => current_user.favorite_genres.include?(genre).inspect}
%span= genre.name
:coffee
$(".genre").click ->
button = this
genre = $(button).attr("data-genre")
favorite = $(button).attr("data-favorite") == "true"
console.log $(button).attr("data-favorite")
spinner = $("<i class='fa fa-spin fa-spinner' style='font-size: 0.8em;'></i>")
$(button).find("span").hide()
$(button).append spinner
if favorite
$.post "/genres/" + genre + "/remove_from_favorites", {id: genre}, (d) ->
$(button).attr "data-favorite", "false"
$(button).removeClass "active"
$(".genre-list #" + genre).hide()
spinner.hide()
$(button).find("span").show()
else
$.post "/genres/" + genre + "/add_to_favorites", {id: genre}, (d) ->
$(button).attr "data-favorite", "true"
$(button).addClass "active"
$(".genre-list .no-favorites").hide()
$(".genre-list").append "<li id='"+genre+"'><a href='/genres/"+genre+"'>" + $(button).find("span").html() + "</a></li>"
spinner.hide()
$(button).find("span").show()