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-20 17:00:03 +02:00
|
|
|
:disabled="taskService.loading || null"
|
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-20 17:00:03 +02:00
|
|
|
:disabled="newTaskTitle === '' || taskService.loading || null"
|
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: '',
|
2021-09-08 11:59:38 +02:00
|
|
|
taskService: new TaskService(),
|
2021-07-17 23:21:46 +02:00
|
|
|
errorMessage: '',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mixins: [
|
|
|
|
createTask,
|
|
|
|
],
|
|
|
|
components: {
|
|
|
|
QuickAddMagic,
|
|
|
|
},
|
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
|
|
|
|
}
|
2021-08-25 12:28:29 +02:00
|
|
|
this.$message.error(e)
|
2021-07-17 23:21:46 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.task-add {
|
|
|
|
margin-bottom: 0;
|
|
|
|
|
|
|
|
.button {
|
|
|
|
height: 2.5rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|