flaschengeist-frontend/src/components/vorstand/JobKindManager.vue

172 lines
4.5 KiB
Vue
Raw Normal View History

<template>
<div>
2020-05-17 19:19:19 +00:00
<v-data-table
:items="jobkinds"
:headers="header"
:loading="jobkindsLoading || workgroupsLoading"
:search="search"
>
<template v-slot:top>
<v-toolbar flat color="white">
<v-toolbar-title>
Dienstarten
</v-toolbar-title>
<v-spacer />
<v-text-field
v-model="search"
label="Suche Dienstart"
single-line
hide-details
>
<template v-slot:append>
<v-icon>{{ searchIcon }}</v-icon>
</template>
</v-text-field>
<v-btn fab small color="primary" @click="add()">
<v-icon>{{ plusIcon }}</v-icon>
</v-btn>
</v-toolbar>
</template>
<template v-slot:item.workgroup="{ item }">
{{ item.workgroup === null ? 'Alle' : item.workgroup.name }}
</template>
<template v-slot:item.actions="{item}">
<v-icon x-small @click="editJobKind(item)">{{editIcon}}</v-icon>
<v-icon x-small @click="deleteJobKind(item)">{{deleteIcon}}</v-icon>
</template>
</v-data-table>
<v-dialog v-model="dialog">
<v-card>
<v-card-title>
{{ title }}
</v-card-title>
<v-card-text>
2020-05-17 19:19:19 +00:00
<v-row>
<v-col>
<v-text-field outlined label="Name" v-model="editedItem.name" />
</v-col>
<v-col>
<v-autocomplete
outlined
return-object
label="Arbeitsgruppe"
v-model="editedItem.workgroup"
item-text="name"
item-value="id"
:items="[...workgroups, { id: -1, name: 'Alle' }]"
/>
</v-col>
</v-row>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn text color="primary" @click="close()">Abbrechen</v-btn>
<v-btn text color="primary" @click="save()">Speichern</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</div>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
2020-05-17 19:19:19 +00:00
import { mdiPencil, mdiDelete, mdiPlus, mdiMagnify } from '@mdi/js'
export default {
name: 'JobKindManager',
data() {
return {
2020-05-17 19:19:19 +00:00
search: null,
editIcon: mdiPencil,
deleteIcon: mdiDelete,
plusIcon: mdiPlus,
2020-05-17 19:19:19 +00:00
searchIcon: mdiMagnify,
dialog: false,
2020-05-17 19:19:19 +00:00
header: [
{ text: 'Name', value: 'name' },
{ text: 'Zugewiesene Arbeitsgruppe', value: 'workgroup' },
{
text: 'Aktionen',
value: 'actions',
filterable: false,
sortable: false
}
],
editedItem: {
id: -1,
2020-05-17 19:19:19 +00:00
name: null,
workgroup: {
id: -1,
name: null
}
},
defaultItem: {
id: -1,
2020-05-17 19:19:19 +00:00
name: null,
workgroup: {
id: -1,
name: null
}
}
}
},
methods: {
...mapActions({
getAllJobKinds: 'jkm/getAllJobKinds',
addingJobKind: 'jkm/addJobKind',
updateJobKind: 'jkm/updateJobKind',
2020-05-17 19:19:19 +00:00
deletingJobKind: 'jkm/deleteJobKind',
getAllWorkgroups: 'wm/getAllWorkgroups'
}),
add() {
this.dialog = true
},
editJobKind(jobkind) {
this.dialog = true
this.editedItem = Object.assign({}, jobkind)
2020-05-17 19:19:19 +00:00
if (this.editedItem.workgroup === null) {
this.editedItem.workgroup = Object.assign({}, this.defaultItem.workgroup)
}
},
deleteJobKind(jobkind) {
2020-05-17 19:19:19 +00:00
confirm('Willst du diese Dienstart wirklich löschen') &&
this.deletingJobKind(jobkind)
this.close()
},
close() {
setTimeout(() => {
this.editedItem = Object.assign({}, this.defaultItem)
this.dialog = false
}, 200)
},
save() {
2020-05-17 19:19:19 +00:00
if (this.editedItem.workgroup.id === -1)
this.editedItem.workgroup = null
this.editedItem.id === -1
? this.addingJobKind(this.editedItem)
: this.updateJobKind(this.editedItem)
this.close()
}
},
computed: {
...mapGetters({
jobkinds: 'jkm/jobkinds',
2020-05-17 19:19:19 +00:00
jobkindsLoading: 'jkm/jobkindsLoading',
workgroups: 'wm/workgroups',
workgroupsLoading: 'wm/workgroupLoading'
}),
title() {
return this.editedItem.id === -1
? 'Neue Dienstart erstellen'
: 'Dienstart bearbeiten'
}
},
created() {
this.getAllJobKinds()
2020-05-17 19:19:19 +00:00
this.getAllWorkgroups()
console.log(this.jobkinds)
}
}
</script>
<style scoped></style>