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

81 lines
1.8 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 @click="back()" class="close">
2018-12-25 16:03:51 +01:00
<icon :icon="['far', 'times-circle']">
</icon>
</a>
2018-09-14 19:19:50 +02:00
<h3>Create a new team</h3>
<form @keyup.esc="back()" @submit.prevent="newTeam">
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
:class="{ 'disabled': teamService.loading}"
class="input"
placeholder="The team's name goes here..." type="text"
v-focus
v-model="team.name"/>
2018-09-14 19:19:50 +02:00
</p>
<p class="control">
<button class="button is-success noshadow" type="submit">
2018-09-14 19:19:50 +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 && team.name === ''">
Please specify a name.
</p>
2018-09-14 19:19:50 +02:00
</form>
</div>
</template>
<script>
import router from '../../router'
import TeamModel from '../../models/team'
import TeamService from '../../services/team'
import {IS_FULLPAGE} from '@/store/mutation-types'
2018-09-14 19:19:50 +02:00
export default {
name: 'NewTeam',
data() {
return {
teamService: TeamService,
team: TeamModel,
showError: false,
}
},
created() {
this.teamService = new TeamService()
this.team = new TeamModel()
this.$store.commit(IS_FULLPAGE, true)
},
mounted() {
this.setTitle('Create a new Team')
},
methods: {
newTeam() {
if (this.team.name === '') {
this.showError = true
return
2018-09-14 19:19:50 +02:00
}
this.showError = false
this.teamService.create(this.team)
.then(response => {
router.push({name: 'teams.edit', params: {id: response.id}})
this.success({message: 'The team was successfully created.'}, this)
})
.catch(e => {
this.error(e, this)
})
2018-09-14 19:19:50 +02:00
},
back() {
router.go(-1)
},
},
}
2018-09-14 19:19:50 +02:00
</script>