forked from vikunja/frontend
140 lines
3.6 KiB
Vue
140 lines
3.6 KiB
Vue
<template>
|
|
<div>
|
|
<div class="field is-grouped">
|
|
<p :class="{ 'is-loading': taskService.loading}" class="control has-icons-left is-expanded">
|
|
<input
|
|
:class="{ 'disabled': taskService.loading}"
|
|
@keyup.enter="addTask()"
|
|
class="input"
|
|
:placeholder="$t('list.list.addPlaceholder')"
|
|
type="text"
|
|
v-focus
|
|
v-model="newTaskText"
|
|
ref="newTaskInput"
|
|
/>
|
|
<span class="icon is-small is-left">
|
|
<icon icon="tasks"/>
|
|
</span>
|
|
</p>
|
|
<p class="control">
|
|
<x-button
|
|
:disabled="newTaskText.length === 0"
|
|
@click="addTask()"
|
|
icon="plus"
|
|
>
|
|
{{ $t('list.list.add') }}
|
|
</x-button>
|
|
</p>
|
|
</div>
|
|
<p class="help is-danger" v-if="showError && newTaskText === ''">
|
|
{{ $t('list.list.addTitleRequired') }}
|
|
</p>
|
|
<quick-add-magic v-if="!showError"/>
|
|
</div>
|
|
<!-- <div class="field is-grouped" >-->
|
|
<!-- <p-->
|
|
<!-- :class="{ 'is-loading': taskService.loading }"-->
|
|
<!-- class="control has-icons-left is-expanded"-->
|
|
<!-- v-if="validListIdAvailable"-->
|
|
<!-- >-->
|
|
<!-- <input-->
|
|
<!-- :class="{ disabled: taskService.loading }"-->
|
|
<!-- @keyup.enter="addTask()"-->
|
|
<!-- class="input"-->
|
|
<!-- placeholder="Add a new task..."-->
|
|
<!-- type="text"-->
|
|
<!-- v-focus-->
|
|
<!-- v-model="newTaskText"-->
|
|
<!-- ref="newTaskInput"-->
|
|
<!-- />-->
|
|
<!-- <span class="icon is-small is-left">-->
|
|
<!-- <icon icon="tasks" />-->
|
|
<!-- </span>-->
|
|
<!-- </p>-->
|
|
<!-- <p class="control" v-if="validListIdAvailable">-->
|
|
<!-- <x-button-->
|
|
<!-- :disabled="newTaskText.length === 0"-->
|
|
<!-- @click="addTask()"-->
|
|
<!-- icon="plus"-->
|
|
<!-- >-->
|
|
<!-- Add-->
|
|
<!-- </x-button>-->
|
|
<!-- </p>-->
|
|
<!-- <p class="help is-warning" v-if="!validListIdAvailable">-->
|
|
<!-- No default list set. Please go to settings and specify default list.-->
|
|
<!-- </p> -->
|
|
<!-- </div>-->
|
|
</template>
|
|
|
|
<script>
|
|
import ListService from '../../services/list'
|
|
import TaskService from '../../services/task'
|
|
import LabelService from '../../services/label'
|
|
import LabelTaskService from '../../services/labelTask'
|
|
import createTask from '@/components/tasks/mixins/createTask'
|
|
import QuickAddMagic from '@/components/tasks/partials/quick-add-magic'
|
|
|
|
export default {
|
|
name: 'add-task',
|
|
data() {
|
|
return {
|
|
newTaskText: '',
|
|
listService: ListService,
|
|
taskService: TaskService,
|
|
labelService: LabelService,
|
|
labelTaskService: LabelTaskService,
|
|
listIdForNewTask: null,
|
|
validListIdAvailable: false,
|
|
showError: false,
|
|
}
|
|
},
|
|
mixins: [
|
|
createTask,
|
|
],
|
|
props: {
|
|
listId: {
|
|
type: Number,
|
|
required: false,
|
|
},
|
|
},
|
|
components: {
|
|
QuickAddMagic,
|
|
},
|
|
created() {
|
|
this.listService = new ListService()
|
|
this.taskService = new TaskService()
|
|
this.labelService = new LabelService()
|
|
this.labelTaskService = new LabelTaskService()
|
|
},
|
|
beforeMount() {
|
|
// If the parent provides the ID alway use that be falling back to the one
|
|
// stored in settings. If neither are avliable then hide the component.
|
|
if (this.listId !== undefined) {
|
|
this.listIdForNewTask = this.listId
|
|
this.validListIdAvailable = true
|
|
} else if (this.$store.state.auth.settings.defaultListId !== undefined) {
|
|
this.listIdForNewTask = this.$store.state.auth.settings.defaultListId
|
|
this.validListIdAvailable = true
|
|
}
|
|
},
|
|
methods: {
|
|
addTask() {
|
|
if (this.newTaskText === '') {
|
|
this.showError = true
|
|
return
|
|
}
|
|
this.showError = false
|
|
|
|
this.createNewTask(this.newTaskText)
|
|
.then(task => {
|
|
this.newTaskText = ''
|
|
this.$emit('taskAdded', task)
|
|
})
|
|
.catch(e => {
|
|
this.error(e)
|
|
})
|
|
},
|
|
},
|
|
}
|
|
</script>
|