diff --git a/src/pretix/presale/views/questions.py b/src/pretix/presale/views/questions.py
index 610ebe26f5..321e9cb2fe 100644
--- a/src/pretix/presale/views/questions.py
+++ b/src/pretix/presale/views/questions.py
@@ -13,7 +13,7 @@ class QuestionsViewMixin(BaseQuestionsViewMixin):
@cached_property
def _positions_for_questions(self):
- qqs = Question.objects.all()
+ qqs = self.request.event.questions.all()
if self.only_user_visible:
qqs = qqs.filter(ask_during_checkin=False)
cart = get_cart(self.request).select_related(
@@ -33,7 +33,7 @@ class QuestionsViewMixin(BaseQuestionsViewMixin):
Question.objects.none(),
to_attr='dummy'
)))
- ),
+ ).select_related('dependency_question'),
to_attr='questions_to_ask')
)
return sorted(list(cart), key=self._keyfunc)
diff --git a/src/pretix/static/pretixcontrol/js/ui/main.js b/src/pretix/static/pretixcontrol/js/ui/main.js
index 5d5f4fc3a2..3c82ccfdb3 100644
--- a/src/pretix/static/pretixcontrol/js/ui/main.js
+++ b/src/pretix/static/pretixcontrol/js/ui/main.js
@@ -1,13 +1,5 @@
/*global $,gettext*/
-function question_page_toggle_view() {
- var show = $("#id_type").val() == "C" || $("#id_type").val() == "M";
- $("#answer-options").toggle(show);
-
- show = $("#id_type").val() == "B" && $("#id_required").prop("checked");
- $(".alert-required-boolean").toggle(show);
-}
-
var waitingDialog = {
show: function (message) {
"use strict";
@@ -34,6 +26,26 @@ var ajaxErrDialog = {
}
};
+var apiGET = function (url, callback) {
+ $.getJSON(url, function (data) {
+ callback(data);
+ });
+};
+
+var i18nToString = function (i18nstring) {
+ var locale = $("body").attr("data-pretixlocale");
+ if (i18nstring[locale]) {
+ return i18nstring[locale];
+ } else if (i18nstring["en"]) {
+ return i18nstring["en"];
+ }
+ for (key in i18nstring) {
+ if (i18nstring[key]) {
+ return i18nstring[key];
+ }
+ }
+};
+
$(document).ajaxError(function (event, jqXHR, settings, thrownError) {
waitingDialog.hide();
var c = $(jqXHR.responseText).filter('.container');
@@ -423,6 +435,9 @@ var form_handlers = function (el) {
}
);
});
+
+ el.find("input[name*=question], select[name*=question]").change(questions_toggle_dependent);
+ questions_toggle_dependent();
};
$(function () {
@@ -491,14 +506,6 @@ $(function () {
window.location.hash = e.target.hash;
});
- // Question editor
- if ($("#answer-options").length) {
-
- $("#id_type").change(question_page_toggle_view);
- $("#id_required").change(question_page_toggle_view);
- question_page_toggle_view();
- }
-
// Event wizard
$("#event-slug-random-generate").click(function () {
var url = $(this).attr("data-rng-url");
diff --git a/src/pretix/static/pretixcontrol/js/ui/question.js b/src/pretix/static/pretixcontrol/js/ui/question.js
index 7457d8555c..2e0fbacb66 100644
--- a/src/pretix/static/pretixcontrol/js/ui/question.js
+++ b/src/pretix/static/pretixcontrol/js/ui/question.js
@@ -1,5 +1,6 @@
/*global $, Morris, gettext*/
$(function () {
+ // Question view
if (!$("#question-stats").length) {
return;
}
@@ -73,3 +74,66 @@ $(function () {
// N, S, T
});
+
+$(function () {
+ // Question editor
+
+ if (!$("#answer-options").length) {
+ return;
+ }
+
+ // Question editor
+ $("#id_type").change(question_page_toggle_view);
+ $("#id_required").change(question_page_toggle_view);
+ question_page_toggle_view();
+
+ function question_page_toggle_view() {
+ var show = $("#id_type").val() == "C" || $("#id_type").val() == "M";
+ $("#answer-options").toggle(show);
+
+ show = $("#id_type").val() == "B" && $("#id_required").prop("checked");
+ $(".alert-required-boolean").toggle(show);
+ }
+
+ var $val = $("#id_dependency_value");
+ var $dq = $("#id_dependency_question");
+ var oldval = $("#dependency_value_val").text();
+ function update_dependency_options() {
+ $val.parent().find(".loading-indicator").remove();
+ $("#id_dependency_value option").remove();
+ $("#id_dependency_value").prop("required", false);
+
+ var val = $dq.children("option:selected").val();
+ if (!val) {
+ $("#id_dependency_value").show();
+ $val.show();
+ return;
+ }
+
+ $("#id_dependency_value").prop("required", true);
+ $val.hide();
+ $val.parent().append("
");
+
+ apiGET('/api/v1/organizers/' + $("body").attr("data-organizer") + '/events/' + $("body").attr("data-event") + '/questions/' + val + '/', function (data) {
+ if (data.type === "B") {
+ $val.append($("