diff options
Diffstat (limited to 'static/create.js')
| -rw-r--r-- | static/create.js | 63 | 
1 files changed, 63 insertions, 0 deletions
| diff --git a/static/create.js b/static/create.js new file mode 100644 index 0000000..6c25659 --- /dev/null +++ b/static/create.js @@ -0,0 +1,63 @@ +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 aDiv = document.createElement('input') +    aDiv.appendChild( document.createTextNode( question.a ) ) +    aDiv.className = 'kysAnswer' +    aDiv.type = 'range' +    aDiv.min = 0 +    aDiv.max = 999 +    aDiv.disabled = true +    aDiv.value = question.a +    questionDiv.appendChild( aDiv ) +     +    return questionDiv +} + +createQuestions = () => { +    const questionsDiv = document.getElementById('questions') +    questionsDiv.className = 'kysQuestions' +    Object.keys(questions).forEach(k => {  +        questionsDiv.appendChild( createQuestionDiv( questions[k] ) ) +    }) +} + +loadQuestions = async() => { +    await fetch( 'get_questions' ) +        .then( response => response.json() ) +        .then( json => questions = json ) +        .catch( error => { +        alert("dkd") +        } ) +     +    createQuestions() +} + +loadQuestions() |