2018-09-11 17:20:41 +00:00
|
|
|
<template>
|
2021-01-30 16:17:04 +00:00
|
|
|
<create-edit
|
2021-06-23 23:24:57 +00:00
|
|
|
:title="$t('namespace.create.title')"
|
2021-01-21 22:33:16 +00:00
|
|
|
@create="newNamespace()"
|
2021-10-17 15:28:44 +00:00
|
|
|
:primary-disabled="namespace.title === ''"
|
2021-01-21 22:33:16 +00:00
|
|
|
>
|
|
|
|
<div class="field">
|
2021-06-23 23:24:57 +00:00
|
|
|
<label class="label" for="namespaceTitle">{{ $t('namespace.attributes.title') }}</label>
|
2021-01-21 22:33:16 +00:00
|
|
|
<div
|
|
|
|
class="control is-expanded"
|
|
|
|
:class="{ 'is-loading': namespaceService.loading }"
|
|
|
|
>
|
2022-09-28 13:31:06 +00:00
|
|
|
<!-- The user should be able to close the modal by pressing escape - that already works with the default modal.
|
|
|
|
But with the input modal here since it autofocuses the input that input field catches the focus instead.
|
|
|
|
Hence we place the listener on the input field directly. -->
|
2020-09-05 20:35:52 +00:00
|
|
|
<input
|
2020-03-04 19:27:27 +00:00
|
|
|
@keyup.enter="newNamespace()"
|
2022-09-28 13:31:06 +00:00
|
|
|
@keyup.esc="$router.back()"
|
2020-09-05 20:35:52 +00:00
|
|
|
class="input"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('namespace.attributes.titlePlaceholder')"
|
2020-09-05 20:35:52 +00:00
|
|
|
type="text"
|
2021-01-21 22:33:16 +00:00
|
|
|
:class="{ disabled: namespaceService.loading }"
|
2020-09-05 20:35:52 +00:00
|
|
|
v-focus
|
2021-01-21 22:33:16 +00:00
|
|
|
v-model="namespace.title"
|
|
|
|
/>
|
|
|
|
</div>
|
2020-03-04 19:27:27 +00:00
|
|
|
</div>
|
2020-06-17 17:10:48 +00:00
|
|
|
<p class="help is-danger" v-if="showError && namespace.title === ''">
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('namespace.create.titleRequired') }}
|
2020-03-04 19:27:27 +00:00
|
|
|
</p>
|
2021-01-21 22:33:16 +00:00
|
|
|
<div class="field">
|
2021-06-23 23:24:57 +00:00
|
|
|
<label class="label">{{ $t('namespace.attributes.color') }}</label>
|
2021-01-21 22:33:16 +00:00
|
|
|
<div class="control">
|
2021-11-28 14:18:27 +00:00
|
|
|
<color-picker v-model="namespace.hexColor"/>
|
2021-01-21 22:33:16 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-22 18:41:00 +00:00
|
|
|
|
2021-11-28 14:18:27 +00:00
|
|
|
<message class="mt-4">
|
2021-11-22 18:41:00 +00:00
|
|
|
<h4 class="title">{{ $t('namespace.create.tooltip') }}</h4>
|
|
|
|
|
|
|
|
{{ $t('namespace.create.explanation') }}
|
2021-11-28 14:18:27 +00:00
|
|
|
</message>
|
2021-01-30 16:17:04 +00:00
|
|
|
</create-edit>
|
2018-09-11 17:20:41 +00:00
|
|
|
</template>
|
|
|
|
|
2022-09-28 13:31:06 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import {ref, shallowReactive} from 'vue'
|
|
|
|
import {useI18n} from 'vue-i18n'
|
|
|
|
import {useRouter} from 'vue-router'
|
2022-02-15 12:07:59 +00:00
|
|
|
|
2022-06-23 01:08:35 +00:00
|
|
|
import Message from '@/components/misc/message.vue'
|
2021-07-25 13:27:15 +00:00
|
|
|
import CreateEdit from '@/components/misc/create-edit.vue'
|
2022-11-17 16:05:10 +00:00
|
|
|
import ColorPicker from '@/components/input/ColorPicker.vue'
|
2022-09-28 13:31:06 +00:00
|
|
|
|
|
|
|
import NamespaceModel from '@/models/namespace'
|
|
|
|
import NamespaceService from '@/services/namespace'
|
2022-09-02 09:15:29 +00:00
|
|
|
import {useNamespaceStore} from '@/stores/namespaces'
|
2022-09-28 13:31:06 +00:00
|
|
|
import type {INamespace} from '@/modelTypes/INamespace'
|
|
|
|
|
|
|
|
import {useTitle} from '@/composables/useTitle'
|
|
|
|
import {success} from '@/message'
|
|
|
|
|
|
|
|
const showError = ref(false)
|
|
|
|
const namespace = ref<INamespace>(new NamespaceModel())
|
|
|
|
const namespaceService = shallowReactive(new NamespaceService())
|
|
|
|
|
|
|
|
const {t} = useI18n({useScope: 'global'})
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
useTitle(() => t('namespace.create.title'))
|
2018-09-11 17:20:41 +00:00
|
|
|
|
2022-09-28 13:31:06 +00:00
|
|
|
async function newNamespace() {
|
|
|
|
if (namespace.value.title === '') {
|
|
|
|
showError.value = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
showError.value = false
|
2020-09-05 20:35:52 +00:00
|
|
|
|
2022-09-28 13:31:06 +00:00
|
|
|
const newNamespace = await namespaceService.create(namespace.value)
|
|
|
|
useNamespaceStore().addNamespace(newNamespace)
|
|
|
|
success({message: t('namespace.create.success')})
|
|
|
|
router.back()
|
|
|
|
}
|
2018-09-11 17:20:41 +00:00
|
|
|
</script>
|