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

93 lines
2.2 KiB
JavaScript

import ngModule from '../module';
import Component from 'core/lib/component';
class Controller extends Component {
constructor($element, $) {
super($element, $);
this.worker = null;
this._quicklinks = {};
}
set workerFk(workerFk) {
if (workerFk == this._workerFk) return;
this._workerFk = workerFk;
this.worker = null;
this.loadData();
}
get workerFk() {
return this._workerFk;
}
get quicklinks() {
return this._quicklinks;
}
set quicklinks(value = {}) {
Object.keys(value).forEach(key => {
this._quicklinks[key] = value[key];
});
}
show() {
this.$.popover.parent = this.parent;
this.$.popover.show();
}
loadData() {
let query = `Workers/findOne`;
let filter = {
where: {
id: this._workerFk
},
include: [
{
relation: 'user',
scope: {
fields: ['name'],
include: {
relation: 'emailUser',
scope: {
fields: ['email']
}
}
}
},
{
relation: 'client',
scope: {fields: ['fi']}
},
{
relation: 'sip',
scope: {fields: ['extension']}
},
{
relation: 'department',
scope: {
include: {
relation: 'department'
}
}
}
]
};
this.$http.get(query, {params: {filter}}).then(res => {
this.worker = res.data;
this.$.$applyAsync(() => {
this.$.popover.relocate();
});
});
}
}
ngModule.component('vnWorkerDescriptorPopover', {
template: require('./index.html'),
controller: Controller,
bindings: {
workerFk: '<',
quicklinks: '<'
}
});