vikunja-frontend/src/views/namespaces/NewNamespace.vue

85 lines
2.1 KiB
Vue
Raw Normal View History

2018-09-11 19:20:41 +02:00
<template>
<create-edit
:title="$t('namespace.create.title')"
@create="newNamespace()"
2021-10-17 17:28:44 +02:00
:primary-disabled="namespace.title === ''"
>
<div class="field">
<label class="label" for="namespaceTitle">{{ $t('namespace.attributes.title') }}</label>
<div
class="control is-expanded"
:class="{ 'is-loading': namespaceService.loading }"
>
<input
@keyup.enter="newNamespace()"
@keyup.esc="back()"
class="input"
:placeholder="$t('namespace.attributes.titlePlaceholder')"
type="text"
:class="{ disabled: namespaceService.loading }"
v-focus
v-model="namespace.title"
/>
</div>
</div>
2020-06-17 19:10:48 +02:00
<p class="help is-danger" v-if="showError && namespace.title === ''">
{{ $t('namespace.create.titleRequired') }}
</p>
<div class="field">
<label class="label">{{ $t('namespace.attributes.color') }}</label>
<div class="control">
<color-picker v-model="namespace.hexColor"/>
</div>
</div>
<message class="mt-4">
<h4 class="title">{{ $t('namespace.create.tooltip') }}</h4>
{{ $t('namespace.create.explanation') }}
</message>
</create-edit>
2018-09-11 19:20:41 +02:00
</template>
2022-02-15 13:07:34 +01:00
<script lang="ts">
2022-02-15 13:07:59 +01:00
import {defineComponent} from 'vue'
import Message from '@/components/misc/message'
import NamespaceModel from '../../models/namespace'
import NamespaceService from '../../services/namespace'
import CreateEdit from '@/components/misc/create-edit.vue'
import ColorPicker from '../../components/input/colorPicker'
2018-09-11 19:20:41 +02:00
2022-02-15 13:07:59 +01:00
export default defineComponent({
name: 'NewNamespace',
data() {
return {
showError: false,
namespace: new NamespaceModel(),
namespaceService: new NamespaceService(),
}
},
components: {
Message,
ColorPicker,
CreateEdit,
},
mounted() {
this.setTitle(this.$t('namespace.create.title'))
},
methods: {
async newNamespace() {
if (this.namespace.title === '') {
this.showError = true
return
2018-12-25 16:03:51 +01:00
}
this.showError = false
2021-10-16 17:20:14 +02:00
const namespace = await this.namespaceService.create(this.namespace)
this.$store.commit('namespaces/addNamespace', namespace)
this.$message.success({message: this.$t('namespace.create.success')})
this.$router.back()
2018-12-25 16:03:51 +01:00
},
},
2022-02-15 13:07:59 +01:00
})
2018-09-11 19:20:41 +02:00
</script>