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

79 lines
1.9 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 class="close" @click="back()">
<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="control is-expanded" :class="{ 'is-loading': listService.loading}">
<input v-focus
class="input"
:class="{ 'disabled': listService.loading}"
v-model="list.title"
type="text"
placeholder="The list's name goes here..."
@keyup.esc="back()"
@keyup.enter="newList()"/>
</p>
<p class="control">
2020-06-17 19:10:48 +02:00
<button class="button is-success noshadow" @click="newList()" :disabled="list.title === ''">
2018-09-09 21:28:07 +02:00
<span class="icon is-small">
<icon icon="plus"/>
</span>
Add
</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,
}
},
2018-12-25 16:03:51 +01:00
created() {
this.list = new ListModel()
this.listService = new ListService()
this.$store.commit(IS_FULLPAGE, true)
2018-12-25 16:03:51 +01:00
},
methods: {
newList() {
2020-06-17 19:10:48 +02:00
if (this.list.title === '') {
this.showError = true
return
}
this.showError = false
this.list.namespaceId = this.$route.params.id
this.listService.create(this.list)
.then(response => {
response.namespaceId = this.list.namespaceId
this.$store.commit('namespaces/addListToNamespace', response)
this.success({message: 'The list was successfully created.'}, this)
router.push({name: 'list.index', params: {listId: response.id}})
})
.catch(e => {
this.error(e, this)
})
},
2018-12-25 16:03:51 +01:00
back() {
router.go(-1)
},
}
}
2018-12-25 16:03:51 +01:00
</script>