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
|
<template>
<a href="#" @click.prevent="addBlock">
<div class="cw-blockadder-item" :class="['cw-blockadder-item-' + type]">
<header class="cw-blockadder-item-title">
{{ title }}
</header>
<p class="cw-blockadder-item-description">
{{ description }}
</p>
</div>
</a>
</template>
<script>
import { mapActions, mapGetters } from 'vuex';
export default {
name: 'courseware-blockadder-item',
components: {},
props: {
title: String,
description: String,
type: String,
},
data() {
return {
showInfo: false,
};
},
computed: {
...mapGetters({
blockAdder: 'blockAdder',
}),
},
methods: {
...mapActions({
createBlock: 'createBlockInContainer',
companionInfo: 'companionInfo',
companionWarning: 'companionWarning',
companionSuccess: 'companionSuccess',
updateContainer: 'updateContainer',
lockObject: 'lockObject',
unlockObject: 'unlockObject',
}),
async addBlock() {
if (Object.keys(this.blockAdder).length !== 0) {
// lock parent container
await this.lockObject({ id: this.blockAdder.container.id, type: 'courseware-containers' });
// create new block
await this.createBlock({
container: this.blockAdder.container,
section: this.blockAdder.section,
blockType: this.type,
});
//get new Block
const newBlock = this.$store.getters['courseware-blocks/lastCreated'];
// update container information -> new block id in sections
let container = this.blockAdder.container;
container.attributes.payload.sections[this.blockAdder.section].blocks.push(newBlock.id);
const structuralElementId = container.relationships['structural-element'].data.id;
// update container
await this.updateContainer({ container, structuralElementId });
// unlock container
await this.unlockObject({ id: this.blockAdder.container.id, type: 'courseware-containers' });
this.companionSuccess({
info: this.$gettext('Der Block wurde erfolgreich eingefügt.'),
});
this.$emit('blockAdded');
} else {
// companion action
this.companionWarning({
info: this.$gettext('Bitte wählen Sie einen Ort aus, an dem der Block eingefügt werden soll.'),
});
}
},
},
};
</script>
<style></style>
|