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