mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add localizeCurrency filter to admin and inject currencyConfig data
This commit is contained in:
@@ -1 +1 @@
|
||||
angular.module("admin.subscriptions", ['ngResource','admin.indexUtils','admin.dropdown'])
|
||||
angular.module("admin.subscriptions", ['ngResource','admin.indexUtils','admin.dropdown', 'admin.utils'])
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
angular.module("admin.utils").filter "localizeCurrency", (currencyConfig)->
|
||||
# Convert number to string currency using injected currency configuration.
|
||||
(amount) ->
|
||||
# Set country code (eg. "US").
|
||||
currency_code = if currencyConfig.display_currency then " " + currencyConfig.currency else ""
|
||||
# Set decimal points, 2 or 0 if hide_cents.
|
||||
decimals = if currencyConfig.hide_cents == "true" then 0 else 2
|
||||
# Set format if the currency symbol should come after the number, otherwise (default) use the locale setting.
|
||||
format = if currencyConfig.symbol_position == "after" then "%n %u" else undefined
|
||||
# We need to use parseFloat as the amount should come in as a string.
|
||||
amount = parseFloat(amount)
|
||||
|
||||
# Build the final price string.
|
||||
I18n.toCurrency(amount, {precision: decimals, unit: currencyConfig.symbol, format: format}) + currency_code
|
||||
@@ -65,6 +65,10 @@ module Admin
|
||||
admin_inject_json_ams_array opts[:module], "columns", column_preferences, Api::Admin::ColumnPreferenceSerializer
|
||||
end
|
||||
|
||||
def admin_inject_currency_config
|
||||
admin_inject_json_ams 'admin.utils', "currencyConfig", {}, Api::CurrencyConfigSerializer
|
||||
end
|
||||
|
||||
def admin_inject_enterprise_permissions
|
||||
permissions =
|
||||
{can_manage_shipping_methods: can?(:manage_shipping_methods, @enterprise),
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
/ insert_before "div#wrapper"
|
||||
|
||||
= admin_inject_currency_config
|
||||
Reference in New Issue
Block a user