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