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
|
<template>
<sidebar-widget :title="$gettext('Suche')">
<template #content>
<form class="sidebar-search" @submit.prevent="">
<ul class="needles">
<li>
<div class="input-group files-search">
<input
type="text"
v-model="searchTerm"
:aria-label="$gettext('Geben Sie einen Suchbegriff mit mindestens 3 Zeichen ein.')"
/>
<a v-if="showSearchResults" @click.prevent="setShowSearchResults(false)"
class="reset-search">
<studip-icon shape="decline"></studip-icon>
</a>
<button
type="submit"
:value="$gettext('Suchen')"
aria-controls="search"
class="submit-search"
@click="loadResults"
>
<studip-icon shape="search"></studip-icon>
</button>
</div>
</li>
</ul>
</form>
</template>
</sidebar-widget>
</template>
<script>
import SidebarWidget from '../../SidebarWidget.vue';
import StudipIcon from '../../StudipIcon.vue';
import { mapActions, mapGetters } from 'vuex';
import axios from 'axios';
export default {
name: 'courseware-search-widget',
components: {
StudipIcon,
SidebarWidget,
},
data() {
return {
searchTerm: ''
}
},
computed: {
...mapGetters({
courseware: 'courseware',
context: 'context',
showSearchResults: 'showSearchResults'
}),
},
methods: {
...mapActions({
setShowSearchResults: 'setShowSearchResults',
setSearchResults: 'setSearchResults',
companionWarning: 'companionWarning',
companionError: 'companionError'
}),
loadResults() {
if (this.searchTerm.length < 3) {
this.companionWarning({ info: this.$gettext('Leider ist Ihr Suchbegriff zu kurz. Der Suchbegriff muss mindestens 3 Zeichen lang sein.')});
return;
}
const limit = 100;
let params = {
search: this.searchTerm,
filters: { category: 'GlobalSearchCourseware', contextType: this.context.type, rangeId: this.context.id}
};
axios({
method: 'get',
url: STUDIP.URLHelper.getURL('dispatch.php/globalsearch/find/' + limit),
params: params,
}).then( result => {
this.setShowSearchResults(true);
if (result.data.GlobalSearchCourseware) {
this.setSearchResults((result.data.GlobalSearchCourseware.content));
} else {
this.setSearchResults([]);
}
}).catch(() => {
this.companionError({ info: this.$gettext('Bei der Anfrage ist ein Fehler aufgetreten.')});
});
}
}
}
</script>
|