2017-06-03 11:01:47 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-17 10:17:50 +00:00
|
|
|
import Section from 'salix/components/section';
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2020-03-17 10:17:50 +00:00
|
|
|
export default class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2017-02-07 11:58:25 +00:00
|
|
|
this.client = {
|
|
|
|
active: true
|
2017-01-31 13:13:06 +00:00
|
|
|
};
|
|
|
|
}
|
2019-06-13 11:08:11 +00:00
|
|
|
|
2020-02-21 11:39:41 +00:00
|
|
|
onSubmit() {
|
|
|
|
return this.$.watcher.submit().then(
|
|
|
|
json => this.$state.go('client.card.basicData', {id: json.data.id})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get province() {
|
|
|
|
return this._province;
|
2019-07-08 12:07:09 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 11:39:41 +00:00
|
|
|
// Province auto complete
|
|
|
|
set province(selection) {
|
|
|
|
this._province = selection;
|
2019-07-08 12:07:09 +00:00
|
|
|
|
|
|
|
if (!selection) return;
|
|
|
|
|
2020-02-21 11:39:41 +00:00
|
|
|
const country = selection.country;
|
|
|
|
|
2020-05-21 09:14:34 +00:00
|
|
|
if (!this.client.countryFk)
|
|
|
|
this.client.countryFk = country.id;
|
2020-02-21 11:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get town() {
|
|
|
|
return this._town;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Town auto complete
|
|
|
|
set town(selection) {
|
|
|
|
this._town = selection;
|
|
|
|
|
|
|
|
if (!selection) return;
|
|
|
|
|
|
|
|
const province = selection.province;
|
2019-06-13 11:08:11 +00:00
|
|
|
const country = province.country;
|
2020-02-21 11:39:41 +00:00
|
|
|
const postcodes = selection.postcodes;
|
2019-06-13 11:08:11 +00:00
|
|
|
|
2020-05-21 09:14:34 +00:00
|
|
|
if (!this.client.provinceFk)
|
|
|
|
this.client.provinceFk = province.id;
|
|
|
|
|
|
|
|
if (!this.client.countryFk)
|
|
|
|
this.client.countryFk = country.id;
|
2020-02-21 11:39:41 +00:00
|
|
|
|
|
|
|
if (postcodes.length === 1)
|
|
|
|
this.client.postcode = postcodes[0].code;
|
2019-06-13 11:08:11 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 11:39:41 +00:00
|
|
|
get postcode() {
|
|
|
|
return this._postcode;
|
2019-07-08 12:07:09 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 11:39:41 +00:00
|
|
|
// Postcode auto complete
|
|
|
|
set postcode(selection) {
|
|
|
|
this._postcode = selection;
|
|
|
|
|
|
|
|
if (!selection) return;
|
|
|
|
|
|
|
|
const town = selection.town;
|
|
|
|
const province = town.province;
|
|
|
|
const country = province.country;
|
|
|
|
|
2020-05-21 09:14:34 +00:00
|
|
|
if (!this.client.city)
|
|
|
|
this.client.city = town.name;
|
|
|
|
|
|
|
|
if (!this.client.provinceFk)
|
|
|
|
this.client.provinceFk = province.id;
|
|
|
|
|
|
|
|
if (!this.client.countryFk)
|
|
|
|
this.client.countryFk = country.id;
|
2017-02-07 11:58:25 +00:00
|
|
|
}
|
2020-02-24 10:27:36 +00:00
|
|
|
|
|
|
|
onResponse(response) {
|
|
|
|
this.client.postcode = response.code;
|
|
|
|
}
|
2017-02-07 11:58:25 +00:00
|
|
|
}
|
2020-02-21 11:39:41 +00:00
|
|
|
|
2020-03-17 10:17:50 +00:00
|
|
|
Controller.$inject = ['$element', '$scope'];
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2017-06-03 11:01:47 +00:00
|
|
|
ngModule.component('vnClientCreate', {
|
2018-05-23 12:26:51 +00:00
|
|
|
template: require('./index.html'),
|
2017-02-07 11:58:25 +00:00
|
|
|
controller: Controller
|
2017-06-03 11:01:47 +00:00
|
|
|
});
|