Files
mixtape/zero.Backoffice.UI/app/modules/integrations/integration.vue
T

118 lines
3.6 KiB
Vue
Raw Normal View History

2021-12-21 15:51:26 +01:00
<template>
2021-12-22 15:41:11 +01:00
<ui-form ref="form" v-slot="form" @submit="onSubmit" @load="onLoad">
<ui-trinity class="ui-editor-overlay integration">
<template v-slot:header>
2021-12-23 08:38:01 +01:00
<ui-header-bar :title="integration.name" prefix="@integration.list" :back-button="false" :close-button="true" @close="config.close" />
2021-12-21 15:51:26 +01:00
</template>
2021-12-22 15:41:11 +01:00
<template v-slot:footer>
2021-12-23 08:38:01 +01:00
<ui-toggle v-if="integration.isConfigured" class="is-accent" v-model:on="model.isActive" on-content="Active" off-content="Inactive" :content-left="true" style="margin-right: 30px;" />
2021-12-22 15:41:11 +01:00
<ui-button type="light onbg" label="@ui.close" @click="config.close"></ui-button>
<template v-if="integration.isConfigured">
<ui-button type="light onbg" label="@ui.remove" @click="onDelete"></ui-button>
2021-12-23 08:38:01 +01:00
<ui-button v-if="!disabled" type="accent" :submit="true" label="@ui.save" :state="form.state" :disabled="loading"></ui-button>
2021-12-22 15:41:11 +01:00
</template>
<template v-if="!integration.isConfigured && !disabled">
<ui-button type="light onbg" :submit="true" label="@ui.save" :state="form.state" :disabled="loading"></ui-button>
<ui-button type="accent" @click="saveAndActivate" label="Save and activate" :state="form.state" :disabled="loading"></ui-button>
</template>
</template>
<ui-loading v-if="loading" :is-big="true" />
<div v-if="!loading" class="ui-editor-overlay-editor">
<ui-editor :config="editor" v-model="model" :meta="meta" :is-page="false" infos="none" :disabled="disabled" />
</div>
</ui-trinity>
2021-12-21 15:51:26 +01:00
</ui-form>
</template>
<script>
2021-12-22 15:41:11 +01:00
import * as overlays from '../../services/overlay';
//import Notification from 'zero/helpers/notification.js';
2021-12-21 15:51:26 +01:00
import api from './api';
export default {
2021-12-22 15:41:11 +01:00
props: {
config: Object
},
2021-12-21 15:51:26 +01:00
data: () => ({
2021-12-22 15:41:11 +01:00
integration: {},
disabled: false,
loading: true,
state: 'default',
editor: null,
2021-12-21 15:51:26 +01:00
meta: {},
2021-12-22 15:41:11 +01:00
model: {}
2021-12-21 15:51:26 +01:00
}),
2021-12-22 15:41:11 +01:00
created()
{
this.integration = { ...this.config.model };
//this.$el.style.setProperty('--color-primary', this.config.model.color);
//this.$el.style.setProperty('--color-button', this.config.model.color);
},
2021-12-21 15:51:26 +01:00
methods: {
async onLoad(form)
{
2021-12-22 15:41:11 +01:00
const alias = this.integration.alias;
this.editor = this.integration.editorAlias || 'integration.' + alias;
const response = await form.load(() => this.integration.isConfigured ? api.getByAlias(alias) : api.getEmpty(alias));
2021-12-21 15:51:26 +01:00
this.model = response;
2021-12-22 15:41:11 +01:00
this.loading = false;
},
saveAndActivate(e)
{
this.model.isActive = true;
this.onSubmit(this.$refs.form);
2021-12-21 15:51:26 +01:00
},
async onSubmit(form)
{
2021-12-22 15:41:11 +01:00
const response = this.integration.isConfigured ? await api.update(this.model) : await api.create(this.model);
2021-12-21 15:51:26 +01:00
await form.handle(response);
2021-12-22 15:41:11 +01:00
if (response.success)
{
this.config.confirm(response.data);
}
2021-12-21 15:51:26 +01:00
},
2021-12-22 15:41:11 +01:00
async onDelete()
2021-12-21 15:51:26 +01:00
{
2021-12-22 15:41:11 +01:00
const result = await overlays.confirmDelete();
if (result.eventType === 'confirm')
{
2021-12-23 08:38:01 +01:00
result.value.state('loading');
2021-12-22 15:41:11 +01:00
const response = await api.delete(this.integration.alias);
if (response.success)
{
2021-12-23 08:38:01 +01:00
result.value.state('success');
2021-12-22 15:41:11 +01:00
result.close();
//Notification.success('@deleteoverlay.success', '@deleteoverlay.success_text');
this.config.confirm(response);
}
2021-12-23 08:38:01 +01:00
else
{
result.value.state('error');
}
2021-12-22 15:41:11 +01:00
}
2021-12-21 15:51:26 +01:00
}
}
}
</script>