mirror of
https://github.com/pretix/pretix.git
synced 2026-05-09 15:54:03 +00:00
committed by
GitHub
parent
6304b34600
commit
c71ba79e55
@@ -14,6 +14,43 @@ function ngettext(singular, plural, count) {
|
|||||||
return plural;
|
return plural;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatPrice(price, currency, locale) {
|
||||||
|
if (!window.Intl || !Intl.NumberFormat) return price;
|
||||||
|
var priceToFormat = price
|
||||||
|
if (currency === undefined) {
|
||||||
|
currency = $("[data-currency]").data("currency")
|
||||||
|
}
|
||||||
|
if (locale === undefined) {
|
||||||
|
locale = $("[data-locale]").data("locale") || $("[data-pretixlocale]").data("pretixlocale");
|
||||||
|
}
|
||||||
|
|
||||||
|
var opt = currency ? {style: "currency", currency: currency} : null;
|
||||||
|
var nf = new Intl.NumberFormat(locale, opt)
|
||||||
|
|
||||||
|
if (isNaN(priceToFormat) && priceToFormat.replaceAll) {
|
||||||
|
// price is not a number, try to reformat based on locale/currency-format
|
||||||
|
var replacements = {
|
||||||
|
group: "",
|
||||||
|
decimal: "."
|
||||||
|
}
|
||||||
|
// format a dummy number to get parts of formatting and
|
||||||
|
// replace group and decimal according to replacements
|
||||||
|
// to hopefully get a parsable number
|
||||||
|
nf.formatToParts(1234.567).forEach(function(part) {
|
||||||
|
if (replacements.hasOwnProperty(part.type)) {
|
||||||
|
priceToFormat = priceToFormat.replaceAll(part.value, replacements[part.type])
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (isNaN(priceToFormat)) return price
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return nf.format(priceToFormat)
|
||||||
|
} catch (error) {
|
||||||
|
return price
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var waitingDialog = {
|
var waitingDialog = {
|
||||||
show: function (message) {
|
show: function (message) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*global $, Morris, gettext*/
|
/*global $, Morris, gettext, formatPrice*/
|
||||||
$(function () {
|
$(function () {
|
||||||
// Question view
|
// Question view
|
||||||
if (!$("#item_variations").length) {
|
if (!$("#item_variations").length) {
|
||||||
@@ -8,7 +8,10 @@ $(function () {
|
|||||||
function update_variation_summary($el) {
|
function update_variation_summary($el) {
|
||||||
var var_name = $el.find("input[name*=-value_]").filter(function () {return !!this.value}).first().val();
|
var var_name = $el.find("input[name*=-value_]").filter(function () {return !!this.value}).first().val();
|
||||||
var price = $el.find("input[name*=-default_price]").val();
|
var price = $el.find("input[name*=-default_price]").val();
|
||||||
|
if (price) {
|
||||||
|
var currency = $el.find("[name*=-default_price] + .input-group-addon").text();
|
||||||
|
price = formatPrice(price, currency);
|
||||||
|
}
|
||||||
|
|
||||||
$el.find(".variation-name").text(var_name);
|
$el.find(".variation-name").text(var_name);
|
||||||
$el.find(".variation-price").text(price);
|
$el.find(".variation-price").text(price);
|
||||||
|
|||||||
Reference in New Issue
Block a user