diff --git a/src/pretix/control/templates/pretixcontrol/items/question_edit.html b/src/pretix/control/templates/pretixcontrol/items/question_edit.html index 200c078605..2cccced337 100644 --- a/src/pretix/control/templates/pretixcontrol/items/question_edit.html +++ b/src/pretix/control/templates/pretixcontrol/items/question_edit.html @@ -118,6 +118,10 @@

+

+ {% trans "or add options from a csv file" %} + +

diff --git a/src/pretix/static/pretixcontrol/js/ui/main.js b/src/pretix/static/pretixcontrol/js/ui/main.js index a9ea046023..413255e884 100644 --- a/src/pretix/static/pretixcontrol/js/ui/main.js +++ b/src/pretix/static/pretixcontrol/js/ui/main.js @@ -119,6 +119,25 @@ var form_handlers = function (el) { form_handlers($(event.target)); }); + el.find("#add-options-csv").on("change", function(event) { + var formset = $(this).closest('.formset'); + var addOptionButton = formset.find("button[data-formset-add]"); + for (const file of event.target.files) { + const reader = new FileReader(); + reader.addEventListener('load', (event) => { + event.target.result.split(/\r?\n/).forEach(function(line) { + if (!line) return; + var values = line.split(/[;,\t]/); + addOptionButton.trigger("click"); + formset.find("[data-formset-body]>*:last-child").find("[type=text], textarea").each(function(i) { + if (values[i]) this.value = values[i]; + }); + }); + }); + reader.readAsText(file); + } + }); + // Vouchers el.find("#voucher-bulk-codes-generate").click(function () { var num = $("#voucher-bulk-codes-num").val();