2019-07-08 12:07:09 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Component from 'core/lib/component';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller extends Component {
|
|
|
|
get townSelection() {
|
|
|
|
return this._townSelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
set townSelection(selection) {
|
|
|
|
this._townSelection = selection;
|
|
|
|
|
|
|
|
if (!selection) return;
|
|
|
|
|
|
|
|
const province = selection.province;
|
|
|
|
const country = province.country;
|
|
|
|
|
2020-10-14 09:33:42 +00:00
|
|
|
this.location.city = selection.name;
|
|
|
|
this.location.provinceFk = province.id;
|
|
|
|
this.location.countryFk = country.id;
|
2019-07-08 12:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
open() {
|
|
|
|
this.$.postcodeDialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
onOpen() {
|
2020-10-14 09:33:42 +00:00
|
|
|
this.location = {};
|
2019-07-08 12:07:09 +00:00
|
|
|
this.$.postcode.focus();
|
|
|
|
}
|
|
|
|
|
2020-10-14 09:33:42 +00:00
|
|
|
onProvinceResponse(response) {
|
|
|
|
this.location.provinceFk = response.id;
|
|
|
|
this.location.countryFk = response.countryFk;
|
|
|
|
}
|
|
|
|
|
|
|
|
onCityResponse(response) {
|
|
|
|
this.location.townFk = response.id;
|
|
|
|
this.location.provinceFk = response.provinceFk;
|
|
|
|
this.location.countryFk = response.countryFk;
|
|
|
|
}
|
|
|
|
|
2020-02-24 10:27:36 +00:00
|
|
|
onAccept() {
|
|
|
|
try {
|
2020-10-14 09:33:42 +00:00
|
|
|
if (!this.location.code)
|
2020-02-24 10:27:36 +00:00
|
|
|
throw new Error(`The postcode can't be empty`);
|
2020-10-14 09:33:42 +00:00
|
|
|
if (!this.location.townFk)
|
2020-02-24 10:27:36 +00:00
|
|
|
throw new Error(`The town can't be empty`);
|
2020-10-14 09:33:42 +00:00
|
|
|
if (!this.location.provinceFk)
|
|
|
|
throw new Error(`The province can't be empty`);
|
|
|
|
if (!this.location.provinceFk)
|
|
|
|
throw new Error(`The country can't be empty`);
|
2019-07-08 12:07:09 +00:00
|
|
|
|
2020-10-14 09:33:42 +00:00
|
|
|
this.$http.patch(`postcodes`, this.location).then(() => {
|
|
|
|
this.vnApp.showMessage(this.$t('The postcode has been created. You can save the data now'));
|
|
|
|
this.emit('response', {$response: this.location});
|
2020-02-24 10:27:36 +00:00
|
|
|
});
|
|
|
|
} catch (e) {
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showError(this.$t(e.message));
|
2020-02-24 10:27:36 +00:00
|
|
|
return false;
|
2019-07-08 12:07:09 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-14 09:33:42 +00:00
|
|
|
ngModule.vnComponent('vnGeoPostcode', {
|
2019-07-08 12:07:09 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
data: '<',
|
|
|
|
}
|
|
|
|
});
|