summaryrefslogtreecommitdiff
path: root/static/answer.js
blob: 61882a8967786e5ea2305cdfd6d47ce38a2c96ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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()