forked from akhilrex/hammond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateQuickEntry.vue
122 lines (120 loc) · 3.17 KB
/
createQuickEntry.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
116
117
118
119
120
121
122
<script>
import { mapState } from 'vuex'
import store from '@state/store'
import axios from 'axios'
export default {
data: function() {
return {
file: null,
tryingToCreate: false,
}
},
computed: {
...mapState('utils', ['isMobile']),
uploadButtonLabel() {
if (this.isMobile) {
if (this.file == null) {
return 'Upload/Click Photo'
} else {
return ''
}
} else {
if (this.file == null) {
return this.$t('uploadphoto')
} else {
return ''
}
}
},
},
methods: {
createQuickEntry() {
if (this.file == null) {
return
}
this.tryingToCreate = true
const formData = new FormData()
formData.append('file', this.file, this.file.name)
axios
.post(`/api/quickEntries`, formData)
.then((data) => {
this.$buefy.toast.open({
message: this.$t('quickentrycreatedsuccessfully'),
type: 'is-success',
duration: 3000,
})
this.file = null
store.dispatch('vehicles/fetchQuickEntries', { force: true }).then((data) => {
this.quickEntries = data
})
})
.catch((ex) => {
this.$buefy.toast.open({
duration: 5000,
message: ex.message,
position: 'is-bottom',
type: 'is-danger',
})
})
.finally(() => {
this.tryingToCreate = false
})
},
},
}
</script>
<template>
<div class="section box">
<div class="columns">
<div class="column is-two-thirds">
<p class="title">{{ $tc('quickentry',1) }}</p>
<p class="subtitle"
>{{ $t('quickentrydesc') }}</p
></div
>
<div class="column is-one-third is-flex is-align-content-center">
<form @submit.prevent="createQuickEntry">
<div class="columns"
><div class="column">
<b-field class="file is-primary" :class="{ 'has-name': !!file }">
<b-upload v-model="file" class="file-label" accept="image/*">
<span class="file-cta">
<b-icon class="file-icon" icon="upload"></b-icon>
<span class="file-label">{{ uploadButtonLabel }}</span>
</span>
<span
v-if="file"
class="file-name"
:class="isMobile ? 'file-name-mobile' : 'file-name-desktop'"
>
{{ file.name }}
</span>
</b-upload>
</b-field>
</div>
<div class="column">
<b-button
tag="input"
native-type="submit"
:disabled="tryingToCreate"
type="is-primary"
:value="this.$t('uploadfile')"
class="control"
>
{{ $t('uploadfile') }}
</b-button>
</div></div
>
</form>
</div>
</div>
</div>
</template>
<style>
.file-name-desktop {
max-width: 9em;
}
.file-name-mobile {
max-width: 12em;
}
</style>