small link_to_ordering refactoring

This commit is contained in:
wvengen 2013-11-25 10:04:44 +01:00
parent de9453fa24
commit 810656a53b
2 changed files with 12 additions and 14 deletions

View file

@ -7,24 +7,20 @@ module GroupOrdersHelper
}.join("\n") }.join("\n")
end end
# Returns a link to the page where a group_order can be edited.
# If the option :show is true, the link is for showing the group_order.
def link_to_ordering(order, options = {}) def link_to_ordering(order, options = {})
path = if group_order = order.group_order(current_user.ordergroup) group_order = order.group_order(current_user.ordergroup)
path = if options[:show] and group_order
group_order_path(group_order)
elsif group_order
edit_group_order_path(group_order, :order_id => order.id) edit_group_order_path(group_order, :order_id => order.id)
else else
new_group_order_path(:order_id => order.id) new_group_order_path(:order_id => order.id)
end end
link_to order.name, path, options options.delete(:show)
end name = block_given? ? yield(order, group_order) : order.name
path ? link_to(name, path, options) : name
def link_to_ordering_price(order, options = {})
if group_order = order.group_order(current_user.ordergroup)
price = group_order.price
path = group_order_path(group_order)
else
price = 0
path = new_group_order_path(:order_id => order.id)
end
link_to number_to_currency(price), path, options
end end
# Return css class names for order result table # Return css class names for order result table

View file

@ -20,7 +20,9 @@
- if group_order = order.group_order(ordergroup) - if group_order = order.group_order(ordergroup)
- total += group_order.price - total += group_order.price
%td= "#{group_order.updated_by.nick} (#{format_time(group_order.updated_on)})" %td= "#{group_order.updated_by.nick} (#{format_time(group_order.updated_on)})"
%td.numeric= link_to_ordering_price(order) %td.numeric
= link_to_ordering(order, show: true) do
- number_to_currency(group_order.price)
- else - else
%td{:colspan => 2} %td{:colspan => 2}
- if total > 0 - if total > 0