-
-
Notifications
You must be signed in to change notification settings - Fork 226
/
CreateCategoryDialog.vue
115 lines (112 loc) · 2.84 KB
/
CreateCategoryDialog.vue
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
<template>
<v-dialog v-model="dialog" content-class="rounded-form" max-width="300px">
<v-card>
<v-card-title class="pa-0">
<v-toolbar-title class="ma-4 primarytext--text">
<h3>{{ hasInitialCategory ? 'Edit' : 'Create New' }} Category</h3>
</v-toolbar-title>
</v-card-title>
<v-card-text>
<v-form ref="categoryForm" class="px-6 mt-3">
<v-container>
<v-text-field
v-model="category.name"
:rules="nameRules"
:counter="15"
label="Category name"
required
:disabled="hasInitialCategory"
/>
<v-text-field
v-model="category.savePath"
:rules="PathRules"
:counter="40"
label="Path"
required
/>
</v-container>
</v-form>
</v-card-text>
<v-divider />
<v-card-actions class="justify-end">
<v-btn
v-if="!hasInitialCategory"
class="accent white--text elevation-0 px-4"
@click="create"
>
Create
</v-btn>
<v-btn
v-else
class="accent white--text elevation-0 px-4"
@click="edit"
>
Edit
</v-btn>
<v-btn
class="error white--text elevation-0 px-4"
@click="cancel"
>
Cancel
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script>
import { mapGetters } from 'vuex'
import qbit from '@/services/qbit'
import { Modal } from '@/mixins'
import { mdiCancel, mdiTagPlus, mdiPencil } from '@mdi/js'
import Vue from 'vue'
export default {
name: 'CreateNewCategoryDialog',
mixins: [Modal],
props: {
initialCategory: Object
},
data: () => ({
nameRules: [
v => !!v || 'Category name is required',
v =>
(v && v.length <= 15) ||
'Category name must be less than 15 characters'
],
PathRules: [
v => !!v || 'Path is required',
v => (v && v.length <= 40) || 'Path must be less than 40 characters'
],
category: { name: '', savePath: '' },
mdiCancel, mdiTagPlus, mdiPencil
}),
computed: {
...mapGetters(['getSelectedCategory']),
hasInitialCategory() {
return !!(this.initialCategory &&
this.initialCategory.name)
}
},
created() {
this.$store.commit('FETCH_CATEGORIES')
if (this.hasInitialCategory) {
this.category = this.initialCategory
}
},
methods: {
create() {
qbit.createCategory(this.category)
this.cancel()
},
cancel() {
this.$store.commit('FETCH_CATEGORIES')
this.dialog = false
},
edit() {
qbit.editCategory(this.category)
Vue.$toast.success('Category edited successfully!')
this.cancel()
}
}
}
</script>
<style></style>