Add 'Answer as ...' in forms

pull/1/head
yflory 3 years ago
parent 2ebe2b955c
commit cd65bea28c

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

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

Loading…
Cancel
Save