import ngModule from '../module'; import Descriptor from 'salix/components/descriptor'; class Controller extends Descriptor { constructor($element, $, $rootScope) { super($element, $); this.$rootScope = $rootScope; } get worker() { return this.entity; } set worker(value) { this.entity = value; if (value) this.getIsExcluded(); } get excluded() { return this.entity.excluded; } set excluded(value) { this.entity.excluded = value; } getIsExcluded() { this.$http.get(`workerDisableExcludeds/${this.entity.id}/exists`).then(data => { this.excluded = data.data.exists; }); } handleExcluded() { if (this.excluded) { this.$http.delete(`workerDisableExcludeds/${this.entity.id}`); this.excluded = false; } else { this.$http.post(`workerDisableExcludeds`, {workerFk: this.entity.id, dated: new Date}); this.excluded = true; } } loadData() { const filter = { 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' } } } ] }; return this.getData(`Workers/${this.id}`, {filter}) .then(res => this.entity = res.data); } onUploadResponse() { const timestamp = new Date().getTime(); const src = this.$rootScope.imagePath('user', '520x520', this.worker.id); const zoomSrc = this.$rootScope.imagePath('user', '1600x1600', this.worker.id); const newSrc = `${src}&t=${timestamp}`; const newZoomSrc = `${zoomSrc}&t=${timestamp}`; this.$.photo.setAttribute('src', newSrc); this.$.photo.setAttribute('zoom-image', newZoomSrc); } } Controller.$inject = ['$element', '$scope', '$rootScope']; ngModule.vnComponent('vnWorkerDescriptor', { template: require('./index.html'), controller: Controller, bindings: { worker: '<' } });