2020-12-30 18:55:54 +01:00
|
|
|
<template>
|
2021-01-30 17:17:04 +01:00
|
|
|
<create-edit
|
2021-01-21 23:33:16 +01:00
|
|
|
title="Create a new label"
|
|
|
|
@create="newLabel()"
|
|
|
|
:create-disabled="label.title === ''"
|
|
|
|
>
|
|
|
|
<div class="field">
|
|
|
|
<label class="label" for="labelTitle">Label Title</label>
|
|
|
|
<div
|
|
|
|
class="control is-expanded"
|
2021-06-03 22:23:04 +02:00
|
|
|
:class="{ 'is-loading': loading }"
|
2021-01-21 23:33:16 +01:00
|
|
|
>
|
|
|
|
<input
|
2021-06-03 22:23:04 +02:00
|
|
|
:class="{ disabled: loading }"
|
2021-01-21 23:33:16 +01:00
|
|
|
class="input"
|
|
|
|
placeholder="The label title goes here..."
|
|
|
|
type="text"
|
|
|
|
id="labelTitle"
|
|
|
|
v-focus
|
|
|
|
v-model="label.title"
|
|
|
|
@keyup.enter="newLabel()"
|
|
|
|
/>
|
2020-12-30 18:55:54 +01:00
|
|
|
</div>
|
2021-01-21 23:33:16 +01:00
|
|
|
</div>
|
|
|
|
<p class="help is-danger" v-if="showError && label.title === ''">
|
|
|
|
Please specify a title.
|
|
|
|
</p>
|
|
|
|
<div class="field">
|
|
|
|
<label class="label">Color</label>
|
|
|
|
<div class="control">
|
2021-06-03 22:23:04 +02:00
|
|
|
<color-picker v-model="label.hexColor"/>
|
2021-01-21 23:33:16 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-01-30 17:17:04 +01:00
|
|
|
</create-edit>
|
2020-12-30 18:55:54 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import labelModel from '../../models/label'
|
|
|
|
import LabelModel from '../../models/label'
|
2021-01-30 17:17:04 +01:00
|
|
|
import CreateEdit from '@/components/misc/create-edit'
|
2021-01-21 23:33:16 +01:00
|
|
|
import ColorPicker from '../../components/input/colorPicker'
|
2021-06-03 22:23:04 +02:00
|
|
|
import {mapState} from 'vuex'
|
|
|
|
import {LOADING, LOADING_MODULE} from '@/store/mutation-types'
|
2020-12-30 18:55:54 +01:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'NewLabel',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
label: labelModel,
|
|
|
|
showError: false,
|
|
|
|
}
|
|
|
|
},
|
2021-01-21 23:33:16 +01:00
|
|
|
components: {
|
2021-01-30 17:17:04 +01:00
|
|
|
CreateEdit,
|
2021-01-21 23:33:16 +01:00
|
|
|
ColorPicker,
|
|
|
|
},
|
2020-12-30 18:55:54 +01:00
|
|
|
created() {
|
|
|
|
this.label = new LabelModel()
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.setTitle('Create a new label')
|
|
|
|
},
|
2021-06-03 22:23:04 +02:00
|
|
|
computed: mapState({
|
|
|
|
loading: state => state[LOADING] && state[LOADING_MODULE] === 'labels',
|
|
|
|
}),
|
2020-12-30 18:55:54 +01:00
|
|
|
methods: {
|
2021-01-21 23:33:16 +01:00
|
|
|
newLabel() {
|
2020-12-30 18:55:54 +01:00
|
|
|
if (this.label.title === '') {
|
|
|
|
this.showError = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.showError = false
|
|
|
|
|
2021-06-03 22:23:04 +02:00
|
|
|
this.$store.dispatch('labels/createLabel', this.label)
|
|
|
|
.then(r => {
|
2021-01-21 23:33:16 +01:00
|
|
|
this.$router.push({
|
|
|
|
name: 'labels.index',
|
2021-06-03 22:23:04 +02:00
|
|
|
params: {id: r.id},
|
2021-01-21 23:33:16 +01:00
|
|
|
})
|
2021-06-03 22:23:04 +02:00
|
|
|
this.success({message: 'The label was successfully created.'}, this)
|
2020-12-30 18:55:54 +01:00
|
|
|
})
|
2021-01-21 23:33:16 +01:00
|
|
|
.catch((e) => {
|
2020-12-30 18:55:54 +01:00
|
|
|
this.error(e, this)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|