merge
This commit is contained in:
commit
dead10641b
|
@ -5,11 +5,12 @@ export const NAME = 'vnClientAddressesDataEdit';
|
|||
export const COMPONENT = {
|
||||
template: template,
|
||||
controllerAs: 'addressData',
|
||||
controller: function($http, $stateParams) {
|
||||
controller: function($http, $stateParams, copyObject, equalsObject) {
|
||||
this.address = {};
|
||||
$http.get(`/client/api/Addresses/${$stateParams.addressId}`).then(
|
||||
json => {
|
||||
this.address = json.data;
|
||||
this.copyAddress();
|
||||
}
|
||||
);
|
||||
$http.get('/client/api/Agencies').then(
|
||||
|
@ -24,10 +25,22 @@ export const COMPONENT = {
|
|||
);
|
||||
|
||||
this.submit = function() {
|
||||
$http.put('/client/api/Addresses', this.address);
|
||||
if (!equalsObject(this.address, this.addressOld)) {
|
||||
$http.put('/client/api/Addresses', this.address).then(
|
||||
json => {
|
||||
this.address = json.data;
|
||||
this.copyAddress();
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
this.copyAddress = () => {
|
||||
this.addressOld = {};
|
||||
copyObject(this.address, this.addressOld);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
COMPONENT.controller.$inject = ['$http', '$stateParams'];
|
||||
COMPONENT.controller.$inject = ['$http', '$stateParams', 'copyObject', 'equalsObject'];
|
||||
module.component(NAME, COMPONENT);
|
||||
|
|
|
@ -8,10 +8,9 @@ export const COMPONENT = {
|
|||
bindings: {
|
||||
client: '<'
|
||||
},
|
||||
controller: function($http, $state)
|
||||
{
|
||||
controller: function($http, $state) {
|
||||
var self = this;
|
||||
let numPerPage = 2;
|
||||
let numPerPage = 5;
|
||||
let numRecords = 0;
|
||||
|
||||
this.$onChanges = function(changes) {
|
||||
|
@ -31,13 +30,14 @@ export const COMPONENT = {
|
|||
);
|
||||
};
|
||||
$http.get('/client/api/Addresses').then(
|
||||
json => this.addresses = json.data
|
||||
json => {
|
||||
this.addresses = json.data;
|
||||
}
|
||||
);
|
||||
|
||||
this.getNumPages = () => {
|
||||
var nPages = numRecords / numPerPage;
|
||||
if (nPages > 0)
|
||||
self.numPages = (nPages % 2) ? Math.ceil(nPages) : Math.ceil(nPages) + 1;
|
||||
self.numPages = Math.ceil(nPages);
|
||||
};
|
||||
|
||||
this.figureOutToDisplay = () => {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
module.exports = function(Address) {
|
||||
|
||||
Address.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'});
|
||||
function isEnabled(err) {
|
||||
if (!this.enabled && this.default) err();
|
||||
}
|
||||
|
||||
Address.observe('before save', function (ctx, next) {
|
||||
if (ctx.data.enabled && ctx.data.default) {
|
||||
ctx.Model.update({client: ctx.data.client}, {default: false});
|
||||
}
|
||||
next();
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue