vikunja-frontend/src/components/teams/NewTeam.vue

84 lines
1.9 KiB
Vue
Raw Normal View History

2018-09-14 19:19:50 +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-14 19:19:50 +02:00
<h3>Create a new team</h3>
2018-12-25 16:03:51 +01:00
<form @submit.prevent="newTeam" @keyup.esc="back()">
2018-09-14 19:19:50 +02:00
<div class="field is-grouped">
<p class="control is-expanded" v-bind:class="{ 'is-loading': teamService.loading}">
<input
v-focus
class="input"
:class="{ 'disabled': teamService.loading}" v-model="team.name"
type="text"
placeholder="The team's name goes here..."/>
2018-09-14 19:19:50 +02:00
</p>
<p class="control">
2018-12-25 16:03:51 +01:00
<button type="submit" class="button is-success noshadow">
2018-09-14 19:19:50 +02:00
<span class="icon is-small">
<icon icon="plus"/>
</span>
Add
</button>
</p>
</div>
<p class="help is-danger" v-if="showError && team.name.length <= 5">
Please specify at least five characters.
</p>
2018-09-14 19:19:50 +02:00
</form>
</div>
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import TeamModel from '../../models/team'
import TeamService from '../../services/team'
2018-09-14 19:19:50 +02:00
export default {
name: "NewTeam",
data() {
return {
teamService: TeamService,
team: TeamModel,
showError: false,
2018-09-14 19:19:50 +02:00
}
},
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 16:03:51 +01:00
created() {
this.teamService = new TeamService()
2019-10-26 14:19:56 +02:00
this.team = new TeamModel()
2018-12-25 16:03:51 +01:00
this.$parent.setFullPage();
},
2018-09-14 19:19:50 +02:00
methods: {
newTeam() {
if (this.team.name.length <= 4) {
this.showError = true
return
}
this.showError = false
this.teamService.create(this.team)
2018-09-14 19:19:50 +02:00
.then(response => {
router.push({name: 'editTeam', params: {id: response.id}})
this.success({message: 'The team was successfully created.'}, this)
2018-09-14 19:19:50 +02:00
})
.catch(e => {
this.error(e, this)
2018-09-14 19:19:50 +02:00
})
},
2018-12-25 16:03:51 +01:00
back() {
router.go(-1)
},
2018-09-14 19:19:50 +02:00
}
}
</script>