Skip to content

Commit

Permalink
212: Specify movie id for selector on show page after create
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevallano committed Aug 18, 2020
1 parent 10ff61d commit d3f3ca8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/z.js
Expand Up @@ -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,
Expand Down
24 changes: 14 additions & 10 deletions 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,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion app/views/movies/_movie.html.erb
Expand Up @@ -3,7 +3,6 @@
<div class="modal fade movie-modal"
id="myModal_<%= movie.tmdb_id %>"
data-movie-id="<%= movie.tmdb_id %>"
data-kits='zorro'
tabindex="-1"
role="dialog"
>
Expand Down

0 comments on commit d3f3ca8

Please sign in to comment.