spree-contrib/spree-product-assembly

View on GitHub
app/views/spree/admin/parts/available.html.erb

Summary

Maintainability
Test Coverage
<h4><%= Spree.t(:available_parts) %></h4>
<table class="table">
  <thead>
    <tr>
      <th><%= Spree.t(:name) %></th>
      <th><%= Spree.t(:options) %></th>
      <th><%= Spree.t(:variants) %></th>
      <th><%= Spree.t(:qty) %></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <% @available_products.each do |part| %>
      <tr id="<%= dom_id(part) %>"
        class="<%= "with-variants" if part.has_variants? %>">

        <td><%= part.name %></td>
        <td>
          <% if part.has_variants? %>
            <%- opts = part.variants.map {|v| [v.options_text, v.id] } %>
            <%= select_tag "part[id]",
              options_for_select(opts),
              include_blank: Spree.t(:user_selectable), class: 'part_selector select2'
            %>
          <% else %>
            <%= hidden_field_tag "part[id]", part.master.id %>
            <%= Spree.t(:no_variants) %>
          <% end %>
        </td>
        <% unless product.has_variants? %>
          <td><%= hidden_field_tag "part[assembly_id]", product.master.id, class: 'parts-assembly' %>Master</td>
        <% else %>
          <td><%= select_tag "part[assembly_id]", options_from_collection_for_select(product.variants, "id", "options_text"), class: 'select2' %></td>
        <% end %>
        <td><%= text_field_tag "part[count]", 1 %></td>
        <td class="actions">
          <%= image_tag "spinner.gif", :style => "display:none", :class => "spinner" %>
          <%= link_to_with_icon('add', Spree.t(:select),
                      admin_product_parts_path(product),
                      :data => { 'target' => dom_id(part), 'master-variant-id' => part.master.id},
                      :class => "add_product_part_link") %>
        </td>
      </tr>
    <% end %>
    <% if @available_products.empty? %>
     <tr><td colspan="3"><%= Spree.t(:no_match_found) %>.</td></tr>
    <% end %>
  </tbody>
</table>