Minor refactoring for ordering js data.
This commit is contained in:
parent
f3773314a7
commit
45e0048490
2 changed files with 28 additions and 33 deletions
|
@ -4,11 +4,11 @@ class OrderingController < ApplicationController
|
||||||
# Security
|
# Security
|
||||||
before_filter :ensure_ordergroup_member
|
before_filter :ensure_ordergroup_member
|
||||||
before_filter :ensure_open_order, :only => [:order, :stock_order, :saveOrder]
|
before_filter :ensure_open_order, :only => [:order, :stock_order, :saveOrder]
|
||||||
|
|
||||||
# Index page.
|
# Index page.
|
||||||
def index
|
def index
|
||||||
end
|
end
|
||||||
|
|
||||||
# Edit a current order.
|
# Edit a current order.
|
||||||
def order
|
def order
|
||||||
redirect_to :action => 'stock_order', :id => @order if @order.stockit?
|
redirect_to :action => 'stock_order', :id => @order if @order.stockit?
|
||||||
|
@ -17,8 +17,8 @@ class OrderingController < ApplicationController
|
||||||
@articles_grouped_by_category = @order.articles_grouped_by_category
|
@articles_grouped_by_category = @order.articles_grouped_by_category
|
||||||
# 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...
|
||||||
|
@ -98,7 +111,7 @@ class OrderingController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update changes to a current order.
|
# Update changes to a current order.
|
||||||
def saveOrder
|
def saveOrder
|
||||||
if (params[:total_balance].to_i < 0) #TODO: Better use a real test on sufficiant funds
|
if (params[:total_balance].to_i < 0) #TODO: Better use a real test on sufficiant funds
|
||||||
|
@ -147,30 +160,30 @@ 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
|
||||||
|
|
||||||
# Shows the Result for the Ordergroup the current user belongs to
|
# Shows the Result for the Ordergroup the current user belongs to
|
||||||
# this method decides between finished and unfinished orders
|
# this method decides between finished and unfinished orders
|
||||||
def my_order_result
|
def my_order_result
|
||||||
@order= Order.find(params[:id])
|
@order= Order.find(params[:id])
|
||||||
@group_order = @order.group_order(@ordergroup)
|
@group_order = @order.group_order(@ordergroup)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Shows all Orders of the Ordergroup
|
# Shows all Orders of the Ordergroup
|
||||||
# if selected, it shows all orders of the foodcoop
|
# if selected, it shows all orders of the foodcoop
|
||||||
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
|
||||||
format.js { render :partial => "orders", :locals => {:orders => @closed_orders, :pagination => true} }
|
format.js { render :partial => "orders", :locals => {:orders => @closed_orders, :pagination => true} }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# adds a Comment to the Order
|
# adds a Comment to the Order
|
||||||
def add_comment
|
def add_comment
|
||||||
order = Order.find(params[:id])
|
order = Order.find(params[:id])
|
||||||
|
@ -185,7 +198,7 @@ class OrderingController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Returns true if @current_user is member of an Ordergroup.
|
# Returns true if @current_user is member of an Ordergroup.
|
||||||
# Used as a :before_filter by OrderingController.
|
# Used as a :before_filter by OrderingController.
|
||||||
def ensure_ordergroup_member
|
def ensure_ordergroup_member
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue