Live: Retrieve previous submission
This commit is contained in:
parent
a57e032e59
commit
f77cfa4df8
6 changed files with 64 additions and 9 deletions
|
|
@ -25,6 +25,26 @@
|
|||
let show_question = null;
|
||||
let value;
|
||||
|
||||
let req_question;
|
||||
let nosend = false;
|
||||
|
||||
function afterQUpdate(q) {
|
||||
value = undefined;
|
||||
if (q) {
|
||||
q.getMyResponse().then((response) => {
|
||||
if (response && response.value)
|
||||
value = response.value;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if (show_question) {
|
||||
req_question = getQuestion(show_question);
|
||||
req_question.then(afterQUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
function wsconnect() {
|
||||
const ws = new WebSocket((window.location.protocol == 'https'?'wss://':'ws://') + window.location.host + `/api/surveys/${sid}/ws`);
|
||||
|
||||
|
|
@ -59,7 +79,7 @@
|
|||
wsconnect();
|
||||
|
||||
function sendValue() {
|
||||
if (show_question && value) {
|
||||
if (show_question && value && !nosend) {
|
||||
survey.submitAnswers([{"id_question": show_question, "value": value}], $user.id_user).then((response) => {
|
||||
console.log("Vos réponses ont bien étés sauvegardées.");
|
||||
}, (error) => {
|
||||
|
|
@ -91,8 +111,11 @@
|
|||
|
||||
<form on:submit|preventDefault={sendValue}>
|
||||
{#if show_question}
|
||||
{#await getQuestion(show_question)}
|
||||
Please wait
|
||||
{#await req_question}
|
||||
<div class="text-center">
|
||||
<div class="spinner-border text-primary mx-3" role="status"></div>
|
||||
<span>Chargement d'une nouvelle question …</span>
|
||||
</div>
|
||||
{:then question}
|
||||
<QuestionForm
|
||||
qid={show_question}
|
||||
|
|
@ -104,6 +127,13 @@
|
|||
<div class="progress-bar" role="progressbar" style="width: 25%"></div>
|
||||
</div-->
|
||||
</QuestionForm>
|
||||
{#if question.kind != 'mcq' && question.kind != 'ucq'}
|
||||
<button
|
||||
class="btn btn-primary"
|
||||
>
|
||||
Soumettre la réponse
|
||||
</button>
|
||||
{/if}
|
||||
{/await}
|
||||
{:else if ws_up}
|
||||
<h2 class="text-center">
|
||||
|
|
|
|||
Reference in a new issue