salix/modules/worker/front/descriptor/index.js

76 lines
2.1 KiB
JavaScript
Raw Normal View History

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() {
return this.entity;
2019-10-21 12:21:52 +00:00
}
set worker(value) {
this.entity = value;
if (value)
this.getIsExcluded();
2023-10-16 13:58:25 +00:00
if (this.entity && !this.entity.user.emailVerified)
this.getPassRequirements();
}
2019-10-21 12:21:52 +00:00
getIsExcluded() {
this.$http.get(`WorkerDisableExcludeds/${this.entity.id}/exists`).then(data => {
this.workerExcluded = data.data.exists;
});
}
handleExcluded() {
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
}
loadData() {
const filter = {
2024-04-15 12:44:18 +00:00
where: {id: this.id},
2019-10-21 12:21:52 +00:00
};
2024-02-12 15:10:58 +00:00
2024-04-15 12:44:18 +00:00
return this.getData(`Workers/summary`, {filter})
.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!'));
}).then(() => this.loadData());
2023-10-16 13:58:25 +00:00
}
2019-10-21 12:21:52 +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: '<'
}
});