import ngModule from '../../module'; export default class Controller { constructor($, $state) { this.$ = $; this.$state = $state; this.data = { address: { clientFk: parseInt($state.params.id), isActive: true }, isDefaultAddress: false }; this.address = this.data.address; } get postcodeSelection() { return this._postcodeSelection; } set postcodeSelection(selection) { this._postcodeSelection = selection; if (!selection) return; const town = selection.town; const province = town.province; const country = province.country; this.address.city = town.name; this.address.provinceFk = province.id; this.address.countryFk = country.id; } onResponse(response) { this.address.postalCode = response.code; } onSubmit() { this.$.watcher.submit().then(res => { if (res.data && this.data.isDefaultAddress) this.client.defaultAddressFk = res.data.id; this.$state.go('client.card.address.index'); }); } } Controller.$inject = ['$scope', '$state']; ngModule.component('vnClientAddressCreate', { template: require('./index.html'), controller: Controller, bindings: { client: '<' } });