summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/GroupModuleGroupList.vue
blob: 622689173abe0fb22b10cb047da96faae0ec0ecb (plain) (blame)
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
<i18n>
{
  "en": {
    "id": "ID",
    "name": "Name",
    "description": "Description",
    "removeSubgroups": "Remove one subgroup | Remove {0} subgroups",
    "addSubgroups": "Add subgroups",
    "deleteGroups": "Delete one group | Delete {0} groups",
    "createGroup": "Create group"
  },
  "de": {
    "id": "ID",
    "name": "Name",
    "description": "Beschreibung",
    "removeSubgroups": "Eine Untergruppe entfernen | {0} Untergruppen entfernen",
    "addSubgroups": "Füge Untergruppen hinzu",
    "deleteGroups": "Eine Gruppe löschen | {0} Gruppen löschen",
    "createGroup": "Gruppe erstellen"
  }
}
</i18n>

<template>
  <div>
    <v-divider></v-divider>
    <data-table v-model="selected" :headers="headers" :items="groups" :loading="loading" @dblclick="loadGroup($event)" copy-button>
      <div slot="actions" slot-scope="row" style="text-align: right">
        <v-btn icon @click.stop @mousedown="loadGroup(row.item)" style="margin: 0"><v-icon>keyboard_arrow_right</v-icon></v-btn>
      </div>
    </data-table>
    <v-divider></v-divider>
    <div v-if="tabIndex === 0" class="text-xs-right">
      <v-btn flat color="error" @click="deleteSelected" :disabled="selected.length === 0">
        <v-icon left>delete</v-icon>{{ $tc('deleteGroups', selected.length, [selected.length]) }}
      </v-btn>
      <v-btn flat color="success" @click="newGroup"><v-icon left>create</v-icon>{{ $t('createGroup') }}</v-btn>
    </div>
    <div v-else class="text-xs-right">
      <v-btn flat color="error" @click="removeSelected" :disabled="selected.length === 0">
        <v-icon left>remove_circle_outline</v-icon>{{ $tc('removeSubgroups', selected.length, [selected.length]) }}
      </v-btn>
      <v-btn flat color="success" @click="addExisting"><v-icon left>add_circle_outline</v-icon>{{ $t('addSubgroups') }}</v-btn>
    </div>
  </div>
</template>

<script>
import DataTable from '@/components/DataTable'
import { mapMutations } from 'vuex'

export default {
  name: 'GroupModuleGroupList',
  props: ['tabIndex', 'groupId', 'groups'],
  components: {
    DataTable
  },
  data () {
    return {
      selected: []
    }
  },
  computed: {
    headers () {
      return [
        { key: 'id', text: this.$t('id'), width: '50px', sortType: 'number' },
        { key: 'name', text: this.$t('name'), width: '200px' },
        { key: 'description', text: this.$t('description') },
        { key: 'actions', width: '60px' }
      ]
    },
    loading () {
      return this.$store.state.groups.tabChain[this.tabIndex].loading
    }
  },
  methods: {
    ...mapMutations('groups', ['setActiveTab', 'setTab', 'setDialog']),
    loadGroup (item) {
      this.$store.dispatch('groups/loadGroup', { id: item.id, name: item.name, tabIndex: this.tabIndex + 1, switchTab: true })
    },
    newGroup () {
      this.setTab({ index: 1, item: { id: 'create', tabType: 'group' } })
      this.setActiveTab(1)
    },
    deleteSelected () {
      this.setDialog({ show: true, info: { action: 'delete', type: 'group', selected: this.selected } })
    },
    removeSelected () {
      this.setDialog({ show: true, info: { action: 'remove', type: 'group', selected: this.selected, tabIndex: this.tabIndex } })
    },
    addExisting () {
      this.setDialog({ show: true, info: { action: 'add', type: 'group', selected: this.selected, tabIndex: this.tabIndex } })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.next-arrow {
  margin-left: 20px;
  margin-right: -10px;
}
</style>