import ngModule from '../module'; export default class Controller { constructor($scope, $state, $http, $translate, vnApp) { this.$ = $scope; this.$state = $state; this.$http = $http; this.$translate = $translate; this.vnApp = vnApp; this.client = { active: true }; } onResponse(response) { this.client.postcode = response.code; } onSubmit() { return this.$.watcher.submit().then( json => this.$state.go('client.card.basicData', {id: json.data.id}) ); } get province() { return this._province; } // Province auto complete set province(selection) { this._province = selection; if (!selection) return; const country = selection.country; this.client.countryFk = country.id; } get town() { return this._town; } // Town auto complete set town(selection) { this._town = selection; if (!selection) return; const province = selection.province; const country = province.country; const postcodes = selection.postcodes; this.client.provinceFk = province.id; this.client.countryFk = country.id; if (postcodes.length === 1) this.client.postcode = postcodes[0].code; } get postcode() { return this._postcode; } // Postcode auto complete set postcode(selection) { this._postcode = selection; if (!selection) return; const town = selection.town; const province = town.province; const country = province.country; this.client.city = town.name; this.client.provinceFk = province.id; this.client.countryFk = country.id; } } Controller.$inject = ['$scope', '$state', '$http', '$translate', 'vnApp']; ngModule.component('vnClientCreate', { template: require('./index.html'), controller: Controller });