Files
mixtape/zero.Backoffice.UI/app/modules/spaces/views/editor.vue
T

107 lines
2.8 KiB
Vue
Raw Normal View History

2021-12-19 14:18:16 +01:00
<template>
<ui-form ref="form" class="space-editor" v-slot="form" @submit="onSubmit" @load="onLoad" :route="route">
2022-01-12 11:39:32 +01:00
<ui-form-header v-model="model" :title="space.name" :title-disabled="space.view === 'editor'" :disabled="disabled" :is-create="isCreate" :state="form.state" :can-delete="meta.canDelete" @delete="onDelete" :active-toggle="true" />
2021-12-19 14:18:16 +01:00
<ui-editor v-if="editor" :config="editor" v-model="model" :meta="meta" :disabled="disabled" :active-toggle="false">
<template v-slot:below>
<ui-editor-infos v-model="model" :disabled="disabled" />
</template>
</ui-editor>
</ui-form>
</template>
<script>
import api from '../api';
import { defineComponent } from 'vue';
//import Overlay from 'zero/helpers/overlay.js';
export default defineComponent({
props: ['config', 'space'],
data: () => ({
disabled: false,
editor: null,
meta: {},
route: null, //zero.alias.sections.settings + '-' + zero.alias.settings.countries + '-edit',
model: { name: null }
}),
computed: {
id()
{
return this.$route.params.id;
},
alias()
{
return this.$route.params.alias;
},
isList()
{
return !!this.id;
2022-01-12 11:39:32 +01:00
},
isCreate()
{
return this.id === 'create';
2021-12-19 14:18:16 +01:00
}
},
watch: {
'$route': 'setup'
},
methods: {
async setup()
{
2022-01-12 11:39:32 +01:00
let alias = this.space.editorAlias || (this.space.alias + ':edit');
alias = alias.indexOf('spaces:') === 0 ? alias : 'spaces:' + alias;
this.editor = await this.zero.getSchema(alias);
2021-12-19 14:18:16 +01:00
},
2022-01-12 11:39:32 +01:00
2021-12-19 14:18:16 +01:00
async onLoad(form)
{
await this.setup();
2022-01-12 11:39:32 +01:00
var config = { system: this.$route.query['zero.scope'] == 'system' };
const response = await form.load(() => !this.isCreate ? api.getById(this.alias, this.id, undefined, config) : api.getEmpty(this.alias, config));
this.model = response;
//this.route = { name: 'spaces-edit', params: { alias: this.alias } };
2021-12-19 14:18:16 +01:00
},
2022-01-12 11:39:32 +01:00
async onSubmit(form)
2021-12-19 14:18:16 +01:00
{
2022-01-12 11:39:32 +01:00
var config = { system: this.$route.query['zero.scope'] == 'system' };
const response = !this.isCreate ? await api.update(this.model, config) : await api.create(this.model, config);
await form.handle(response);
2021-12-19 14:18:16 +01:00
},
onDelete(item, opts)
{
opts.hide();
2022-01-12 11:39:32 +01:00
var config = { system: this.$route.query['zero.scope'] == 'system' };
this.$refs.form.onDelete(api.delete.bind(this, this.id, config));
}
2021-12-19 14:18:16 +01:00
}
})
</script>
<style lang="scss">
.space-editor .ui-header-bar + .editor > .ui-box
{
margin-top: 0;
}
.space-editor .editor-outer.-infos-aside
{
grid-template-columns: 1fr;
.editor-infos
{
margin: -31px var(--padding) 0;
}
}
</style>