From c31e864c73549a15f3f84938e021ac39bcd78d55 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 26 Jun 2013 01:17:04 +0200 Subject: [PATCH] internationalise currency in order screen --- app/assets/javascripts/ordering.js | 12 ++++++++---- app/views/group_orders/_form.html.haml | 11 ++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/ordering.js b/app/assets/javascripts/ordering.js index a75d0541..1a1421bd 100644 --- a/app/assets/javascripts/ordering.js +++ b/app/assets/javascripts/ordering.js @@ -7,7 +7,9 @@ var modified = false // indicates if anything has been clicked on this page var groupBalance = 0; // available group money -var decimalSeparator = "."; // default decimal separator +var currencySeparator = "."; // default decimal separator +var currencyPrecision = 2; // default digits behind comma +var currencyUnit = "€"; // default currency var toleranceIsCostly = true; // default tolerance behaviour var isStockit = false; // Wheter the order is from stock oder normal supplier @@ -20,8 +22,10 @@ var toleranceOthers = new Array(); var itemsAllocated = new Array(); // how many items the group has been allocated and should definitely get var quantityAvailable = new Array(); // stock_order. how many items are currently in stock -function setDecimalSeparator(character) { - decimalSeparator = character; +function setCurrencyFormat(separator, precision, unit) { + currencySeparator = separator; + currencyPrecision = precision; + currencyUnit = unit; } function setToleranceBehaviour(value) { @@ -129,7 +133,7 @@ function update(item, quantity, tolerance) { } function asMoney(amount) { - return String(amount.toFixed(2)).replace(/\./, ","); + return String(amount.toFixed(currencyPrecision)).replace(/\./, currencySeparator) + ' ' + currencyUnit; } function calcUnits(unitSize, quantity, tolerance) { diff --git a/app/views/group_orders/_form.html.haml b/app/views/group_orders/_form.html.haml index 0cfc0caa..2939a689 100644 --- a/app/views/group_orders/_form.html.haml +++ b/app/views/group_orders/_form.html.haml @@ -3,7 +3,7 @@ $(function() { #{data_to_js(@ordering_data)} setGroupBalance(#{@ordering_data[:available_funds]}); - setDecimalSeparator(","); + setCurrencyFormat("#{t('number.currency.format.separator')}", #{t('number.currency.format.precision')}, "#{t('number.currency.format.unit')}"); setToleranceBehaviour(#{FoodsoftConfig[:tolerance_is_costly]}); setStockit(#{@order.stockit?}); }); @@ -97,8 +97,7 @@ %input{type: 'button', value: '-', 'data-decrease_tolerance' => order_article.id} %td{id: "td_price_#{order_article.id}", style: "text-align:right; padding-right:10px; width:4em"} - %span{id: "price_#{order_article.id}_display"}= number_to_currency(@ordering_data[:order_articles][order_article.id][:total_price], unit: "") - € + %span{id: "price_#{order_article.id}_display"}= number_to_currency(@ordering_data[:order_articles][order_article.id][:total_price]) .article-info .article-name= order_article.article.name .pull-right @@ -125,8 +124,7 @@ %tr %td= t('.total_sum_amount') + ':' %td.currency - %span#total_price= @group_order.price - € + %span#total_price= number_to_currency(@group_order.price) %tr %td= t('.available_funds') + ':' %td.currency= number_to_currency(@ordering_data[:available_funds]) @@ -134,8 +132,7 @@ %td= t('.new_funds') + ':' %td.currency %strong - %span#new_balance= @ordering_data[:available_funds] - @group_order.price - € + %span#new_balance= number_to_currency(@ordering_data[:available_funds] - @group_order.price) #order-button = submit_tag( t('.action_save'), id: 'submit_button', class: 'btn btn-primary' ) #{link_to t('ui.or_cancel'), group_orders_path}