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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
<template>
<studip-dialog
:title="$gettext('Lernmaterial aus Ablaufplan-Themen erstellen')"
:confirmText="$gettext('Erstellen')"
confirmClass="accept"
:closeText="$gettext('Abbrechen')"
closeClass="cancel"
height="450"
width="500"
@close="setShowUnitTopicsDialog(false)"
@confirm="createUnit"
>
<template v-slot:dialogContent>
<form class="default" @submit.prevent="">
<courseware-collapsible-box :title="$gettext('Grundeinstellungen')" :open="true" >
<label class="studiprequired">
{{ text.title }}
<span :title="$gettext('Dies ist ein Pflichtfeld')" aria-hidden="true" class="asterisk">*</span>
<input type="text" v-model="title" required />
</label>
<label class="studiprequired">
{{ text.description }}
<span :title="$gettext('Dies ist ein Pflichtfeld')" aria-hidden="true" class="asterisk">*</span>
<textarea v-model="description" required />
</label>
</courseware-collapsible-box>
<courseware-collapsible-box :title="$gettext('Darstellung')" >
<label>
{{ $gettext('Bild hochladen') }}
<br>
<input
class="cw-file-input"
ref="upload_image"
type="file"
accept="image/*"
@change="checkUploadFile"
>
<CoursewareCompanionBox
v-if="uploadFileError"
:msgCompanion="uploadFileError"
mood="sad"
class="cw-companion-box-in-form"
/>
</label>
<template v-if="selectedStockImage">
<StockImageSelectableImageCard :stock-image="selectedStockImage" />
<label>
<button class="button" type="button" @click="selectedStockImage = null">
{{ $gettext('Bild entfernen') }}
</button>
</label>
</template>
<label v-else>
{{ $gettext('oder') }}
<br>
<button class="button" type="button" @click="showStockImageSelector = true">
{{ $gettext('Aus dem Bilderpool auswählen') }}
</button>
<StockImageSelector
v-if="showStockImageSelector"
@close="showStockImageSelector = false"
@select="onSelectStockImage"
/>
</label>
<label for="color">
{{ $gettext('Farbe') }}
</label>
<StudipSelect
id="color"
v-model="color"
:options="colors"
:reduce="(color) => color.class"
label="name"
:clearable="false"
>
<template #no-options>
{{ $gettext('Es steht keine Auswahl zur Verfügung.') }}
</template>
<template #selected-option="option">
<span class="vs__option-color" :style="{ 'background-color': option.hex }"></span>
<span>{{ name }}</span>
</template>
<template #option="option">
<span class="vs__option-color" :style="{ 'background-color': option.hex }"></span
><span>{{ option.name }}</span>
</template>
</StudipSelect>
</courseware-collapsible-box>
</form>
</template>
</studip-dialog>
</template>
<script>
import CoursewareCollapsibleBox from '../layouts/CoursewareCollapsibleBox.vue';
import StockImageSelectableImageCard from '../../stock-images/SelectableImageCard.vue';
import StockImageSelector from '../../stock-images/SelectorDialog.vue';
import StudipSelect from '../../StudipSelect.vue';
import colorMixin from '@/vue/mixins/courseware/colors.js';
import { mapActions, mapGetters } from 'vuex';
export default {
name: 'courseware-shelf-dialog-topics',
mixins: [colorMixin],
components: {
CoursewareCollapsibleBox,
StockImageSelectableImageCard,
StockImageSelector,
StudipSelect,
},
data() {
return {
title: '',
description: '',
color: 'studip-blue',
uploadFileError: '',
showStockImageSelector: false,
selectedStockImage: null,
text: {
title: this.$gettext('Titel des Lernmaterials'),
description: this.$gettext('Beschreibung'),
},
};
},
computed: {
...mapGetters({
context: 'context',
lastCreateCoursewareUnit: 'courseware-units/lastCreated',
structuralElementById: 'courseware-structural-elements/byId',
}),
colors() {
return this.mixinColors.filter((color) => color.darkmode);
},
},
methods: {
...mapActions({
companionError: 'companionError',
companionInfo: 'companionInfo',
companionSuccess: 'companionSuccess',
createCoursewareUnit: 'courseware-units/create',
setShowUnitTopicsDialog: 'setShowUnitTopicsDialog',
loadStructuralElementById: 'courseware-structural-elements/loadById',
uploadImageForStructuralElement: 'uploadImageForStructuralElement',
}),
checkUploadFile() {
const file = this.$refs?.upload_image?.files[0];
if (file.size > 2097152) {
this.uploadFileError = this.$gettext(
'Diese Datei ist zu groß. Bitte wählen Sie eine Datei aus, die kleiner als 2MB ist.'
);
} else if (!file.type.includes('image')) {
this.uploadFileError = this.$gettext('Diese Datei ist kein Bild. Bitte wählen Sie ein Bild aus.');
} else {
this.uploadFileError = '';
this.selectedStockImage = null;
}
},
async createUnit() {
if (this.title === '') {
this.companionError({
info: this.$gettext('Bitte geben Sie einen Titel ein.'),
});
return false;
}
if (this.description === '') {
this.companionError({
info: this.$gettext('Bitte geben Sie eine Beschreibung ein.'),
});
return false;
}
const file = this.$refs?.upload_image?.files[0];
const unit = {
attributes: {
title: this.title,
purpose: 'content',
payload: {
description: this.description,
color: this.color,
license_type: '',
required_time: '',
difficulty_start: '',
difficulty_end: '',
},
},
relationships: {
range: {
data: {
type: this.context.type,
id: this.context.id,
},
},
},
template: {
type: 'topics',
},
};
await this.createCoursewareUnit(unit, { root: true });
this.setShowUnitTopicsDialog(false);
const newElementId = this.lastCreateCoursewareUnit.relationships['structural-element'].data.id;
await this.loadStructuralElementById({ id: newElementId });
let newStructuralElement = this.structuralElementById({ id: newElementId });
try {
if (file) {
await this.uploadImageForStructuralElement({
structuralElement: newStructuralElement,
file,
});
} else if (this.selectedStockImage) {
await this.setStockImageForStructuralElement({
structuralElement: newStructuralElement,
stockImage: this.selectedStockImage,
});
}
this.loadStructuralElementById({ id: newStructuralElement.id, options: { include: 'children' } });
} catch (error) {
console.error(error);
this.companionError({
info: this.$gettext('Das Bild für das neue Lernmaterial konnte nicht gespeichert werden.'),
});
}
},
onSelectStockImage(stockImage) {
if (this.$refs?.upload_image) {
this.$refs.upload_image.value = null;
}
this.selectedStockImage = stockImage;
this.showStockImageSelector = false;
},
},
};
</script>
|