2020-07-11 03:13:11 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<XModalWindow
|
|
|
|
ref="dialog"
|
|
|
|
:width="450"
|
|
|
|
:can-close="false"
|
|
|
|
:with-ok-button="true"
|
|
|
|
:ok-button-disabled="false"
|
|
|
|
@click="cancel()"
|
|
|
|
@ok="ok()"
|
|
|
|
@close="cancel()"
|
|
|
|
@closed="$emit('closed')"
|
|
|
|
>
|
|
|
|
<template #header>
|
|
|
|
{{ title }}
|
|
|
|
</template>
|
2021-12-02 12:09:12 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
<MkSpacer :margin-min="20" :margin-max="32">
|
|
|
|
<div class="xkpnjxcv _formRoot">
|
|
|
|
<template
|
|
|
|
v-for="item in Object.keys(form).filter(
|
|
|
|
(item) => !form[item].hidden
|
|
|
|
)"
|
|
|
|
>
|
|
|
|
<FormInput
|
|
|
|
v-if="form[item].type === 'number'"
|
|
|
|
v-model="values[item]"
|
|
|
|
type="number"
|
|
|
|
:step="form[item].step || 1"
|
|
|
|
class="_formBlock"
|
|
|
|
>
|
|
|
|
<template #label
|
|
|
|
><span v-text="form[item].label || item"></span
|
|
|
|
><span v-if="form[item].required === false">
|
|
|
|
({{ i18n.ts.optional }})</span
|
|
|
|
></template
|
|
|
|
>
|
|
|
|
<template v-if="form[item].description" #caption>{{
|
|
|
|
form[item].description
|
|
|
|
}}</template>
|
|
|
|
</FormInput>
|
|
|
|
<FormInput
|
|
|
|
v-else-if="
|
|
|
|
form[item].type === 'string' &&
|
|
|
|
!form[item].multiline
|
|
|
|
"
|
|
|
|
v-model="values[item]"
|
|
|
|
type="text"
|
|
|
|
class="_formBlock"
|
|
|
|
>
|
|
|
|
<template #label
|
|
|
|
><span v-text="form[item].label || item"></span
|
|
|
|
><span v-if="form[item].required === false">
|
|
|
|
({{ i18n.ts.optional }})</span
|
|
|
|
></template
|
|
|
|
>
|
|
|
|
<template v-if="form[item].description" #caption>{{
|
|
|
|
form[item].description
|
|
|
|
}}</template>
|
|
|
|
</FormInput>
|
|
|
|
<FormTextarea
|
|
|
|
v-else-if="
|
|
|
|
form[item].type === 'string' && form[item].multiline
|
|
|
|
"
|
|
|
|
v-model="values[item]"
|
|
|
|
class="_formBlock"
|
|
|
|
>
|
|
|
|
<template #label
|
|
|
|
><span v-text="form[item].label || item"></span
|
|
|
|
><span v-if="form[item].required === false">
|
|
|
|
({{ i18n.ts.optional }})</span
|
|
|
|
></template
|
|
|
|
>
|
|
|
|
<template v-if="form[item].description" #caption>{{
|
|
|
|
form[item].description
|
|
|
|
}}</template>
|
|
|
|
</FormTextarea>
|
|
|
|
<FormSwitch
|
|
|
|
v-else-if="form[item].type === 'boolean'"
|
|
|
|
v-model="values[item]"
|
|
|
|
class="_formBlock"
|
|
|
|
>
|
|
|
|
<span v-text="form[item].label || item"></span>
|
|
|
|
<template v-if="form[item].description" #caption>{{
|
|
|
|
form[item].description
|
|
|
|
}}</template>
|
|
|
|
</FormSwitch>
|
|
|
|
<FormSelect
|
|
|
|
v-else-if="form[item].type === 'enum'"
|
|
|
|
v-model="values[item]"
|
|
|
|
class="_formBlock"
|
|
|
|
>
|
|
|
|
<template #label
|
|
|
|
><span v-text="form[item].label || item"></span
|
|
|
|
><span v-if="form[item].required === false">
|
|
|
|
({{ i18n.ts.optional }})</span
|
|
|
|
></template
|
|
|
|
>
|
|
|
|
<option
|
|
|
|
v-for="item in form[item].enum"
|
|
|
|
:key="item.value"
|
|
|
|
:value="item.value"
|
|
|
|
>
|
|
|
|
{{ item.label }}
|
|
|
|
</option>
|
|
|
|
</FormSelect>
|
|
|
|
<FormRadios
|
|
|
|
v-else-if="form[item].type === 'radio'"
|
|
|
|
v-model="values[item]"
|
|
|
|
class="_formBlock"
|
|
|
|
>
|
|
|
|
<template #label
|
|
|
|
><span v-text="form[item].label || item"></span
|
|
|
|
><span v-if="form[item].required === false">
|
|
|
|
({{ i18n.ts.optional }})</span
|
|
|
|
></template
|
|
|
|
>
|
|
|
|
<option
|
|
|
|
v-for="item in form[item].options"
|
|
|
|
:key="item.value"
|
|
|
|
:value="item.value"
|
|
|
|
>
|
|
|
|
{{ item.label }}
|
|
|
|
</option>
|
|
|
|
</FormRadios>
|
|
|
|
<FormRange
|
|
|
|
v-else-if="form[item].type === 'range'"
|
|
|
|
v-model="values[item]"
|
|
|
|
:min="form[item].min"
|
|
|
|
:max="form[item].max"
|
|
|
|
:step="form[item].step"
|
|
|
|
:text-converter="form[item].textConverter"
|
|
|
|
class="_formBlock"
|
|
|
|
>
|
|
|
|
<template #label
|
|
|
|
><span v-text="form[item].label || item"></span
|
|
|
|
><span v-if="form[item].required === false">
|
|
|
|
({{ i18n.ts.optional }})</span
|
|
|
|
></template
|
|
|
|
>
|
|
|
|
<template v-if="form[item].description" #caption>{{
|
|
|
|
form[item].description
|
|
|
|
}}</template>
|
|
|
|
</FormRange>
|
|
|
|
<MkButton
|
|
|
|
v-else-if="form[item].type === 'button'"
|
|
|
|
class="_formBlock"
|
|
|
|
@click="form[item].action($event, values)"
|
|
|
|
>
|
|
|
|
<span v-text="form[item].content || item"></span>
|
|
|
|
</MkButton>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
</XModalWindow>
|
2020-07-11 03:13:11 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-04-08 02:01:42 +02:00
|
|
|
import { defineComponent } from "vue";
|
|
|
|
import FormInput from "./form/input.vue";
|
|
|
|
import FormTextarea from "./form/textarea.vue";
|
|
|
|
import FormSwitch from "./form/switch.vue";
|
|
|
|
import FormSelect from "./form/select.vue";
|
|
|
|
import FormRange from "./form/range.vue";
|
|
|
|
import MkButton from "./MkButton.vue";
|
|
|
|
import FormRadios from "./form/radios.vue";
|
|
|
|
import XModalWindow from "@/components/MkModalWindow.vue";
|
|
|
|
import { i18n } from "@/i18n";
|
2020-07-11 03:13:11 +02:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2020-07-11 03:13:11 +02:00
|
|
|
components: {
|
2020-10-17 13:12:00 +02:00
|
|
|
XModalWindow,
|
2020-11-25 13:31:34 +01:00
|
|
|
FormInput,
|
|
|
|
FormTextarea,
|
|
|
|
FormSwitch,
|
|
|
|
FormSelect,
|
|
|
|
FormRange,
|
2021-12-02 12:09:12 +01:00
|
|
|
MkButton,
|
2021-07-19 16:30:45 +02:00
|
|
|
FormRadios,
|
2020-07-11 03:13:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
form: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
emits: ["done"],
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2020-07-11 03:13:11 +02:00
|
|
|
data() {
|
|
|
|
return {
|
2022-07-01 09:43:38 +02:00
|
|
|
values: {},
|
2022-11-11 09:41:34 +01:00
|
|
|
i18n,
|
2020-07-11 03:13:11 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
for (const item in this.form) {
|
2022-07-04 16:39:04 +02:00
|
|
|
this.values[item] = this.form[item].default ?? null;
|
2020-07-11 03:13:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
ok() {
|
2023-04-08 02:01:42 +02:00
|
|
|
this.$emit("done", {
|
2022-07-01 09:43:38 +02:00
|
|
|
result: this.values,
|
2020-10-17 13:12:00 +02:00
|
|
|
});
|
|
|
|
this.$refs.dialog.close();
|
2020-07-11 03:13:11 +02:00
|
|
|
},
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
cancel() {
|
2023-04-08 02:01:42 +02:00
|
|
|
this.$emit("done", {
|
2022-07-01 09:43:38 +02:00
|
|
|
canceled: true,
|
2020-10-17 13:12:00 +02:00
|
|
|
});
|
|
|
|
this.$refs.dialog.close();
|
2022-07-01 09:43:38 +02:00
|
|
|
},
|
|
|
|
},
|
2020-07-11 03:13:11 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.xkpnjxcv {
|
|
|
|
}
|
|
|
|
</style>
|