add currency localisation

This commit is contained in:
Rafael Schouten
2014-09-03 17:23:53 +10:00
parent 0fd496aa97
commit 991d0029dd
17 changed files with 86 additions and 16903 deletions

View File

@@ -0,0 +1,17 @@
# Convert number to string currency using injected currency localisation settings.
#
# Injected: currencyLocalisation - see /app/serializers/api/currency_localization_serializer.rb
Darkswarm.filter "localiseCurrency", (currencyLocalization)->
(amount) ->
decimals = if currencyLocalization.hide_cents then 0 else 2
amount_fixed = amount.toFixed(decimals)
currency_str = ""
currency_str = " " + currencyLocalization.currency if currencyLocalization.display_currency
# Return string
if currencyLocalization.symbol_position == 'before'
currencyLocalization.symbol + amount_fixed + currency_str
else
amount_fixed + " " + currencyLocalization.symbol + currency_str

View File

@@ -6,6 +6,6 @@ Darkswarm.factory 'Variants', ->
extend: (variant)->
variant.getPrice = ->
variant.price * variant.line_item.quantity
variant.basePricePercentage = Math.round(variant.base_price / variant.price * 100)
variant.price_with_fees * variant.line_item.quantity
variant.basePricePercentage = Math.round(variant.price / variant.price_with_fees * 100)
variant

View File

@@ -10,26 +10,26 @@
.expanded{"ng-show" => "expanded"}
%ul
%li.cost
.right {{ variant.base_price | currency }}
.right {{ variant.price | localiseCurrency }}
Item cost
%li{"bo-if" => "variant.fees.admin"}
.right {{ variant.fees.admin | currency }}
.right {{ variant.fees.admin | localiseCurrency }}
Admin fee
%li{"bo-if" => "variant.fees.sales"}
.right {{ variant.fees.sales | currency }}
.right {{ variant.fees.sales | localiseCurrency }}
Sales fee
%li{"bo-if" => "variant.fees.packing"}
.right {{ variant.fees.packing | currency }}
.right {{ variant.fees.packing | localiseCurrency }}
Packing fee
%li{"bo-if" => "variant.fees.transport"}
.right {{ variant.fees.transport | currency }}
.right {{ variant.fees.transport | localiseCurrency }}
Transport fee
%li{"bo-if" => "variant.fees.fundraising"}
.right {{ variant.fees.fundraising | currency }}
.right {{ variant.fees.fundraising | localiseCurrency }}
Fundraising fee
%li
%strong
.right = {{ variant.price | currency }}
.right = {{ variant.price | localiseCurrency }}
 
%a{"ng-click" => "expanded = !expanded"}

View File

@@ -48,7 +48,7 @@
.small-4.medium-2.large-2.columns.variant-price
.table-cell.price
%i.ofn-i_009-close
{{ variant.price | currency }}
{{ variant.price | localiseCurrency }}
-# Now in a template in app/assets/javascripts/templates !
%price-breakdown{"price-breakdown" => "_", variant: "variant",
@@ -59,4 +59,4 @@
.small-12.medium-2.large-2.columns.total-price.text-right
.table-cell
%strong
{{ variant.getPrice() | currency }}
{{ variant.getPrice() | localiseCurrency }}