-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTestSurveyBuilder.vue
69 lines (66 loc) · 1.81 KB
/
TestSurveyBuilder.vue
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
<template>
<div class="test-survey-builder">
<h2 class="text-center">Vue Survey Builder Demo</h2>
<hr/>
<QuestionsView :questions="questionsList" :readOnly="true" />
<div v-if="addQuestion">
<SurveyBuilder :options="sampleQuestion" />
</div>
<div class="pt-10">
<button type="button" class="add_another_btn br-25"
@click="addNewQuestion()">Add question</button>
</div>
</div>
</template>
<script>
import SurveyBuilder from './SurveyBuilder.vue';
import QuestionsView from './QuestionsView.vue';
import sampleQuestionObj from './survey-builder.json';
export default {
name: 'TestSurveyBuilder',
data() {
return {
questionsList: [],
addQuestion: false,
};
},
mounted() {
this.$root.$on('add-update-question', (q) => {
this.updateQuestionsList(q);
});
},
components: { SurveyBuilder, QuestionsView },
methods: {
updateQuestionsList(q) {
const question = q?.question;
const questionIndex = this.questionsList.findIndex((x) => x.id === question.id);
if (questionIndex >= 0) {
this.questionsList.splice(questionIndex, 1, question);
} else {
this.questionsList.push(JSON.parse(JSON.stringify(question)));
}
this.addQuestion = false;
this.$root.$emit('selected-question', null);
window.console.log(question, this.addQuestion, this.questionsList);
},
addNewQuestion() {
this.sampleQuestion = JSON.parse(JSON.stringify(sampleQuestionObj));
this.addQuestion = true;
},
},
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.add_another_btn {
font-size: 14px;
background-color: transparent;
border-color: #4c8ce4;
color: #4c8ce4;
padding: 8px;
cursor: pointer;
}
.text-center {
text-align: center;
}
</style>