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"
@showEdit="initCurrentData"
@storeEdit="storeBlock"
@closeEdit="initCurrentData"
>
<template #content>
<div class="cw-block-title">
{{ $gettext('Bestätigung') }}
</div>
<form class="default cw-block-confirm-content" prevent.default="">
<label>
<input type="checkbox" :disabled="confirm" :checked="confirm" @click="setConfirm" />
<span>{{ currentText }}</span>
</label>
</form>
</template>
<template v-if="canEdit" #edit>
<form class="default" @submit.prevent="">
<label>
{{ $gettext('Text') }}
<input type="text" v-model="currentText" />
</label>
</form>
</template>
<template #info>{{ $gettext('Informationen zum Bestätigungs-Block') }}</template>
</courseware-default-block>
</div>
</template>
<script>
import BlockComponents from './block-components.js';
import blockMixin from '@/vue/mixins/courseware/block.js';
import { mapActions, mapGetters } from 'vuex';
export default {
name: 'courseware-confirm-block',
mixins: [blockMixin],
components: Object.assign(BlockComponents, {}),
props: {
block: Object,
canEdit: Boolean,
isTeacher: Boolean,
},
data() {
return {
currentText: '',
confirm: false,
};
},
computed: {
...mapGetters({
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',
updateUserDataFields: 'courseware-user-data-fields/update',
}),
initCurrentData() {
this.currentText = this.text;
if (this.userData?.attributes?.payload?.confirm) {
this.confirm = this.userData.attributes.payload.confirm;
}
},
async setConfirm() {
if (this.confirm) {
return;
}
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.updateUserDataFields(data);
this.setUserProgress({ grade: 1, loadProgresses: true });
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>
<style scoped lang="scss">
@import '../../../../assets/stylesheets/scss/courseware/blocks/confirm';
</style>
|