salix-front/src/components/FormModelPopup.vue

96 lines
2.3 KiB
Vue
Raw Normal View History

<script setup>
import { ref, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import FormModel from 'components/FormModel.vue';
2024-06-07 07:07:58 +00:00
const emit = defineEmits(['onDataSaved', 'onDataCanceled']);
2024-05-15 12:31:51 +00:00
defineProps({
title: {
type: String,
default: '',
},
subtitle: {
type: String,
default: '',
},
});
const { t } = useI18n();
const formModelRef = ref(null);
const closeButton = ref(null);
2024-03-08 12:02:49 +00:00
const onDataSaved = (formData, requestResponse) => {
closeForm();
2024-06-07 07:07:58 +00:00
emit('onDataSaved', formData, requestResponse);
};
const isLoading = computed(() => formModelRef.value?.isLoading);
const closeForm = async () => {
if (closeButton.value) closeButton.value.click();
};
defineExpose({
isLoading,
});
</script>
<template>
<FormModel
ref="formModelRef"
:observe-form-changes="false"
:default-actions="false"
2024-06-07 07:07:58 +00:00
v-bind="$attrs"
2024-03-08 12:02:49 +00:00
@on-data-saved="onDataSaved"
>
<template #form="{ data, validate }">
2024-01-03 19:55:48 +00:00
<span ref="closeButton" class="close-icon" v-close-popup>
<QIcon name="close" size="sm" />
</span>
<h1 class="title">{{ title }}</h1>
<p>{{ subtitle }}</p>
<slot name="form-inputs" :data="data" :validate="validate" />
<div class="q-mt-lg row justify-end">
<QBtn
2024-04-23 12:18:28 +00:00
:label="t('globals.cancel')"
:title="t('globals.cancel')"
type="reset"
color="primary"
2024-04-23 12:18:28 +00:00
flat
:disabled="isLoading"
:loading="isLoading"
2024-06-07 07:07:58 +00:00
@click="emit('onDataCanceled')"
2024-04-23 12:18:28 +00:00
v-close-popup
/>
<QBtn
2024-04-23 12:18:28 +00:00
:label="t('globals.save')"
:title="t('globals.save')"
type="submit"
color="primary"
class="q-ml-sm"
:disabled="isLoading"
:loading="isLoading"
/>
</div>
</template>
</FormModel>
</template>
<style lang="scss" scoped>
.title {
font-size: 17px;
font-weight: bold;
line-height: 20px;
}
2024-01-03 19:55:48 +00:00
.close-icon {
position: absolute;
top: 20px;
right: 20px;
cursor: pointer;
}
</style>