Add 'Answer as ...' in forms

This commit is contained in:
yflory 2021-09-02 11:00:03 +02:00
parent 2ebe2b955c
commit cd65bea28c
2 changed files with 26 additions and 5 deletions

View File

@ -331,6 +331,10 @@
margin-left: 10px;
}
}
.cp-form-anon-answer-registered {
font-style: italic;
margin-left: 10px;
}
}
}

View File

@ -2346,6 +2346,7 @@ define([
} else if (content.answers.anonymous) {
// Answers aren't anonymous and guests are allowed
// Guests can set a username and logged in users can answer anonymously
var $anon;
if (!loggedIn) {
anonName = h('div.cp-form-anon-answer-input', [
Messages.form_answerAs,
@ -2355,15 +2356,24 @@ define([
})
]);
$anonName = $(anonName).hide();
$anonBox.on('change', function () {
if (Util.isChecked($anonBox)) { $anonName.hide(); }
else { $anonName.show(); }
});
} else if (APP.cantAnon) {
// You've already answered with your credentials
$cbox.hide();
$anonBox.attr('disabled', 'disabled').prop('checked', false);
}
if (!anonName) {
anonName = h('div.cp-form-anon-answer-input', [
Messages.form_answerAs,
h('span.cp-form-anon-answer-registered', user.name || Messages.anonymous)
]);
}
if (!APP.cantAnon) {
var $anon = $(anonName).hide();
$anonBox.on('change', function () {
if (Util.isChecked($anonBox)) { $anon.hide(); }
else { $anon.show(); }
});
}
} else {
// Answers don't have to be anonymous and only logged in users can answer
// ==> they have to answer with their keys so we know their name too
@ -2374,7 +2384,7 @@ define([
$cbox.after(h('div.alert.alert-info', Messages.form_authAnswer));
});
}
if (update && content.answers.cantEdit) {
if (update && content.answers.cantEdit || APP.isClosed) {
$cbox.hide();
anonName = undefined;
}
@ -3036,6 +3046,13 @@ define([
new Date(answers._time || APP.lastAnswerTime).toLocaleString()])));
}
if (APP.isClosed) {
APP.formBlocks.forEach(function (b) {
if (!b.setEditable) { return; }
b.setEditable(false);
});
}
// In view mode, add "Submit" and "reset" buttons
$container.append(makeFormControls(framework, content, Boolean(answers), evOnChange));