Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace new product inline form with normal form #2493

Merged
merged 6 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions backend/app/views/spree/admin/products/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

<div data-hook="admin_product_form_slug">
<%= f.field_container :slug do %>
<%= f.label :slug, class: 'required' %>
<%= f.text_field :slug, class: 'fullwidth title', required: true %>
<%= f.label :slug, class: ('required' if !f.object.new_record?) %>
<%= f.text_field :slug, class: 'fullwidth title', required: !f.object.new_record?, disabled: f.object.new_record? %>
<%= f.error_message_on :slug %>
<% end %>
</div>
Expand Down Expand Up @@ -122,9 +122,9 @@

<div data-hook="admin_product_form_shipping_categories">
<%= f.field_container :shipping_categories do %>
<%= f.label :shipping_category_id, Spree::ShippingCategory.model_name.human %>
<%= f.label :shipping_category_id, Spree::ShippingCategory.model_name.human, class: 'required' %>
<%= f.field_hint :shipping_category %>
<%= f.collection_select(:shipping_category_id, @shipping_categories, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select' }) %>
<%= f.collection_select(:shipping_category_id, @shipping_categories, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select' , required: true}) %>
<%= f.error_message_on :shipping_category %>
<% end %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions backend/app/views/spree/admin/products/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<% admin_breadcrumb(plural_resource_name(Spree::Product)) %>

<% content_for :page_actions do %>
<li id="new_product_link">
<%= button_link_to t('spree.new_product'), new_object_url, { remote: true, id: 'admin_new_product' } %>
<li>
<%= button_link_to t('spree.new_product'), new_object_url %>
</li>
<% end if can?(:create, Spree::Product) %>

Expand Down
62 changes: 4 additions & 58 deletions backend/app/views/spree/admin/products/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,68 +1,14 @@
<% admin_breadcrumb link_to(plural_resource_name(Spree::Product), spree.admin_products_path) %>
<% admin_breadcrumb t('spree.new_product') %>

<%= render partial: 'spree/shared/error_messages', locals: { target: @product } %>

<%= form_for [:admin, @product], method: :post, url: admin_products_path, html: { multipart: true } do |f| %>

<fieldset data-hook="new_product">

<legend align="center"><%= t('spree.new_product') %></legend>

<%= f.field_container :name do %>
<%= f.label :name, class: 'required' %><br />
<%= f.text_field :name, class: 'fullwidth title', required: true %>
<%= f.error_message_on :name %>
<% end %>

<div data-hook="new_product_attrs" class="row">
<% unless @product.has_variants? %>
<div data-hook="new_product_sku" class="col-3">
<%= f.field_container :sku do %>
<%= f.label :sku, t('spree.sku') %><br />
<%= f.text_field :sku, size: 16, class: 'fullwidth' %>
<%= f.error_message_on :sku %>
<% end %>
</div>
<% end %>

<div data-hook="new_product_price" class="col-3">
<%= f.field_container :price do %>
<%= f.label :price, class: 'required' %><br />
<%= f.text_field :price, value: number_to_currency(@product.price, unit: ''), class: 'fullwidth', required: true %>
<%= f.error_message_on :price %>
<% end %>
</div>

<div data-hook="new_product_available_on" class="col-3">
<%= f.field_container :available_on do %>
<%= f.label :available_on %>
<%= f.error_message_on :available_on %>
<%= f.text_field :available_on, class: 'datepicker fullwidth' %>
<% end %>
</div>

</div>

<div class='row'>
<div data-hook="new_product_shipping_category" class="col-3">
<%= f.field_container :shipping_category do %>
<%= f.label :shipping_category_id, Spree::ShippingCategory.
model_name.human, class: 'required' %>
<%= f.field_hint :shipping_category %><br />
<%= f.collection_select(:shipping_category_id, @shipping_categories, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select fullwidth' }) %>
<%= f.error_message_on :shipping_category_id %>
<% end %>
</div>

<div data-hook="new_product_tax_category" class="col-3">
<%= f.field_container :tax_category do %>
<%= f.label :tax_category_id, Spree::TaxCategory.model_name.human %>
<%= f.field_hint :tax_category %>
<%= f.collection_select(:tax_category_id, @tax_categories, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select fullwidth' }) %>
<%= f.error_message_on :tax_category %>
<% end %>
</div>
</div>
<%= render partial: 'form', locals: { f: f } %>

<%= render partial: 'spree/admin/shared/new_resource_links' %>

</fieldset>
<% end %>
4 changes: 0 additions & 4 deletions backend/app/views/spree/admin/products/new.js.erb

This file was deleted.

7 changes: 2 additions & 5 deletions backend/spec/features/admin/products/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ def build_option_type_with_values(name, values)
before(:each) do
@shipping_category = create(:shipping_category)
click_nav "Products"
click_link "admin_new_product"
within('#new_product') do
expect(page).to have_content("SKU")
end
click_on "New Product"
end

it "should allow an admin to create a new product", js: true do
Expand All @@ -174,7 +171,7 @@ def build_option_type_with_values(name, values)
expect(page).to have_content("successfully updated!")
end

it "should show validation errors", js: true do
it "should show validation errors", js: false do
fill_in "product_name", with: "Baseball Cap"
fill_in "product_sku", with: "B100"
fill_in "product_price", with: "100"
Expand Down