import ngModule from '../module';
import ModuleCard from 'salix/components/module-card';

class Controller extends ModuleCard {
    reload() {
        let filter = {
            include: [
                {
                    relation: 'user',
                    scope: {
                        fields: ['name'],
                        include: {
                            relation: 'emailUser',
                            scope: {
                                fields: ['email']
                            }
                        }
                    }
                }, {
                    relation: 'sip',
                    scope: {
                        fields: ['extension', 'secret']
                    }
                }, {
                    relation: 'department',
                    scope: {
                        include: {
                            relation: 'department'
                        }
                    }
                }, {
                    relation: 'phones',
                    scope: {
                        fields: ['phone'],
                        order: 'typeFk ASC'
                    }
                }
            ]
        };

        this.$http.get(`Workers/${this.$params.id}`, {filter})
            .then(res => this.worker = res.data);
    }
}

ngModule.component('vnWorkerCard', {
    template: require('./index.html'),
    controller: Controller
});