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 {
|
|
|
|
constructor($element, $scope, $http, $translate, vnApp) {
|
|
|
|
super($element, $scope);
|
|
|
|
this.$ = $scope;
|
|
|
|
this.$http = $http;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
onResponse(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response == 'accept') {
|
2019-07-08 12:07:09 +00:00
|
|
|
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`);
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
this.$http.patch(`postcodes`, this.data).then(response => {
|
2019-07-08 12:07:09 +00:00
|
|
|
if (response.data) {
|
|
|
|
this.vnApp.showMessage(this.$translate.instant('The postcode has been saved'));
|
|
|
|
|
|
|
|
this.emit('response', {response: response.data});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
this.vnApp.showError(this.$translate.instant(e.message));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$element', '$scope', '$http', '$translate', 'vnApp'];
|
|
|
|
|
|
|
|
ngModule.component('vnClientPostcode', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
data: '<',
|
|
|
|
}
|
|
|
|
});
|