-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
266 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<script setup lang="ts"> | ||
import { POST } from '@/api'; | ||
import { $t } from '@/i18n'; | ||
import type { NodeTreeOption } from '@/views/admin/AdminTextsNodesView.vue'; | ||
import { NForm, NFormItem, NModal, NButton, NInput, type InputInst, type FormInst } from 'naive-ui'; | ||
import ModalButtonFooter from '@/components/ModalButtonFooter.vue'; | ||
import { ref } from 'vue'; | ||
import { useFormRules } from '@/formRules'; | ||
import { useStateStore } from '@/stores'; | ||
import { useMessages } from '@/messages'; | ||
const props = withDefaults(defineProps<{ show: boolean; parent: NodeTreeOption | null }>(), { | ||
show: false, | ||
}); | ||
const emits = defineEmits(['update:show', 'submit']); | ||
const initialNodeModel = () => ({ | ||
label: '', | ||
}); | ||
const state = useStateStore(); | ||
const { message } = useMessages(); | ||
const nodeFormRef = ref<FormInst | null>(null); | ||
const nodeFormModel = ref<Record<string, string | null>>(initialNodeModel()); | ||
const { nodeFormRules } = useFormRules(); | ||
const loading = ref(false); | ||
const nodeRenameInputRef = ref<InputInst | null>(null); | ||
async function handleSubmit() { | ||
loading.value = true; | ||
nodeFormRef.value | ||
?.validate(async (validationErrors) => { | ||
if (!validationErrors) { | ||
const { data, error } = await POST('/nodes', { | ||
body: { | ||
label: nodeFormModel.value.label || '', | ||
level: (props.parent?.level ?? -1) + 1, | ||
position: Number.MAX_SAFE_INTEGER, | ||
textId: state.text?.id || '', | ||
parentId: props.parent?.key?.toString() || null, | ||
}, | ||
}); | ||
emits('submit', error ? undefined : data); | ||
emits('update:show', false); | ||
} | ||
}) | ||
.catch(() => { | ||
message.error($t('errors.followFormRules')); | ||
}); | ||
loading.value = false; | ||
} | ||
</script> | ||
|
||
<template> | ||
<n-modal | ||
:show="show" | ||
preset="card" | ||
class="tekst-modal" | ||
size="large" | ||
:bordered="false" | ||
:closable="false" | ||
to="#app-container" | ||
embedded | ||
@update:show="$emit('update:show', $event)" | ||
@after-leave="nodeFormModel.label = ''" | ||
> | ||
<h2> | ||
{{ | ||
$t('admin.texts.nodes.add.heading', { | ||
level: (props.parent?.level ?? -1) + 1, | ||
parentLabel: props.parent?.label || state.text?.title || '', | ||
}) | ||
}} | ||
</h2> | ||
|
||
<n-form | ||
ref="nodeFormRef" | ||
:model="nodeFormModel" | ||
:rules="nodeFormRules" | ||
label-placement="top" | ||
label-width="auto" | ||
require-mark-placement="right-hanging" | ||
> | ||
<n-form-item path="label" :label="$t('models.node.label')"> | ||
<n-input | ||
ref="nodeRenameInputRef" | ||
v-model:value="nodeFormModel.label" | ||
type="text" | ||
:disabled="loading" | ||
:autofocus="true" | ||
@keydown.enter="handleSubmit" | ||
/> | ||
</n-form-item> | ||
</n-form> | ||
<ModalButtonFooter> | ||
<n-button secondary :disabled="loading" @click="$emit('update:show', false)"> | ||
{{ $t('general.cancelAction') }} | ||
</n-button> | ||
<n-button type="primary" :loading="loading" :disabled="loading" @click="handleSubmit"> | ||
{{ $t('general.saveAction') }} | ||
</n-button> | ||
</ModalButtonFooter> | ||
</n-modal> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.