From d3f3ca8b84218fb5dd7c060a08271b9f9ac7b506 Mon Sep 17 00:00:00 2001 From: mike vallano Date: Mon, 17 Aug 2020 19:26:41 -0500 Subject: [PATCH] 212: Specify movie id for selector on show page after create --- app/assets/javascripts/z.js | 1 + app/views/listings/create.js.erb | 24 ++++++++++++++---------- app/views/movies/_movie.html.erb | 1 - 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/z.js b/app/assets/javascripts/z.js index 981e0a73..76b28e05 100644 --- a/app/assets/javascripts/z.js +++ b/app/assets/javascripts/z.js @@ -19,6 +19,7 @@ $(document).ready(function(){ 'z-index': 1100 }); + // Generic selector to trigger autocomplete on the movie show page $('.list-dropdown').autocomplete({ source: $('.list-dropdown').data('autocomplete-source'), minLength: 0, diff --git a/app/views/listings/create.js.erb b/app/views/listings/create.js.erb index 1b8a1357..6d4a79f5 100644 --- a/app/views/listings/create.js.erb +++ b/app/views/listings/create.js.erb @@ -1,22 +1,21 @@ var from = "<%= @from %>"; if (from == 'first_list') { console.log("from page " + from); - $("#movie_modal_innard_<%= @movie.tmdb_id %>").html("<%= j(render :partial => 'movies/movie_modal_innard', :locals => {:movie => @movie}) %>"); - $("#movie_show_listings_<%= @movie.tmdb_id %>").html("<%= j(render :partial => 'movies/movie_show_list_manage', :locals => {:movie => @movie}) %>"); + $("#movie_modal_innard_<%= @movie.tmdb_id %>").html("<%= j(render partial: 'movies/movie_modal_innard', locals: {movie: @movie}) %>"); + $("#movie_show_listings_<%= @movie.tmdb_id %>").html("<%= j(render partial: 'movies/movie_show_list_manage', locals: {movie: @movie}) %>"); } else { - $("#movie_on_lists_<%= @movie.tmdb_id %>").html("<%= j(render :partial => 'movies/movie_on_lists', :locals => {:movie => @movie}) %>"); - $("#movie_other_list_<%= @movie.tmdb_id %>").html("<%= j(render :partial => 'movies/movie_add_to_another_list', :locals => {:movie => @movie}) %>"); - $("#movie_show_listings_<%= @movie.tmdb_id %>").html("<%= j(render :partial => 'movies/movie_show_list_manage', :locals => {:movie => @movie}) %>"); + $("#movie_on_lists_<%= @movie.tmdb_id %>").html("<%= j(render partial: 'movies/movie_on_lists', locals: {movie: @movie}) %>"); + $("#movie_other_list_<%= @movie.tmdb_id %>").html("<%= j(render partial: 'movies/movie_add_to_another_list', locals: {movie: @movie}) %>"); + $("#movie_show_listings_<%= @movie.tmdb_id %>").html("<%= j(render partial: 'movies/movie_show_list_manage', locals: {movie: @movie}) %>"); } +<%# On a list view, we need to specify the movie +so we use the movie's tmdb_id %> var $listPageDropdown = $("#myModal_<%= @movie.tmdb_id %>").find("#add-to-list-dropdown-" + "<%= @movie.tmdb_id %>"); -var $showPageDropdown = $('.list-dropdown'); -($listPageDropdown, $showPageDropdown).click(triggerClickForListAutocomplete); +($listPageDropdown).click(triggerClickForListAutocomplete); -<%# On a list view, we need to specify the movie -so we use the movie's tmdb_id %> ($listPageDropdown).autocomplete({ source: $listPageDropdown.data('autocomplete-source'), minLength: 0, @@ -25,7 +24,12 @@ so we use the movie's tmdb_id %> } }); -<%# On a show page, we have only one movie, so the selector is not tied to the movie id %> +<%# On a show page, we have only one movie, +but we still need the selector because the class is on _all_ movies %> +var $showPageDropdown = $("#movie_show_listings_" + "<%= @movie.tmdb_id %>").find("#add-to-list-dropdown-" + "<%= @movie.tmdb_id %>"); + +($showPageDropdown).click(triggerClickForListAutocomplete); + ($showPageDropdown).autocomplete({ source: $showPageDropdown.data('autocomplete-source'), minLength: 0, diff --git a/app/views/movies/_movie.html.erb b/app/views/movies/_movie.html.erb index 9507ffb1..accbe418 100644 --- a/app/views/movies/_movie.html.erb +++ b/app/views/movies/_movie.html.erb @@ -3,7 +3,6 @@