Skip to content

Commit

Permalink
Update to use AJAX for featuring and unfeaturing products.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelsey Langlois and LDevinMacKrell committed Dec 7, 2017
1 parent 1915e65 commit 34f1fc9
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -79,7 +79,6 @@ To install on your own machine, follow the instructions below:
* Confirmation email once order shipped

* Shipping and taxes (APIs)
* X Sales tax added and calculated for shopping cart (Avalara's Tax Rate API)
* USPS's shipping rate for a product (rate calculator API. XML not JSON. Can also use Stripe API)
* Random API of our choice
@@ -90,7 +89,6 @@ To install on your own machine, follow the instructions below:
* Paginate results
* Change page without refresh
* Admin:
* Product CRUD without refresh
* Mark items as featured without refresh
## Support and contact details
4 changes: 2 additions & 2 deletions app/views/products/_show.html.erb
Original file line number Diff line number Diff line change
@@ -43,9 +43,9 @@
<hr>
<p>
<% if !@product.featured %>
<%= link_to "Feature", product_path(product: { id: @product.id, featured: true}), data: { method: "patch" } %> |
<%= link_to "Feature", product_path(product: { id: @product.id, featured: true}), id: "add_feature", remote: true, data: { method: "patch" } %> |
<% else %>
<%= link_to "End Feature", product_path(product: { id: @product.id, featured: false}), data: { method: "patch" } %> |
<%= link_to "End Feature", product_path(product: { id: @product.id, featured: false}), id: "remove_feature", remote: true, data: { method: "patch" } %> |
<% end %>
<%= link_to "Edit", edit_product_path(@product), id: "product-edit", remote: true %> |
<%= link_to "Delete", product_path(@product), remote: true, data: {
12 changes: 7 additions & 5 deletions app/views/products/index.html.erb
Original file line number Diff line number Diff line change
@@ -5,11 +5,13 @@

<% if @featured.any? %>
<h1>Featured</h1>
<% @featured.each do |product| %>
<div class="product-feature">
<h3><%= link_to product.name, product_path(product) %></h3>
</div>
<% end %>
<div class="featured-products">
<% @featured.each do |product| %>
<div class="product-feature" id="feature-<%= product.id %>">
<h3><%= link_to product.name, product_path(product) %></h3>
</div>
<% end %>
</div>
<% end %>

<% if @discounted.any? %>
9 changes: 9 additions & 0 deletions app/views/products/update.js.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
$('#product-details-<%= @product.id %>').after("<%= j render 'show' %>");
$('#product-details-<%= @product.id %>').remove();
$('#edit_product_<%= @product.id %>').before("<%= j render 'show' %>");
$('#edit_product_<%= @product.id %>').remove();
$('#hide_details_<%= @product.id %>').click(function() {
$('#product-details-<%= @product.id %>').before('<%= j render @product %>')
$('#product-details-<%= @product.id %>').remove();
});

<% if @product.featured %>
$('#feature-<%= @product.id %>').remove();
$('.featured-products').prepend('<div class="product-feature" id="feature-<%= @product.id %>"><h3><%= link_to @product.name, product_path(@product) %></h3></div>');
<% else %>
$('#feature-<%= @product.id %>').remove();
<% end %>

0 comments on commit 34f1fc9

Please sign in to comment.