summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorKristina Hänninen <khannine@local>2023-11-21 12:52:55 +0200
committerKristina Hänninen <khannine@local>2023-11-21 12:52:55 +0200
commit4c5fd0076b4903320ba470ebf0cd454e5f7a2995 (patch)
tree8765cb09df85d08b4a6207e0dc959901fddcc4b2 /static
parentb868d0ba58384fce5a9a45ae153dee9815327d55 (diff)
Initial anwsering form and related
Diffstat (limited to 'static')
-rw-r--r--static/answer.js68
-rw-r--r--static/create.js1
2 files changed, 68 insertions, 1 deletions
diff --git a/static/answer.js b/static/answer.js
new file mode 100644
index 0000000..61882a8
--- /dev/null
+++ b/static/answer.js
@@ -0,0 +1,68 @@
+var questions = {}
+
+createQuestionDiv = ( question ) => {
+ const questionDiv = document.createElement('div')
+ questionDiv.className = 'kysQuestion'
+
+ const qDiv = document.createElement('div')
+ qDiv.appendChild( document.createTextNode( question.q ) )
+ qDiv.className = 'kysText'
+ questionDiv.appendChild( qDiv )
+
+ const npDiv = document.createElement('div')
+ npDiv.className = 'kysScale'
+
+ const nDiv = document.createElement('div')
+ nDiv.appendChild( document.createTextNode( question.n ) )
+ nDiv.className = 'kysNegative'
+ npDiv.appendChild( nDiv )
+
+ const sDiv = document.createElement('div')
+ sDiv.className = 'kysScaleSpacer'
+ npDiv.appendChild( sDiv )
+
+ const pDiv = document.createElement('div')
+ pDiv.appendChild( document.createTextNode( question.p ) )
+ pDiv.className = 'kysPositive'
+ npDiv.appendChild( pDiv )
+
+ questionDiv.appendChild( npDiv )
+
+ const aInput = document.createElement('input')
+ aInput.className = 'kysAnswer'
+ aInput.type = 'range'
+ aInput.min = 0
+ aInput.max = 999
+ aInput.value = 500
+ aInput.name = question.i
+ questionDiv.appendChild( aInput )
+
+ return questionDiv
+}
+
+createQuestions = () => {
+ const kysForm = document.getElementById('questionForm')
+ const questionsDiv = document.createElement('div')
+ Object.keys(questions).forEach(k => {
+ questionsDiv.appendChild( createQuestionDiv( questions[k] ) )
+ })
+ kysForm.appendChild( questionsDiv )
+ const submitInput = document.createElement('input')
+ submitInput.type='submit'
+ submitInput.value='Vastaa kyselyyn'
+ submitInput.className = 'kysSubmitAnswers'
+ kysForm.appendChild( submitInput )
+}
+
+loadQuestions = async() => {
+ await fetch( 'get/quiz_creator' )
+ .then( response => response.json() )
+ .then( json => questions = json )
+ .catch( error => {
+ alert("dkd")
+ } )
+
+ createQuestions()
+}
+
+loadQuestions()
diff --git a/static/create.js b/static/create.js
index d64073f..d34a2da 100644
--- a/static/create.js
+++ b/static/create.js
@@ -29,7 +29,6 @@ createQuestionDiv = ( question ) => {
questionDiv.appendChild( npDiv )
const aDiv = document.createElement('input')
- aDiv.appendChild( document.createTextNode( question.a ) )
aDiv.className = 'kysAnswer'
aDiv.type = 'range'
aDiv.min = 0