From 3519aba24378a546d01f8a6e74e1d9f1387d2fcb Mon Sep 17 00:00:00 2001 From: Niko Date: Wed, 2 Mar 2022 00:54:38 +0100 Subject: [PATCH] Add disabled state for Quiz when filled + More locales in /app --- web/src/app/css/app.css | 6 +++++- web/src/app/js/pages/quiz.js | 26 ++++++++++++++++++++------ web/src/config/lang/en.php | 1 + web/src/config/lang/es.php | 1 + 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/web/src/app/css/app.css b/web/src/app/css/app.css index 82052be..81c9ae2 100644 --- a/web/src/app/css/app.css +++ b/web/src/app/css/app.css @@ -93,7 +93,10 @@ img.avatar { .button.disabled { - filter: grayscale() !important; + filter: grayscale() !important; + cursor: initial !important; + user-select: none; + z-index: -1; } .button.floating { padding: 1.5em; @@ -276,6 +279,7 @@ main { top: 0; background: #f9f9f9; border-bottom: 10px solid #00000014; + z-index: 1; } #quiz .person .lovebg { padding: 1.5em 2em; diff --git a/web/src/app/js/pages/quiz.js b/web/src/app/js/pages/quiz.js index ded1fed..e393075 100644 --- a/web/src/app/js/pages/quiz.js +++ b/web/src/app/js/pages/quiz.js @@ -71,11 +71,20 @@ app.pages.quiz = { } }); content.innerHTML += tpl; - if (item.options.length > 0) { + if (item.options.length > 0) document.querySelector(`#quiz #question-${i} .type-freetext`).remove(); - } else { - document.querySelector(`#quiz #question-${i} .type-options`).remove(); - } + else document.querySelector(`#quiz #question-${i} .type-options`).remove(); + } + + if (json.responses !== undefined && json.responses.length > 0) { + document.querySelectorAll('form label.button') + .forEach(function(item) { item.classList.add('disabled') }); + document.querySelectorAll('form input[type="text"], form input[type="radio"]') + .forEach(function(item) { item.setAttribute('disabled', 'true') }); + for (var i in json.responses) + document.querySelector('form#quiz')['question_'+i] + .value = json.responses[parseInt(i)]; + document.querySelector('*[onclick*="actions.send"]').remove(); } page().scrollInit(); }, @@ -163,11 +172,16 @@ app.pages.quiz = { const key = 'question_'+page().data.content[i].index; const value = form[key].value.trim(); if (value === '') - return app.toast.error('TODO: translate: you must fill all quiz questions before sending it'); + return app.toast.error(s('app.error.must_fill_quiz')); data[key] = value; } http.post('/api/v1/me/quizs', data, function(json) { - console.log(json); + if (json.error !== undefined) + app.toast.error(app.strings.app.error[json.error]); + else if (json.result === 1) { + app.toast.info(app.strings.app.ok.quiz_sent); + setTimeout(function(){ exit() }, app.toast.DEFAULT_MILLIS); + } }); }, }, diff --git a/web/src/config/lang/en.php b/web/src/config/lang/en.php index 470dbc0..fca39b4 100644 --- a/web/src/config/lang/en.php +++ b/web/src/config/lang/en.php @@ -53,6 +53,7 @@ $strings = [ 'follow_rejected_max' => 'You have reached the limit of crush requests on this person', 'user_blocked_you' => 'We are sorry, this person rejected to be your crush. You will find another love soon!', 'already_sent_quiz' => 'Sorry, you can\'t send the Quiz again. It was already sent.', + 'must_fill_quiz' => 'Error, you must fill all Quiz questions before sending it.', ], ], ]; diff --git a/web/src/config/lang/es.php b/web/src/config/lang/es.php index c336bec..0d56ec1 100644 --- a/web/src/config/lang/es.php +++ b/web/src/config/lang/es.php @@ -53,6 +53,7 @@ $strings = [ 'follow_rejected_max' => 'Has alcanzado el límite de peticiones de crush para esta persona', 'user_blocked_you' => 'Lo sentimos, esta persona ha rechazado ser su crush. ¡Encontrarás a otra persona pronto!', 'already_sent_quiz' => 'Lo siento, no puedes enviar este Quiz de nuevo. Ya ha sido enviado antes.', + 'must_fill_quiz' => 'Error, debes rellenar todas las preguntas del Quiz antes de enviarlo.', ], ], ];