Bug 27796: (QA follow-up) Missing filters
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / includes / format_price.inc
1 [% USE Koha %]
2 <!-- format-price.inc -->
3 <script>
4     [%# This should use the Format template plugin, but not pushed yet %]
5     [% IF Koha.Preference("CurrencyFormat") == 'FR' %]
6         var default_value = {
7             thousands_sep: ' ',
8             decimal_point: ',',
9             decimal_digits: 2
10         };
11     [% ELSIF Koha.Preference("CurrencyFormat") == 'CH' %]
12         var default_value = {
13             thousands_sep: '\'',
14             decimal_point: '.',
15             decimal_digits: 2
16         };
17     [% ELSE %]
18         var default_value = {
19             thousands_sep: ',',
20             decimal_point: '.',
21             decimal_digits: 2
22         };
23
24     [% END %]
25     Number.prototype.format_price = function( value, params ) {
26         params = params == undefined ? {} : params;
27         var thousands_sep = params.thousands_sep == undefined ? default_value.thousands_sep : params.thousands_sep,
28             decimal_point = params.decimal_point == undefined ? default_value.decimal_point : params.decimal_point,
29             //symbol = params.symbol == undefined ? '$' : params.symbol, // Not implemented yet
30             decimal_digits = params.decimal_digits == undefined ? default_value.decimal_digits : params.decimal_digits;
31
32             var re = '\\d(?=(\\d{' + 3 + '})+' + '\\D' + ')', value = this.toFixed(decimal_digits);
33             return value.replace('.', decimal_point).replace(new RegExp(re, 'g'), '$&' + thousands_sep);
34     }
35 </script>
36 <!-- / format-price.inc -->