From 7bbe9059a1be0acbc9d727494e9a23dda16ccd04 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 19 Aug 2021 15:23:49 +0200 Subject: [PATCH] Tell users when a form has already been submitted --- www/form/inner.js | 22 ++++++++++++++++++---- www/form/main.js | 6 ++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/www/form/inner.js b/www/form/inner.js index bf2228e7b..2f717cb05 100644 --- a/www/form/inner.js +++ b/www/form/inner.js @@ -1388,6 +1388,10 @@ define([ $el.prop('checked', true); } }); + var selected = $tag.find('input:checked').length; + if (selected >= opts.max) { + $tag.find('input:not(:checked)').attr('disabled', 'disabled'); + } } }; @@ -2671,14 +2675,22 @@ define([ return; } + // If the form is already submitted, show an info message + Messages.form_alreadyAnswered = "You've submitted answers to this form on {0}"; // XXX + if (answers) { + $container.prepend(h('div.alert.alert-info', + Messages._getKey('form_alreadyAnswered', [ + new Date(answers._time).toLocaleString()]))); + // XXX make the page read-only? + } + // In view mode, add "Submit" and "reset" buttons + $container.append(makeFormControls(framework, content, Boolean(answers), evOnChange)); + // Embed mode is enforced so we add the title at the top and a CryptPad logo // at the bottom var title = framework._.title.title || framework._.title.defaultTitle; $container.prepend(h('h1.cp-form-view-title', title)); - - $container.append(makeFormControls(framework, content, Boolean(answers), evOnChange)); - var logo = h('div.cp-form-view-logo', [ h('img', { src:'/customize/CryptPad_logo_grey.svg?'+ApiConfig.requireConf.urlArgs, @@ -2690,6 +2702,7 @@ define([ framework._.sfCommon.gotoURL('/drive/'); }); $container.append(logo); + if (!answers) { $container.find('.cp-reset-button').attr('disabled', 'disabled'); } @@ -3156,7 +3169,7 @@ define([ } // If the results are public and there is at least one doodle, fetch the results now - if (content.answers.privateKey && Object.keys(content.form).some(function (uid) { + if (0 && content.answers.privateKey && Object.keys(content.form).some(function (uid) { return content.form[uid].type === "poll"; })) { sframeChan.query("Q_FORM_FETCH_ANSWERS", { @@ -3186,6 +3199,7 @@ define([ var myAnswersObj = answers[curve1] || answers[curve2] || undefined; if (myAnswersObj) { myAnswers = myAnswersObj.msg; + myAnswers._time = myAnswersObj.time; } } // If we have a non-anon answer, we can't answer anonymously later diff --git a/www/form/main.js b/www/form/main.js index 9a017fbe1..4c0831fe9 100644 --- a/www/form/main.js +++ b/www/form/main.js @@ -272,8 +272,10 @@ define([ my_private: Nacl.util.decodeBase64(myKeys.curvePrivate), their_public: Nacl.util.decodeBase64(data.publicKey) }); - res.content._isAnon = answer.anonymous; - cb(JSON.parse(res.content)); + var parsed = JSON.parse(res.content); + parsed._isAnon = answer.anonymous; + parsed._time = messages[0].time; + cb(parsed); }); });