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

70 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-05-16 06:54:54 +00:00
import ngModule from '../../module';
2023-05-15 11:15:33 +00:00
import Descriptor from 'salix/components/descriptor';
class Controller extends Descriptor {
constructor($element, $, $rootScope) {
super($element, $);
this.$rootScope = $rootScope;
}
2023-05-16 11:10:26 +00:00
get department() {
return this.entity;
}
2023-05-15 11:15:33 +00:00
2023-05-16 11:10:26 +00:00
set department(value) {
this.entity = value;
}
2023-05-30 11:21:57 +00:00
2023-05-30 13:13:16 +00:00
filterDepartments(department, event) {
if (event.defaultPrevented) return;
event.preventDefault();
event.stopPropagation();
this.$state.go(`worker.index`,
{q: JSON.stringify({departmentFk: department.id})});
}
2023-05-30 11:21:57 +00:00
deleteDepartment() {
return this.$http.post(`Departments/${this.id}/setDeleted`)
.then(() => this.reload())
.then(() => {
const isInsideDepartment = this.$state.current.name.startsWith('department');
if (isInsideDepartment)
this.$state.go('department.index');
this.vnApp.showSuccess(this.$t('Department deleted.'));
});
}
2023-05-16 11:10:26 +00:00
loadData() {
const filter = {
2023-05-26 12:08:37 +00:00
fields: ['id', 'name', 'code', 'workerFk', 'isProduction', 'chatName',
2023-05-26 12:23:34 +00:00
'isTeleworking', 'notificationEmail', 'hasToRefill', 'hasToSendMail', 'hasToMistake', 'clientFk'],
2023-05-16 11:10:26 +00:00
include: [
{relation: 'client',
scope: {
fields: ['id', 'name']
}},
2023-05-26 12:08:37 +00:00
{
relation: 'worker',
scope: {
fields: ['id', 'firstName', 'lastName']
}
2023-05-16 11:10:26 +00:00
}
]
};
2023-05-15 11:15:33 +00:00
return this.getData(`Departments/${this.id}`, {filter})
2023-05-16 11:10:26 +00:00
.then(res => this.entity = res.data);
}
2023-05-15 11:15:33 +00:00
}
Controller.$inject = ['$element', '$scope', '$rootScope'];
ngModule.vnComponent('vnWorkerDepartmentDescriptor', {
template: require('./index.html'),
controller: Controller,
bindings: {
department: '<'
2023-05-15 11:15:33 +00:00
}
});