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
|
<template>
<div class="file-chooser">
<button class="button" @click="openDialog">{{ buttonTitle }}</button><span>{{ selectedName }}</span>
<file-chooser-dialog v-if="showDialog" v-bind="$props" @close="closeDialog" @selected="select" />
</div>
</template>
<script>
import FileChooserDialog from './file-chooser/FileChooserDialog.vue';
import { mapActions, mapGetters } from 'vuex';
export default {
name: 'studip-file-chooser',
components: {
FileChooserDialog,
},
props: {
selectable: {
type: String,
default: 'file',
validator: (value) => {
return ['file', 'folder'].includes(value);
},
},
selectedId: {
type: String,
required: false,
},
courseId: {
type: String,
validator: (value) => {
return value !== '';
},
required: false,
},
userId: {
type: String,
validator: (value) => {
return value !== '';
},
required: false,
},
isImage: { type: Boolean, default: false },
isVideo: { type: Boolean, default: false },
isAudio: { type: Boolean, default: false },
isDocument: { type: Boolean, default: false },
excludedCourseFolderTypes: { type: Array, default: () => [] },
excludedUserFolderTypes: { type: Array, default: () => [] },
},
model: {
prop: 'selectedId',
event: 'select',
},
data() {
return {
showDialog: false,
selectedFile: null,
selectedFolder: null,
};
},
computed: {
...mapGetters({
fileById: 'file-refs/byId',
folderById: 'folders/byId',
}),
buttonTitle() {
if (this.selectable === 'folder') {
return this.$gettext('Ordner auswählen');
}
return this.$gettext('Datei auswählen');
},
selectedName() {
if (this.selectable === 'folder') {
if (this.selectedId === '') {
return this.$gettext('Kein Ordner ausgewählt');
}
return this.$gettextInterpolate(this.$gettext('Ordner "%{folderName}" ausgewählt'), {
folderName: this.folderById({ id: this.selectedId })?.attributes?.name ?? '-',
});
}
if (this.selectedId === '') {
return this.$gettext('Keine Datei ausgewählt');
}
return this.$gettextInterpolate(this.$gettext('Datei "%{fileName}" ausgewählt'), {
fileName: this.fileById({ id: this.selectedId })?.attributes?.name ?? '-',
});
},
},
methods: {
...mapActions({
loadFile: 'file-refs/loadById',
loadFolder: 'folders/loadById',
}),
openDialog() {
this.showDialog = true;
},
closeDialog() {
this.showDialog = false;
},
select(id) {
this.closeDialog();
this.$emit('select', id);
},
loadSelection() {
if (this.selectable === 'folder') {
if (this.selectedId !== '') {
this.loadFolder({ id: this.selectedId });
}
} else {
if (this.selectedId !== '') {
this.loadFile({ id: this.selectedId });
}
}
}
},
mounted() {
this.loadSelection();
},
};
</script>
<style lang="scss" scoped>
.file-chooser {
text-indent: 0;
max-width: 48em;
button {
margin: 0.5ex 0 0.5ex 0;
width: 150px;
}
span {
box-sizing: border-box;
border: solid thin var(--content-color-40);
border-left: none;
display: inline-block;
font-size: 14px;
line-height: 130%;
min-width: 100px;
width: calc(100% - 150px);
overflow: hidden;
text-overflow: ellipsis;
padding: 5px 15px;
vertical-align: middle;
white-space: nowrap;
}
}
</style>
|