import ngModule from '../../module';
import Section from 'salix/components/section';

class Controller extends Section {
    constructor($element, $) {
        super($element, $);
        this.filter = {
            include:
                {relation: 'agency',
                    scope: {
                        fields: ['id', 'name']
                    }
                }
        };
    }

    add() {
        this.$.model.insert({});
    }

    onSubmit() {
        this.$.watcher.check();
        this.$.model.save().then(() => {
            this.$.watcher.notifySaved();
            this.$.watcher.updateOriginalData();
        });
    }
}

ngModule.vnComponent('vnSupplierAgencyTermIndex', {
    template: require('./index.html'),
    controller: Controller,
    bindings: {
        supplier: '<'
    }
});