56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
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;
|
|
|
|
this.data.provinceFk = province.id;
|
|
this.data.countryFk = country.id;
|
|
}
|
|
|
|
open() {
|
|
this.$.postcodeDialog.show();
|
|
}
|
|
|
|
onOpen() {
|
|
this.$.postcode.focus();
|
|
}
|
|
|
|
onAccept() {
|
|
try {
|
|
if (!this.data.code)
|
|
throw new Error(`The postcode can't be empty`);
|
|
if (!this.data.townFk)
|
|
throw new Error(`The town can't be empty`);
|
|
|
|
this.$http.patch(`postcodes`, this.data).then(res => {
|
|
this.vnApp.showMessage(this.$t('The postcode has been saved'));
|
|
this.emit('response', {$response: res.data});
|
|
});
|
|
} catch (e) {
|
|
this.vnApp.showError(this.$t(e.message));
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
ngModule.component('vnClientPostcode', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
data: '<',
|
|
}
|
|
});
|