Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.16 KB | None | 0 0
  1. <div class="new-list">
  2.     <h2>New List</h2>
  3.     <%= form_for @list, url: list_path, html: {class: "form-signin"} do |f| %>
  4.         <%= f.text_field :name, placeholder: "Name your list (optional)" %>
  5.         <!-- Category -->
  6.         <div class="categories">
  7.             <% current_user.categories.each do |category| %>
  8.                 <h3 class="category">
  9.                   <%= category.name %>
  10.                 </h3>
  11.                 <!-- Items -->  
  12.                 <div class="dropdown-button" data-toggle="collapse" data-target="#<%= category.name %>">
  13.                     <span class="glyphicon glyphicon-chevron-down"></span>
  14.                 </div>
  15.                 <!-- Dropdown div -->
  16.                 <div id="<%= category.name %>" class="collapse">
  17.                     <div class="table-responsive">
  18.                         <!-- User Item table -->
  19.                         <table class="items">
  20.                             <tr>
  21.                                 <th>Add</th>
  22.                                 <th>Name</th>
  23.                                 <th>Price</th>
  24.                                 <th>Qnty</th>
  25.                             </tr>
  26.                         <% category.user_items.each do |item| %>
  27.                             <%= f.fields_for l = @list.list_items.build, index: l.id do |list_item| %>
  28.                                 <% @category = category %>
  29.                                 <% @f = f %>
  30.                                 <tr>
  31.                                     <td><%= list_item.check_box :user_item_id, { checked: false }, item.id, nil %></td>
  32.                                     <td><%= item.name %></td>
  33.                                     <td><%= item.price %></td>
  34.                                     <td><%= list_item.number_field :quantity,
  35.                                                                                                     min: 1,
  36.                                                                                                     class: "num"%></td>
  37.                                 </tr>
  38.                             <% end %>
  39.                         <% end %>
  40.                       </table>
  41.                     </div>
  42.                     <h3>Create a new item here:</h3>
  43.                     <%= render partial: 'shared/user_item_form', locals: {f: f, category_id: category.id}  %>
  44.                     <h4><span class="glyphicon glyphicon-plus" id="add-item"></span>Add More</h4>
  45.                 </div>
  46.             <% end %> <!-- current_user.categories -->
  47.             <br>
  48.             <%= f.submit "Submit" %>
  49.         </div>
  50.     <% end %>
  51. </div>
  52.  
  53. <!-- dropdown button script -->
  54. <script>
  55.   $(document).ready(function () {
  56.       $('.data-toggle').collapse();
  57.       addNewItemForm();
  58.   });
  59.  
  60. function addNewItemForm(){
  61.   $('#add-item').click(function(){
  62.         $(this).parents(':eq(1)').append("<%= escape_javascript render partial: 'shared/user_item_form', locals: {f: @f, category_id: @category.id} %>");
  63.   });
  64. }
  65. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement