tap/app/views/orders/order.html.erb

99 lines
1.7 KiB
Text
Raw Normal View History

2014-11-23 21:12:31 +01:00
<%= current_ordering_user.name %>
2014-11-24 21:45:32 +01:00
2014-11-25 02:01:57 +01:00
2014-11-24 21:45:32 +01:00
<% @products.each do |p| %>
<%#= render "orders/order_button" %>
<!-- dit moet in een andere file -->
<button class="btn btn-default product-btn"
data-name= '<%= p.name %>'
date-price= '<%= p.sale_price %>'>
<%= p.name %>
</button>
<!-- tot hier -->
<% end %>
2014-11-25 02:01:57 +01:00
2014-11-23 21:12:31 +01:00
<%= form_for @order do |f| %>
2014-11-10 02:30:42 +01:00
<div class="field">
2014-11-25 02:01:57 +01:00
<%#= f.text_area :products , placeholder: "dit zou een hidden field moeten zijn met product JSON..." %>
2014-11-10 02:30:42 +01:00
</div>
2014-11-24 21:45:32 +01:00
<%#= hidden_field_tag "products", "return_products_string" %>
<div class="hidden"></div>
<%= f.submit "Order", class: "btn btn-primary " %>
2014-11-23 21:12:31 +01:00
<% end %>
2014-11-24 21:45:32 +01:00
<div style="padding-top: 50px;" class="order_list ">
<p>
Nothing ordered yet!
</p>
</div>
<script charset="utf-8">
var products = {};
//var product_number = 0;
$(document).ready(function() {
//Making/adding orderlist/JSON
$('.product-btn').click(function() {
//product_number++;
var name = $(this).data('name');
var price = $(this).data('price');
if(products.hasOwnProperty(name)){
products[name].number_of++;
} else{
products[name] = {
name : name,
price : price,
number_of: 1
}
}
update();
});
2014-11-25 02:01:57 +01:00
2014-11-24 21:45:32 +01:00
//updates the orderlist view
var update = function(){
2014-11-25 02:01:57 +01:00
$('.order_list').empty().append("<p>Ordered: </p>" + JSON.stringify(products) );
2014-11-24 21:45:32 +01:00
jQuery.each(products, function(i, product) {
$(".order_list").append("<p> - "+ i +": "+ product.number_of +"</p>");
});
2014-11-25 02:01:57 +01:00
$('.hidden').empty().append("<input id='order_products' name='order[products]' type='hidden' value="+ JSON.stringify(products) +" />")
2014-11-24 21:45:32 +01:00
}
});
</script>