aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/apps/questionnaires/QuestionnaireAnswer.vue
blob: 169550adc69d078c573d23bd9fe226a1c84be4ea (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<template>
    <form action="#"
          method="post"
          enctype="multipart/form-data"
          class="questionnaire default"
          @submit.prevent="submit()"
          :data-dialog="asDialog ? true : null"
          :data-secure="activateFormSecure"
    >
        <div v-if="questionnaireData.questions[currentPage]">

            <div class="questionnaire_answer">

                Seite {{ currentPage + 1 }} von {{ totalPages }}

                <article
                    v-for="element in questionnaireData.questions[currentPage]"
                    :key="element.id">

                    <QuestionnaireInfoView v-if="element.questiontype == 'QuestionnaireInfo'" :question="element" />
                    <HeadlineView v-if="element.questiontype == 'Headline'" :question="element" />
                    <DividerView v-if="element.questiontype == 'Divider'" />
                    <BlankLineView v-if="element.questiontype == 'BlankLine'" />

                    <VoteAnswer v-if="element.questiontype == 'Vote'" :question="element"/>
                    <FreetextAnswer v-if="element.questiontype == 'Freetext'" :question="element"/>
                    <RangescaleAnswer v-if="element.questiontype == 'Rangescale'" :question="element"/>
                    <LikertAnswer v-if="element.questiontype == 'LikertScale'" :question="element"/>
                    <AutomatedDataAnswer v-if="element.questiontype == 'QuestionnaireAutomatedData'" :question="element"/>
                </article>

            </div>

        </div>

        <!-- Navigation -->
        <div>
            <button :style="{visibility: currentPage > 0 ? 'visible' : 'hidden'}" class="button arr_left" @click="prevPage">
                {{ $gettext('zurück') }}
            </button>
                <button :style="{visibility: currentPage < totalPages - 1 ? 'visible' : 'hidden'}" class="button arr_right" @click="nextPage">
                    {{ $gettext('weiter') }}
                </button>
        </div>

        <div class="terms">
            <span v-if="questionnaireData.anonymous == 1 ">{{ $gettext('Die Teilnahme ist anonym.') }}</span>
            <span v-else>{{ $gettext('Die Teilnahme ist nicht anonym.') }}</span>
            <span v-if="questionnaireData.editanswers == 1 ">{{ $gettext('Sie können Ihre Antworten nachträglich ändern.') }}</span>
            <span v-if="questionnaireData.stopdate">{{ $gettext('Sie können den Fragebogen beantworten bis zum %{date} um %{time} Uhr.', {date:getFormattedDate, time:getFormattedTime}) }}</span>
        </div>

        <div data-dialog-button style="text-align: center;">

            <template v-if="config.isAnswerable">
                <button class="button">{{ $gettext('Speichern') }}</button>
            </template>
            <template v-if="config.resultsVisible">
                <button class="button">{{ $gettext('Ergebnisse anzeigen') }}</button>
            </template>
            <template v-if="config.isEditable && (!config.isRunning || config.countAnswers.length > 0)">
                <button class="button">{{ $gettext('Bearbeiten') }}</button>
            </template>
            <template v-if="config.isEditable">
                <button class="button">{{ $gettext('Kontext auswählen') }}</button>
            </template>
            <template v-if="config.isCopyable">
                <button class="button">{{ $gettext('Kopieren') }}</button>
            </template>
            <template v-if="config.isEditable && !config.isRunning">
                <button class="button">{{ $gettext('Starten') }}</button>
            </template>
            <template v-if="config.isEditable && config.isRunning">
                <button class="button">{{ $gettext('Beenden') }}</button>
            </template>


        </div>

    </form>
    {{ config }}
</template>

<script setup>
import { $gettext } from "../../../assets/javascripts/lib/gettext";
import { computed, ref } from "vue";

/* Import Design Element views */
import QuestionnaireInfoView from '../../components/questionnaires/QuestionnaireInfoView.vue';
import HeadlineView from '../../components/questionnaires/HeadlineView.vue';
import DividerView from '../../components/questionnaires/DividerView.vue';
import BlankLineView from '../../components/questionnaires/BlankLineView.vue';
import PagebreakView from '../../components/questionnaires/PagebreakView.vue';

/* Import Question Views */
import VoteAnswer from '../../components/questionnaires/VoteAnswer.vue';
import FreetextAnswer from '../../components/questionnaires/FreetextAnswer.vue';
import RangescaleAnswer from '../../components/questionnaires/RangescaleAnswer.vue';
import LikertAnswer from '../../components/questionnaires/LikertAnswer.vue';
import AutomatedDataAnswer from '../../components/questionnaires/AutomatedDataAnswer.vue';

const props = defineProps({
    questionnaireData: Object,
    config: Object
})

const currentPage = ref(0)
const totalPages = computed(() => props.questionnaireData.questions.length)

const nextPage = () => {
    if (currentPage.value < totalPages.value - 1) {
        currentPage.value++
    }
}

const prevPage = () => {
    if (currentPage.value > 0) {
        currentPage.value--
    }
}

const getFormattedDate = computed(() => {
    if (!props.questionnaireData?.stopdate) return ''

    return new Date(props.questionnaireData.stopdate * 1000)
        .toLocaleDateString(document.documentElement.lang, {
            day: '2-digit',
            month: '2-digit',
            year: 'numeric'
        })
})

const getFormattedTime = computed(() => {
    if (!props.questionnaireData?.stopdate) return ''

    return new Date(props.questionnaireData.stopdate * 1000)
        .toLocaleTimeString(document.documentElement.lang, {
            hour: '2-digit',
            minute: '2-digit'
        })
})





</script>