mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Allow dependencies between questions (#1202)
- [x] data model - [x] api - [x] backend editor - [x] backend validation logic - [x] frontend display logic - [x] frontend validation logic - [x] test checkout step - [x] test modify order in frontend - [x] test modify order in backend - [x] validation tests - [x] correctly evaluate dependency tree in frontend? - [x] copy events
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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("<div class=\"help-block loading-indicator\"><span class=\"fa" +
|
||||
" fa-cog fa-spin\"></span></div>");
|
||||
|
||||
apiGET('/api/v1/organizers/' + $("body").attr("data-organizer") + '/events/' + $("body").attr("data-event") + '/questions/' + val + '/', function (data) {
|
||||
if (data.type === "B") {
|
||||
$val.append($("<option>").attr("value", "True").text(gettext("Ja")));
|
||||
$val.append($("<option>").attr("value", "False").text(gettext("Nein")));
|
||||
} else {
|
||||
for (var i = 0; i < data.options.length; i++) {
|
||||
var opt = data.options[i];
|
||||
var $opt = $("<option>").attr("value", opt.identifier).text(i18nToString(opt.answer));
|
||||
$val.append($opt);
|
||||
}
|
||||
}
|
||||
if (oldval) {
|
||||
$val.val(oldval);
|
||||
}
|
||||
$val.parent().find(".loading-indicator").remove();
|
||||
$val.show();
|
||||
});
|
||||
}
|
||||
|
||||
update_dependency_options();
|
||||
$dq.change(update_dependency_options);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user