2018-05-23 12:26:51 +00:00
|
|
|
import ngModule from '../../module';
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-05-23 12:26:51 +00:00
|
|
|
class Controller {
|
2018-07-16 06:00:04 +00:00
|
|
|
constructor($http, $scope, $stateParams) {
|
2017-09-28 12:34:18 +00:00
|
|
|
this.$http = $http;
|
|
|
|
this.$scope = $scope;
|
2018-07-16 06:00:04 +00:00
|
|
|
this.$stateParams = $stateParams;
|
|
|
|
this.filter = {
|
|
|
|
include: {
|
|
|
|
observations: 'observationType'
|
|
|
|
},
|
2019-02-28 07:55:34 +00:00
|
|
|
order: ['isActive DESC', 'nickname ASC']
|
2018-07-16 06:00:04 +00:00
|
|
|
};
|
2017-09-28 12:34:18 +00:00
|
|
|
}
|
2018-07-16 06:00:04 +00:00
|
|
|
|
2019-02-28 07:55:34 +00:00
|
|
|
get client() {
|
|
|
|
return this._client;
|
|
|
|
}
|
|
|
|
|
|
|
|
set client(value) {
|
|
|
|
this._client = value;
|
|
|
|
this.sortAddresses();
|
|
|
|
}
|
|
|
|
|
|
|
|
get addresses() {
|
|
|
|
return this._addresses;
|
|
|
|
}
|
|
|
|
|
|
|
|
set addresses(value) {
|
|
|
|
this._addresses = value;
|
|
|
|
this.sortAddresses();
|
|
|
|
}
|
|
|
|
|
2018-02-08 08:04:29 +00:00
|
|
|
setDefault(address) {
|
2019-02-28 07:55:34 +00:00
|
|
|
let query = `/client/api/Clients/${this.$stateParams.id}`;
|
|
|
|
let params = {defaultAddressFk: address.id};
|
|
|
|
this.$http.patch(query, params).then(res => {
|
|
|
|
if (res.data) {
|
|
|
|
this.client.defaultAddressFk = res.data.defaultAddressFk;
|
|
|
|
this.sortAddresses();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
isDefaultAddress(address) {
|
|
|
|
if (!this.client) return;
|
|
|
|
return this.client.defaultAddressFk === address.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort address by default address
|
|
|
|
*/
|
|
|
|
sortAddresses() {
|
|
|
|
if (!this.client || !this.addresses) return;
|
|
|
|
this.$scope.model.data = this.addresses.sort((a, b) => {
|
|
|
|
return this.isDefaultAddress(b) - this.isDefaultAddress(a);
|
|
|
|
});
|
2017-09-28 12:34:18 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-16 06:00:04 +00:00
|
|
|
Controller.$inject = ['$http', '$scope', '$stateParams'];
|
2017-09-28 12:34:18 +00:00
|
|
|
|
2018-05-23 12:26:51 +00:00
|
|
|
ngModule.component('vnClientAddressIndex', {
|
|
|
|
template: require('./index.html'),
|
2019-02-28 07:55:34 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
client: '<'
|
|
|
|
}
|
2017-06-03 11:01:47 +00:00
|
|
|
});
|