From 8f1e8f893420d0582d73427afc14aac4c8c6f203 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 26 Aug 2021 11:36:53 +0200 Subject: [PATCH] Move response message in forms --- www/form/inner.js | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/www/form/inner.js b/www/form/inner.js index 11d4b665f..855b6a1c8 100644 --- a/www/form/inner.js +++ b/www/form/inner.js @@ -1992,12 +1992,6 @@ define([ return; } - if (content.answers.msg) { - var description = h('div.cp-form-creator-results-description#cp-form-response-msg'); - var $desc = $(description).appendTo($container); - DiffMd.apply(DiffMd.render(content.answers.msg), $desc, APP.common); - } - var heading = h('h2#cp-title', Messages._getKey('form_totalResponses', [answerCount])); $(heading).appendTo($container); var timeline = h('div.cp-form-creator-results-timeline'); @@ -2206,12 +2200,40 @@ define([ if (answers._time) { APP.lastAnswerTime = answers._time; } + // If responses are public, show button to view them + var responses; + if (content.answers.privateKey) { + responses = h('button.btn.btn-default', Messages.form_results); + $(responses).click(function () { + var sframeChan = framework._.sfCommon.getSframeChannel(); + sframeChan.query("Q_FORM_FETCH_ANSWERS", content.answers, function (err, obj) { + var answers = obj && obj.results; + if (answers) { APP.answers = answers; } + $('body').addClass('cp-app-form-results'); + renderResults(content, answers); + $container.hide(); + }); + }); + } + + var description = h('div.cp-form-creator-results-description#cp-form-response-msg'); + if (content.answers.msg) { + var $desc = $(description); + DiffMd.apply(DiffMd.render(content.answers.msg), $desc, APP.common); + } + + var actions = h('div.cp-form-submit-actions', [ + action, + responses || undefined + ]); + var title = framework._.title.title || framework._.title.defaultTitle; $container.append(h('div.cp-form-submit-success', [ h('h3.cp-form-view-title', title), + description, h('div.alert.alert-info', Messages._getKey('form_alreadyAnswered', [ new Date(APP.lastAnswerTime).toLocaleString()])), - action + actions ])); };