Minor refactoring for ordering js data.

This commit is contained in:
benni 2011-06-13 16:45:16 +02:00
parent f3773314a7
commit 45e0048490
2 changed files with 28 additions and 33 deletions

View file

@ -18,7 +18,7 @@ class OrderingController < ApplicationController
# save results of earlier orders in array # save results of earlier orders in array
ordered_articles = Array.new ordered_articles = Array.new
@group_order = @order.group_orders.find(:first, @group_order = @order.group_orders.find(:first,
:conditions => "ordergroup_id = #{@ordergroup.id}", :include => :group_order_articles) :conditions => "ordergroup_id = #{@ordergroup.id}", :include => :group_order_articles)
if @group_order if @group_order
# Group has already ordered, so get the results... # Group has already ordered, so get the results...
@ -56,6 +56,19 @@ class OrderingController < ApplicationController
i += 1 i += 1
end end
end end
@add_data_to_js = []
if Foodsoft.config[:tolerance_is_costly]
for i in 0...@price.size
@add_data_to_js << [@price[i], @unit[i], @price[i] * (@tolerance[i] + @quantity[i]), @others_quantity[i],
@others_tolerance[i], @used_quantity[i], 0]
end
else
for j in 0...@price.size
@add_data_to_js << [@price[j], @unit[j], @price[j] * @quantity[j], @others_quantity[j],
@others_tolerance[j], @used_quantity[j], 0]
end
end
end end
def stock_order def stock_order
@ -64,7 +77,7 @@ class OrderingController < ApplicationController
# save results of earlier orders in array # save results of earlier orders in array
ordered_articles = Array.new ordered_articles = Array.new
@group_order = @order.group_orders.find(:first, @group_order = @order.group_orders.find(:first,
:conditions => "ordergroup_id = #{@ordergroup.id}", :include => :group_order_articles) :conditions => "ordergroup_id = #{@ordergroup.id}", :include => :group_order_articles)
if @group_order if @group_order
# Group has already ordered, so get the results... # Group has already ordered, so get the results...
@ -147,7 +160,7 @@ class OrderingController < ApplicationController
logger.error('Failed to update order: ' + exception.message) logger.error('Failed to update order: ' + exception.message)
flash[:error] = 'Die Bestellung konnte nicht aktualisiert werden, da ein Fehler auftrat.' flash[:error] = 'Die Bestellung konnte nicht aktualisiert werden, da ein Fehler auftrat.'
end end
redirect_to :action => 'my_order_result', :id => @order redirect_to :action => 'my_order_result', :id => @order
end end
end end
@ -163,7 +176,7 @@ class OrderingController < ApplicationController
def myOrders def myOrders
# get only orders belonging to the ordergroup # get only orders belonging to the ordergroup
@closed_orders = Order.paginate :page => params[:page], :per_page => 10, @closed_orders = Order.paginate :page => params[:page], :per_page => 10,
:conditions => { :state => 'closed' }, :order => "orders.ends DESC" :conditions => { :state => 'closed' }, :order => "orders.ends DESC"
respond_to do |format| respond_to do |format|
format.html # myOrders.haml format.html # myOrders.haml

View file

@ -1,27 +1,9 @@
<script> <script>
//<![CDATA[ //<![CDATA[
$(function() { $(function() {
<% if Foodsoft.config[:tolerance_is_costly] <% for row in @add_data_to_js %>
for i in 0...@price.size %> addData(<%= row.join(", ") %>);
addData(<%= @price[i] %>, <% end %>
<%= @unit[i] %>,
<%= @price[i] * (@tolerance[i] + @quantity[i])%>,
<%= @others_quantity[i] %>,
<%= @others_tolerance[i] %>,
<%= @used_quantity[i] %>,
0);
<% end
else
for j in 0...@price.size -%>
addData(<%= @price[j] %>,
<%= @unit[j] %>,
<%= @price[j] * @quantity[j]%>,
<%= @others_quantity[j] %>,
<%= @others_tolerance[j] %>,
<%= @used_quantity[j] %>,
0);
<% end
end%>
setGroupBalance(<%= @availableFunds %>); setGroupBalance(<%= @availableFunds %>);
// localization // localization