2018-05-23 12:26:51 +00:00
|
|
|
import ngModule from '../../module';
|
2017-02-07 11:58:25 +00:00
|
|
|
|
2017-06-07 06:39:40 +00:00
|
|
|
export default class Controller {
|
2018-05-31 09:52:39 +00:00
|
|
|
constructor($scope, $state) {
|
|
|
|
this.$ = $scope;
|
2018-02-01 12:28:45 +00:00
|
|
|
this.$state = $state;
|
2018-05-31 09:52:39 +00:00
|
|
|
this.$stateParams = $state.params;
|
2018-01-30 13:47:47 +00:00
|
|
|
}
|
2018-02-01 12:28:45 +00:00
|
|
|
|
|
|
|
removeObservation(index) {
|
2018-05-31 09:52:39 +00:00
|
|
|
this.$.watcher.setDirty();
|
|
|
|
this.$.model.remove(index);
|
2018-02-07 12:10:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 07:28:38 +00:00
|
|
|
cancel() {
|
2018-07-25 11:37:27 +00:00
|
|
|
this.goToIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
goToIndex() {
|
|
|
|
this.$state.go('client.card.address.index');
|
|
|
|
}
|
|
|
|
|
2019-07-08 12:07:09 +00:00
|
|
|
get postcodeSelection() {
|
|
|
|
return this._postcodeSelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
set postcodeSelection(selection) {
|
2019-07-17 05:33:46 +00:00
|
|
|
const hasValue = this._postcodeSelection;
|
2019-07-08 12:07:09 +00:00
|
|
|
this._postcodeSelection = selection;
|
|
|
|
|
2019-07-17 05:33:46 +00:00
|
|
|
if (!selection || !hasValue) return;
|
2019-07-08 12:07:09 +00:00
|
|
|
|
|
|
|
const town = selection.town;
|
2019-06-13 11:08:11 +00:00
|
|
|
const province = town.province;
|
|
|
|
|
2019-07-08 12:07:09 +00:00
|
|
|
this.address.city = town.name;
|
2019-06-13 11:08:11 +00:00
|
|
|
this.address.provinceFk = province.id;
|
|
|
|
}
|
|
|
|
|
2019-07-08 12:07:09 +00:00
|
|
|
onResponse(response) {
|
|
|
|
this.address.postalCode = response.code;
|
|
|
|
}
|
|
|
|
|
2019-06-13 11:08:11 +00:00
|
|
|
onSubmit() {
|
2018-05-31 09:52:39 +00:00
|
|
|
this.$.watcher.check();
|
|
|
|
this.$.watcher.realSubmit()
|
|
|
|
.then(() => this.$.model.save(true))
|
|
|
|
.then(() => {
|
|
|
|
this.$.watcher.setPristine();
|
|
|
|
this.$.watcher.notifySaved();
|
2018-05-02 09:54:13 +00:00
|
|
|
this.card.reload();
|
2018-07-25 11:37:27 +00:00
|
|
|
this.goToIndex();
|
2018-02-01 12:28:45 +00:00
|
|
|
});
|
2018-03-16 14:08:36 +00:00
|
|
|
}
|
2017-06-07 06:39:40 +00:00
|
|
|
}
|
2018-05-31 09:52:39 +00:00
|
|
|
Controller.$inject = ['$scope', '$state'];
|
2017-06-07 06:39:40 +00:00
|
|
|
|
2018-05-23 12:26:51 +00:00
|
|
|
ngModule.component('vnClientAddressEdit', {
|
|
|
|
template: require('./index.html'),
|
2018-05-02 09:54:13 +00:00
|
|
|
controller: Controller,
|
|
|
|
require: {
|
|
|
|
card: '^vnClientCard'
|
|
|
|
}
|
2017-06-03 11:01:47 +00:00
|
|
|
});
|