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

97 lines
2.4 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
import Component from 'core/lib/component';
class Controller extends Component {
constructor($element, $scope, $http, $timeout, $q) {
super($element, $scope);
this.$timeout = $timeout;
this.$http = $http;
this.$q = $q;
this.worker = null;
2019-05-07 09:32:35 +00:00
this._quicklinks = {};
}
2019-04-25 06:28:23 +00:00
set workerFk(workerFk) {
if (workerFk == this._workerFk) return;
2019-04-25 06:28:23 +00:00
this._workerFk = workerFk;
this.worker = null;
this.loadData();
}
2019-04-25 06:28:23 +00:00
get workerFk() {
return this._workerFk;
}
get quicklinks() {
return this._quicklinks;
}
2019-05-07 09:32:35 +00:00
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: {
2019-04-25 06:28:23 +00:00
id: this._workerFk
},
include: [
{
relation: 'user',
2019-03-15 11:58:26 +00:00
scope: {
fields: ['name'],
include: {
relation: 'emailUser',
scope: {
fields: ['email']
}
}
}
},
{
relation: 'client',
scope: {fields: ['fi']}
2019-03-15 11:58:26 +00:00
},
{
relation: 'sip',
scope: {fields: ['extension']}
2019-03-15 11:58:26 +00:00
},
{
relation: 'department',
scope: {
include: {
relation: 'department'
}
}
}
]
};
this.$http.get(query, {params: {filter}}).then(res => {
this.worker = res.data;
this.$.$applyAsync(() => {
this.$.popover.relocate();
});
});
}
}
Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q'];
ngModule.component('vnWorkerDescriptorPopover', {
template: require('./index.html'),
controller: Controller,
bindings: {
2019-04-25 06:28:23 +00:00
workerFk: '<',
quicklinks: '<'
}
});