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';
|
2024-04-18 13:19:19 +00:00
|
|
|
import UserError from 'core/lib/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();
|
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() {
|
2024-09-06 14:01:26 +00:00
|
|
|
return this.getData('Workers/descriptor', {filter: {where: {id: this.id}}})
|
|
|
|
.then(res => this.entity = res.data[0]);
|
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(
|
2024-02-13 09:10:48 +00:00
|
|
|
`Workers/${this.entity.id}/setPassword`, {newPass: this.newPassword}
|
2023-10-16 13:58:25 +00:00
|
|
|
) .then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Password changed!'));
|
2024-02-22 14:42:54 +00:00
|
|
|
}).then(() => this.loadData());
|
2023-10-16 13:58:25 +00:00
|
|
|
}
|
2019-10-21 12:21:52 +00:00
|
|
|
}
|
|
|
|
|
2024-02-22 14:42:54 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', '$rootScope', 'vnConfig'];
|
2020-11-27 12:10:39 +00:00
|
|
|
|
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: '<'
|
|
|
|
}
|
|
|
|
});
|