salix/modules/client/front/address/edit/index.js

95 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-05-23 12:26:51 +00:00
import ngModule from '../../module';
2020-03-17 10:17:50 +00:00
import Section from 'salix/components/section';
2020-03-17 10:17:50 +00:00
export default class Controller extends Section {
2018-02-01 12:28:45 +00:00
removeObservation(index) {
this.$.watcher.setDirty();
this.$.model.remove(index);
2018-02-07 12:10:22 +00:00
}
cancel() {
2018-07-25 11:37:27 +00:00
this.goToIndex();
}
goToIndex() {
this.$state.go('client.card.address.index');
}
onSubmit() {
2020-01-28 08:03:20 +00:00
this.$.watcher.submit()
.then(() => this.$.model.save(true))
.then(() => {
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
}
2020-01-28 10:56:26 +00:00
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);
}
2020-02-24 10:27:36 +00:00
get town() {
return this._town;
}
// Town auto complete
set town(selection) {
2020-12-31 09:30:51 +00:00
const oldValue = this._town;
2020-02-24 10:27:36 +00:00
this._town = selection;
2020-12-31 09:30:51 +00:00
if (!selection || !oldValue) return;
2020-02-24 10:27:36 +00:00
const province = selection.province;
const postcodes = selection.postcodes;
2020-05-21 09:14:34 +00:00
if (!this.address.provinceFk)
this.address.provinceFk = province.id;
2020-02-24 10:27:36 +00:00
2020-11-04 10:37:54 +00:00
if (!this.address.postalCode && postcodes.length === 1)
2020-02-24 10:27:36 +00:00
this.address.postalCode = postcodes[0].code;
}
get postcode() {
return this._postcode;
}
// Postcode auto complete
set postcode(selection) {
2020-12-31 09:30:51 +00:00
const oldValue = this._postcode;
2020-02-24 10:27:36 +00:00
this._postcode = selection;
2020-12-31 09:30:51 +00:00
if (!selection || !oldValue) return;
2020-02-24 10:27:36 +00:00
const town = selection.town;
const province = town.province;
2020-05-21 09:14:34 +00:00
if (!this.address.city)
this.address.city = town.name;
if (!this.address.provinceFk)
this.address.provinceFk = province.id;
2020-02-24 10:27:36 +00:00
}
onResponse(response) {
this.address.postalCode = response.code;
2020-10-15 11:59:28 +00:00
this.address.city = response.city;
this.address.provinceFk = response.provinceFk;
2020-02-24 10:27:36 +00:00
}
2017-06-07 06:39:40 +00:00
}
ngModule.vnComponent('vnClientAddressEdit', {
2018-05-23 12:26:51 +00:00
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
});