89 lines
2.0 KiB
JavaScript
89 lines
2.0 KiB
JavaScript
import ngModule from '../../module';
|
|
import Section from 'salix/components/section';
|
|
|
|
export default class Controller extends Section {
|
|
removeObservation(index) {
|
|
this.$.watcher.setDirty();
|
|
this.$.model.remove(index);
|
|
}
|
|
|
|
cancel() {
|
|
this.goToIndex();
|
|
}
|
|
|
|
goToIndex() {
|
|
this.$state.go('client.card.address.index');
|
|
}
|
|
|
|
onSubmit() {
|
|
this.$.watcher.submit()
|
|
.then(() => this.$.model.save(true))
|
|
.then(() => {
|
|
this.card.reload();
|
|
this.goToIndex();
|
|
});
|
|
}
|
|
|
|
showCustomAgent(event) {
|
|
if (event.defaultPrevented) return;
|
|
event.preventDefault();
|
|
|
|
this.$.customAgent.show();
|
|
}
|
|
|
|
onCustomAgentAccept() {
|
|
return this.$http.post(`CustomsAgents`, this.newCustomsAgent)
|
|
.then(res => this.address.customsAgentFk = res.data.id);
|
|
}
|
|
|
|
get town() {
|
|
return this._town;
|
|
}
|
|
|
|
// Town auto complete
|
|
set town(selection) {
|
|
const oldValue = this._town;
|
|
this._town = selection;
|
|
|
|
if (!oldValue) return;
|
|
|
|
const province = selection.province;
|
|
const postcodes = selection.postcodes;
|
|
|
|
this.address.provinceFk = province.id;
|
|
|
|
if (postcodes.length === 1)
|
|
this.address.postalCode = postcodes[0].code;
|
|
}
|
|
|
|
get postcode() {
|
|
return this._postcode;
|
|
}
|
|
|
|
// Postcode auto complete
|
|
set postcode(selection) {
|
|
const oldValue = this._postcode;
|
|
this._postcode = selection;
|
|
|
|
if (!oldValue) return;
|
|
|
|
const town = selection.town;
|
|
const province = town.province;
|
|
|
|
this.address.city = town.name;
|
|
this.address.provinceFk = province.id;
|
|
}
|
|
|
|
onResponse(response) {
|
|
this.address.postalCode = response.code;
|
|
}
|
|
}
|
|
|
|
ngModule.component('vnClientAddressEdit', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
require: {
|
|
card: '^vnClientCard'
|
|
}
|
|
});
|