frontend/src/components/lists/NewList.vue

77 lines
2.2 KiB
Vue
Raw Normal View History

2018-09-09 19:28:07 +00:00
<template>
2018-12-25 15:03:51 +00:00
<div class="fullpage">
<a class="close" @click="back()">
<icon :icon="['far', 'times-circle']">
</icon>
</a>
2018-09-09 19:28:07 +00:00
<h3>Create a new list</h3>
2018-12-25 15:03:51 +00:00
<form @submit.prevent="newList" @keyup.esc="back()">
2018-09-09 19:28:07 +00:00
<div class="field is-grouped">
2018-12-25 15:03:51 +00:00
<p class="control is-expanded" :class="{ 'is-loading': loading}">
<input v-focus class="input" :class="{ 'disabled': loading}" v-model="list.title" type="text" placeholder="The list's name goes here...">
2018-09-09 19:28:07 +00:00
</p>
<p class="control">
2018-12-25 15:03:51 +00:00
<button type="submit" class="button is-success noshadow">
2018-09-09 19:28:07 +00:00
<span class="icon is-small">
<icon icon="plus"/>
</span>
Add
</button>
</p>
</div>
</form>
</div>
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import {HTTP} from '../../http-common'
import message from '../../message'
export default {
name: "NewList",
data() {
return {
list: {title: ''},
error: '',
loading: false
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (!auth.user.authenticated) {
router.push({name: 'home'})
}
},
2018-12-25 15:03:51 +00:00
created() {
this.$parent.setFullPage();
},
2018-09-09 19:28:07 +00:00
methods: {
newList() {
2018-11-27 10:23:50 +00:00
const cancel = message.setLoading(this)
2018-09-09 19:28:07 +00:00
HTTP.put(`namespaces/` + this.$route.params.id + `/lists`, this.list, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
2018-12-25 15:03:51 +00:00
.then(response => {
2018-09-09 19:28:07 +00:00
this.$parent.loadNamespaces()
this.handleSuccess({message: 'The list was successfully created.'})
2018-11-27 10:23:50 +00:00
cancel()
2018-12-25 15:03:51 +00:00
router.push({name: 'showList', params: {id: response.data.id}})
2018-09-09 19:28:07 +00:00
})
.catch(e => {
cancel()
this.handleError(e)
2018-09-09 19:28:07 +00:00
})
},
2018-12-25 15:03:51 +00:00
back() {
router.go(-1)
},
2018-09-09 19:28:07 +00:00
handleError(e) {
message.error(e, this)
},
handleSuccess(e) {
message.success(e, this)
}
}
}
2018-12-25 15:03:51 +00:00
</script>