|
| 1 | +<header> |
| 2 | + <h1> |
| 3 | + Artists |
| 4 | + <%= button_to 'New Artist', new_artist_path, method: 'get', tabindex: 5 %> |
| 5 | + </h1> |
| 6 | +</header> |
| 7 | + |
| 8 | +<section id="searchbox"> |
| 9 | +<%= form_tag search_path, method: 'get' do %> |
| 10 | + <input type="text" name="q" value="<%= params[:q] %>" id="q" autofocus="autofocus" placeholder="start typing to search..." tabindex="0" /> |
| 11 | +<% end %> |
| 12 | +</section> |
| 13 | + |
| 14 | +<section class="artists"> |
| 15 | + <% @artists.each do |artist| %> |
| 16 | + <%= div_for artist, class: 'result clearfix' do %> |
| 17 | + <h2> |
| 18 | + <%= link_to artist do %> |
| 19 | + <span class="name"><%= artist.name %></span> |
| 20 | + <small><%= pluralize artist.album_count, 'album' %></small> |
| 21 | + <% end %> |
| 22 | + </h2> |
| 23 | + <div class="actions clearfix"> |
| 24 | + <%= button_to 'Edit', edit_artist_path(artist), method: 'get' %> |
| 25 | + <%= button_to 'Destroy', artist, method: :delete, data: { confirm: 'Are you sure?' } %> |
| 26 | + </div> |
| 27 | + <% end %> |
| 28 | + <% end %> |
| 29 | +</section> |
| 30 | + |
| 31 | +<% if @artists.empty? %> |
| 32 | +<section class="no-results"> |
| 33 | + <p>The search hasn't returned any results...</p> |
| 34 | +</section> |
| 35 | +<% end %> |
| 36 | + |
| 37 | +<script> |
| 38 | +$.widget( "custom.suggest", $.ui.autocomplete, { |
| 39 | + _renderMenu: function( ul, items ) { |
| 40 | + $.each( items, function( index, item ) { |
| 41 | + var category = ul.append( "<li class='ui-autocomplete-category'>" + item.label + "</li>" ); |
| 42 | + |
| 43 | + $.each( item.value, function( index, item ) { |
| 44 | + var li = $('<li class="ui-autocomplete-item"><a href="<%= Rails.application.config.relative_url_root %>'+ item.payload.url +'">'+ item.text +'</a></li>').data('ui-autocomplete-item', item ) |
| 45 | + category.append(li) |
| 46 | + } ) |
| 47 | + }); |
| 48 | + } |
| 49 | + }); |
| 50 | + |
| 51 | +$( "#q" ).suggest({ |
| 52 | + source: '<%= suggest_path %>', |
| 53 | + select: function(event, ui) { |
| 54 | + document.location.href = '<%= Rails.application.config.relative_url_root %>'+ui.item.payload.url |
| 55 | + } |
| 56 | +}); |
| 57 | +</script> |
0 commit comments