2021-07-17 23:21:46 +02:00
|
|
|
<template>
|
|
|
|
<div class="task-add">
|
|
|
|
<div class="field is-grouped">
|
2021-08-13 21:47:15 +02:00
|
|
|
<p class="control has-icons-left is-expanded">
|
2021-07-17 23:21:46 +02:00
|
|
|
<input
|
2021-08-13 21:47:15 +02:00
|
|
|
:disabled="taskService.loading"
|
2021-07-17 23:21:46 +02:00
|
|
|
@keyup.enter="addTask()"
|
|
|
|
class="input"
|
|
|
|
:placeholder="$t('list.list.addPlaceholder')"
|
|
|
|
type="text"
|
|
|
|
v-focus
|
|
|
|
v-model="newTaskTitle"
|
|
|
|
ref="newTaskInput"
|
|
|
|
@keyup="errorMessage = ''"
|
|
|
|
/>
|
|
|
|
<span class="icon is-small is-left">
|
|
|
|
<icon icon="tasks"/>
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
<p class="control">
|
|
|
|
<x-button
|
2021-08-13 21:47:15 +02:00
|
|
|
:disabled="newTaskTitle === '' || taskService.loading"
|
2021-07-17 23:21:46 +02:00
|
|
|
@click="addTask()"
|
|
|
|
icon="plus"
|
2021-08-13 21:47:15 +02:00
|
|
|
:loading="taskService.loading"
|
2021-07-17 23:21:46 +02:00
|
|
|
>
|
|
|
|
{{ $t('list.list.add') }}
|
|
|
|
</x-button>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<p class="help is-danger" v-if="errorMessage !== ''">
|
|
|
|
{{ errorMessage }}
|
|
|
|
</p>
|
|
|
|
<quick-add-magic v-if="errorMessage === ''"/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import TaskService from '../../services/task'
|
|
|
|
import createTask from '@/components/tasks/mixins/createTask'
|
2021-07-25 15:27:15 +02:00
|
|
|
import QuickAddMagic from '@/components/tasks/partials/quick-add-magic.vue'
|
2021-07-17 23:21:46 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'add-task',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
newTaskTitle: '',
|
|
|
|
taskService: TaskService,
|
|
|
|
errorMessage: '',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mixins: [
|
|
|
|
createTask,
|
|
|
|
],
|
|
|
|
components: {
|
|
|
|
QuickAddMagic,
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.taskService = new TaskService()
|
|
|
|
},
|
2021-07-28 21:56:29 +02:00
|
|
|
props: {
|
|
|
|
defaultPosition: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
},
|
2021-07-17 23:21:46 +02:00
|
|
|
methods: {
|
|
|
|
addTask() {
|
|
|
|
if (this.newTaskTitle === '') {
|
|
|
|
this.errorMessage = this.$t('list.create.addTitleRequired')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.errorMessage = ''
|
|
|
|
|
2021-08-13 21:47:15 +02:00
|
|
|
if (this.taskService.loading) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-28 21:56:29 +02:00
|
|
|
this.createNewTask(this.newTaskTitle, 0, this.$store.state.auth.settings.defaultListId, this.defaultPosition)
|
2021-07-17 23:21:46 +02:00
|
|
|
.then(task => {
|
|
|
|
this.newTaskTitle = ''
|
|
|
|
this.$emit('taskAdded', task)
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
if (e === 'NO_LIST') {
|
|
|
|
this.errorMessage = this.$t('list.create.addListRequired')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.error(e)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.task-add {
|
|
|
|
margin-bottom: 0;
|
|
|
|
|
|
|
|
.button {
|
|
|
|
height: 2.5rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|