Files
mixtape/zero.Backoffice.UI/old_app/pages/settings/user.vue
T

121 lines
3.5 KiB
Vue
Raw Normal View History

2020-04-08 13:07:15 +02:00
<template>
2020-07-06 13:08:51 +02:00
<ui-form ref="form" class="user" v-slot="form" @submit="onSubmit" @load="onLoad" :route="route">
2021-09-11 14:54:28 +02:00
<ui-form-header v-model="model" prefix="@user.users" title="@user.name" :disabled="disabled" :is-create="!$route.params.id" :state="form.state" :can-delete="meta.canDelete" @delete="onDelete">
2020-07-06 14:35:58 +02:00
<template v-slot:actions>
2021-09-07 15:53:47 +02:00
<ui-dropdown-button v-if="model.isActive" label="@ui.disable" icon="fth-minus-circle" @click="onActiveChange" :disabled="disabled" />
<ui-dropdown-button v-if="!model.isActive" label="@ui.enable" icon="fth-plus-circle" @click="onActiveChange" :disabled="disabled" />
2020-07-06 14:35:58 +02:00
</template>
</ui-form-header>
2020-09-17 11:26:23 +02:00
<ui-editor config="user" v-model="model" :meta="meta" :disabled="disabled">
2020-07-06 14:35:58 +02:00
<template v-slot:settings>
<ui-property label="@user.fields.isLockedOut" :is-text="true" class="is-toggle">
2020-09-17 11:26:23 +02:00
<ui-toggle :value="isLockedOut" :negative="true" @input="onLockoutChange" :disabled="disabled" />
2020-07-06 14:35:58 +02:00
</ui-property>
<p v-if="isLockedOut" class="ui-message type-error block user-aside-error">
<i class="ui-message-icon fth-alert-circle"></i>
<span class="ui-message-text">
<span v-localize:html="'@user.fields.isLockedOut_warning'"></span>:<br>
<strong><ui-date v-model="model.lockoutEnd" format="long" /></strong>
</span>
</p>
<ui-message v-if="!model.isActive" class="user-aside-error" type="error" text="@user.fields.isDisabled_warning" />
</template>
2021-01-09 19:09:31 +01:00
<template v-slot:below>
<ui-editor-infos v-model="model" :disabled="disabled" />
</template>
2020-07-06 14:35:58 +02:00
</ui-editor>
2020-07-06 13:08:51 +02:00
</ui-form>
</template>
2020-04-08 13:07:15 +02:00
<script>
2021-09-23 10:58:14 +02:00
import AuthApi from 'zero/helpers/auth.js';
2020-11-20 15:17:41 +01:00
import UsersApi from 'zero/api/users.js';
2020-07-06 13:08:51 +02:00
export default {
data: () => ({
meta: {},
model: {
avatarId: null,
name: null,
email: null,
2020-07-06 14:35:58 +02:00
lockoutEnd: null
2020-07-06 13:08:51 +02:00
},
2020-10-16 14:02:10 +02:00
route: zero.alias.settings.users + '-edit',
2020-07-06 14:35:58 +02:00
disabled: false,
originalLockoutEnd: null
2020-07-06 13:08:51 +02:00
}),
2020-07-06 14:35:58 +02:00
computed: {
isLockedOut()
{
return !!this.model.lockoutEnd;
}
},
2020-07-06 13:08:51 +02:00
methods: {
onLoad(form)
{
2020-10-19 14:48:21 +02:00
form.load(!this.$route.params.id ? UsersApi.getEmpty() : UsersApi.getById(this.$route.params.id)).then(response =>
2020-07-06 13:08:51 +02:00
{
this.disabled = !response.meta.canEdit;
this.meta = response.meta;
2020-07-06 14:35:58 +02:00
this.model = response.entity;
this.originalLockoutEnd = this.model.lockoutEnd;
2020-07-06 13:08:51 +02:00
});
},
onSubmit(form)
{
2020-07-06 14:35:58 +02:00
form.handle(UsersApi.save(this.model)).then(res =>
{
2021-09-23 10:58:14 +02:00
if (res.model.id === AuthApi.user.id)
2020-10-15 14:10:38 +02:00
{
2021-09-23 10:58:14 +02:00
AuthApi.setUser(res.model);
2020-10-15 14:10:38 +02:00
}
2020-07-06 14:35:58 +02:00
});
2020-07-06 13:08:51 +02:00
},
onDelete(item, opts)
{
opts.hide();
2020-10-19 14:48:21 +02:00
this.$refs.form.onDelete(UsersApi.delete.bind(this, this.$route.params.id));
2020-05-11 11:30:56 +02:00
},
onLockoutChange(locked)
{
this.model.lockoutEnd = locked ? this.originalLockoutEnd : null;
},
2020-05-11 11:30:56 +02:00
2020-07-06 14:35:58 +02:00
onActiveChange(value, opts)
{
opts.loading(true);
const isActive = !this.model.isActive;
let promise = isActive ? UsersApi.enable(this.model) : UsersApi.disable(this.model);
promise.then(response =>
{
opts.loading(false);
opts.hide();
if (response.success)
{
this.model.isActive = isActive;
}
});
},
2020-04-08 13:07:15 +02:00
}
}
</script>
<style lang="scss">
.user-aside-error
{
margin-bottom: 0;
}
2020-07-06 14:35:58 +02:00
</style>