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
|
<template>
<div class="cw-block cw-block-confirm">
<courseware-default-block
:block="block"
:canEdit="canEdit"
:isTeacher="isTeacher"
:preview="true"
:defaultGrade="false"
@storeEdit="storeBlock"
@closeEdit="initCurrentData"
>
<template #content>
<div class="cw-block-title">
<translate>Bestätigung</translate>
</div>
<div class="cw-block-confirm-content">
<div class="cw-block-confirm-checkbox">
<studip-icon v-if="!confirm" shape="checkbox-unchecked" role="info" @click="setConfirm" />
<studip-icon v-if="confirm" shape="checkbox-checked" role="info" />
</div>
<p class="cw-block-confirm-text">
{{ currentText }}
</p>
</div>
</template>
<template v-if="canEdit" #edit>
<form class="default" @submit.prevent="">
<label>
<translate>Text</translate>
<input type="text" v-model="currentText" />
</label>
</form>
</template>
<template #info><translate>Informationen zum Bestätigungs-Block</translate></template>
</courseware-default-block>
</div>
</template>
<script>
import CoursewareDefaultBlock from './CoursewareDefaultBlock.vue';
import { mapActions, mapGetters } from 'vuex';
import { blockMixin } from './block-mixin.js';
import StudipIcon from '../StudipIcon.vue';
export default {
name: 'courseware-confirm-block',
mixins: [blockMixin],
components: {
CoursewareDefaultBlock,
StudipIcon,
},
props: {
block: Object,
canEdit: Boolean,
isTeacher: Boolean,
},
data() {
return {
currentText: '',
confirm: false,
};
},
computed: {
...mapGetters({
userId: 'userId',
getUserDataById: 'courseware-user-data-fields/byId',
}),
text() {
return this.block?.attributes?.payload?.text;
},
userData() {
return this.getUserDataById({ id: this.block.relationships['user-data-field'].data.id });
},
},
mounted() {
this.initCurrentData();
},
methods: {
...mapActions({
updateBlock: 'updateBlockInContainer',
}),
initCurrentData() {
this.currentText = this.text;
if (this.userData?.attributes?.payload?.confirm) {
this.confirm = this.userData.attributes.payload.confirm;
}
},
async setConfirm() {
let data = {};
data.type = 'courseware-user-data-fields';
data.id = this.block.relationships['user-data-field'].data.id;
data.attributes = {};
data.attributes.payload = {};
data.attributes.payload.confirm = true;
data.relationships = {};
data.relationships.block = {};
data.relationships.block.data = {};
data.relationships.block.data.id = this.block.id;
data.relationships.block.data.type = this.block.type;
await this.$store.dispatch('courseware-user-data-fields/update', data);
this.userProgress = 1;
this.confirm = true;
},
storeBlock() {
let attributes = {};
attributes.payload = {};
attributes.payload.text = this.currentText;
this.updateBlock({
attributes: attributes,
blockId: this.block.id,
containerId: this.block.relationships.container.data.id,
});
},
},
};
</script>
|