2019-01-28 15:24:45 +00:00
|
|
|
import ngModule from '../module';
|
2020-04-25 09:50:04 +00:00
|
|
|
import Descriptor from 'salix/components/descriptor';
|
2023-10-16 13:58:25 +00:00
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
2020-04-25 09:50:04 +00:00
|
|
|
class Controller extends Descriptor {
|
2020-11-27 12:10:39 +00:00
|
|
|
constructor($element, $, $rootScope) {
|
|
|
|
super($element, $);
|
|
|
|
this.$rootScope = $rootScope;
|
|
|
|
}
|
|
|
|
|
2019-10-21 12:21:52 +00:00
|
|
|
get worker() {
|
2020-04-30 10:48:52 +00:00
|
|
|
return this.entity;
|
2019-10-21 12:21:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set worker(value) {
|
2020-04-30 10:48:52 +00:00
|
|
|
this.entity = value;
|
2022-10-18 08:25:54 +00:00
|
|
|
if (value)
|
|
|
|
this.getIsExcluded();
|
2024-02-12 15:10:58 +00:00
|
|
|
this.$http.get(`UserConfigs/getUserConfig`)
|
|
|
|
.then(res => this.userFk = res.data.userFk);
|
2023-10-16 13:58:25 +00:00
|
|
|
|
|
|
|
if (this.entity && !this.entity.user.emailVerified)
|
|
|
|
this.getPassRequirements();
|
2020-04-30 10:48:52 +00:00
|
|
|
}
|
2019-10-21 12:21:52 +00:00
|
|
|
|
2022-10-18 08:25:54 +00:00
|
|
|
getIsExcluded() {
|
2023-07-14 10:18:41 +00:00
|
|
|
this.$http.get(`WorkerDisableExcludeds/${this.entity.id}/exists`).then(data => {
|
|
|
|
this.workerExcluded = data.data.exists;
|
2022-10-18 08:25:54 +00:00
|
|
|
});
|
2022-10-06 08:18:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 08:25:54 +00:00
|
|
|
handleExcluded() {
|
2023-07-14 10:18:41 +00:00
|
|
|
if (this.workerExcluded)
|
|
|
|
this.$http.delete(`WorkerDisableExcludeds/${this.entity.id}`);
|
|
|
|
else
|
|
|
|
this.$http.post(`WorkerDisableExcludeds`, {workerFk: this.entity.id, dated: new Date});
|
|
|
|
|
|
|
|
this.workerExcluded = !this.workerExcluded;
|
2022-10-05 09:52:14 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
loadData() {
|
|
|
|
const filter = {
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'user',
|
|
|
|
scope: {
|
2023-10-16 13:58:25 +00:00
|
|
|
fields: ['name', 'emailVerified'],
|
2020-04-30 10:48:52 +00:00
|
|
|
include: {
|
|
|
|
relation: 'emailUser',
|
|
|
|
scope: {
|
|
|
|
fields: ['email']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'client',
|
|
|
|
scope: {
|
|
|
|
fields: ['fi']
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'sip',
|
|
|
|
scope: {
|
|
|
|
fields: ['extension']
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'department',
|
|
|
|
scope: {
|
|
|
|
include: {
|
|
|
|
relation: 'department'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2019-10-21 12:21:52 +00:00
|
|
|
};
|
2024-02-12 15:10:58 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
return this.getData(`Workers/${this.id}`, {filter})
|
|
|
|
.then(res => this.entity = res.data);
|
2019-10-21 12:21:52 +00:00
|
|
|
}
|
2023-10-16 13:58:25 +00:00
|
|
|
|
|
|
|
getPassRequirements() {
|
|
|
|
this.$http.get('UserPasswords/findOne')
|
|
|
|
.then(res => {
|
|
|
|
this.passRequirements = res.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setPassword() {
|
|
|
|
if (!this.newPassword)
|
|
|
|
throw new UserError(`You must enter a new password`);
|
|
|
|
if (this.newPassword != this.repeatPassword)
|
|
|
|
throw new UserError(`Passwords don't match`);
|
|
|
|
this.$http.patch(
|
|
|
|
`Workers/${this.entity.id}/setPassword`,
|
2024-02-12 15:10:58 +00:00
|
|
|
{workerFk: this.entity.id, newPass: this.newPassword, emailVerified: !!this.entity.user.emailVerified}
|
2023-10-16 13:58:25 +00:00
|
|
|
) .then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Password changed!'));
|
|
|
|
});
|
|
|
|
}
|
2019-10-21 12:21:52 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 12:10:39 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', '$rootScope'];
|
|
|
|
|
2020-04-25 09:50:04 +00:00
|
|
|
ngModule.vnComponent('vnWorkerDescriptor', {
|
2019-01-28 15:24:45 +00:00
|
|
|
template: require('./index.html'),
|
2019-10-21 12:21:52 +00:00
|
|
|
controller: Controller,
|
2019-01-28 15:24:45 +00:00
|
|
|
bindings: {
|
|
|
|
worker: '<'
|
|
|
|
}
|
|
|
|
});
|