vikunja-frontend/src/views/list/NewList.vue

83 lines
1.8 KiB
Vue
Raw Normal View History

2018-09-09 21:28:07 +02:00
<template>
2018-12-25 16:03:51 +01:00
<div class="fullpage">
<a @click="back()" class="close">
2018-12-25 16:03:51 +01:00
<icon :icon="['far', 'times-circle']">
</icon>
</a>
2018-09-09 21:28:07 +02:00
<h3>Create a new list</h3>
<div class="field is-grouped">
<p :class="{ 'is-loading': listService.loading}" class="control is-expanded">
<input
:class="{ 'disabled': listService.loading}"
@keyup.enter="newList()"
@keyup.esc="back()"
class="input"
placeholder="The list's name goes here..."
type="text"
v-focus
v-model="list.title"/>
</p>
<p class="control">
<x-button
:disabled="list.title === ''"
@click="newList()"
icon="plus"
:shadow="false"
>
Add
</x-button>
</p>
</div>
2020-06-17 19:10:48 +02:00
<p class="help is-danger" v-if="showError && list.title === ''">
Please specify a title.
</p>
2018-09-09 21:28:07 +02:00
</div>
</template>
<script>
import router from '../../router'
import ListService from '../../services/list'
import ListModel from '../../models/list'
import {IS_FULLPAGE} from '@/store/mutation-types'
2018-09-09 21:28:07 +02:00
export default {
name: 'NewList',
data() {
return {
showError: false,
list: ListModel,
listService: ListService,
}
},
created() {
this.list = new ListModel()
this.listService = new ListService()
this.$store.commit(IS_FULLPAGE, true)
},
mounted() {
this.setTitle('Create a new list')
},
methods: {
newList() {
if (this.list.title === '') {
this.showError = true
return
}
this.showError = false
this.list.namespaceId = this.$route.params.id
this.$store.dispatch('lists/createList', this.list)
.then(r => {
this.success({message: 'The list was successfully created.'}, this)
router.push({name: 'list.index', params: {listId: r.id}})
})
.catch(e => {
this.error(e, this)
})
},
back() {
router.go(-1)
},
},
}
2018-12-25 16:03:51 +01:00
</script>