diff --git a/src/pretix/control/forms/vouchers.py b/src/pretix/control/forms/vouchers.py index 1d7d405ccd..ff0c4a6ca9 100644 --- a/src/pretix/control/forms/vouchers.py +++ b/src/pretix/control/forms/vouchers.py @@ -87,7 +87,7 @@ class VoucherBulkForm(VoucherForm): widget=forms.Textarea, label=_("Codes"), help_text=_( - "Add one voucher code per line" + "Add one voucher code per line. We suggest that you copy this list and save it into a file." ) ) diff --git a/src/pretix/control/templates/pretixcontrol/vouchers/bulk.html b/src/pretix/control/templates/pretixcontrol/vouchers/bulk.html index 81274e3939..bf8c15fe4c 100644 --- a/src/pretix/control/templates/pretixcontrol/vouchers/bulk.html +++ b/src/pretix/control/templates/pretixcontrol/vouchers/bulk.html @@ -9,6 +9,20 @@ {% bootstrap_form_errors form %}
{% trans "Voucher codes" %} +
+
+
+ +
+ +
+
+
+
{% bootstrap_field form.codes layout="horizontal" %}
diff --git a/src/static/pretixcontrol/js/ui/main.js b/src/static/pretixcontrol/js/ui/main.js index 980462328f..3ae93ecb90 100644 --- a/src/static/pretixcontrol/js/ui/main.js +++ b/src/static/pretixcontrol/js/ui/main.js @@ -53,4 +53,29 @@ $(function () { $("#id_required").change(question_page_toggle_view); question_page_toggle_view(); } + + // Vouchers + $("#voucher-bulk-codes-generate").click(function () { + var charset = "ABCDEFGHKLMNPQRSTUVWXYZ23456789", + i = 0, j = 0, len = 16, + num = parseInt($("#voucher-bulk-codes-num").val()), text = ""; + for (j = 0; j < num; j++) { + var key = []; + if (window.crypto && window.crypto.getRandomValues && Uint8Array) { + key = new Uint8Array(len); + window.crypto.getRandomValues(key); + } else { + for (i = 0; i < len; i++) { + key.push(Math.floor(Math.random() * charset.length)); + } + } + if (i > 0) { + text += "\n"; + } + for (i = 0; i < len; i++) { + text += charset.charAt(key[i] % charset.length); + } + } + $("#id_codes").html(text); + }); });