Merge branch 'master' of ssh://git.verdnatura.es:/var/lib/git/salix

This commit is contained in:
Juan Ferrer Toribio 2017-01-25 13:36:21 +01:00
commit 50552b8a21
2 changed files with 25 additions and 24 deletions

View File

@ -11,28 +11,10 @@ export const COMPONENT = {
}, },
controller: function($http, $scope, copyObject) { controller: function($http, $scope, copyObject) {
var self = this; var self = this;
this.$onChanges = function(changes) {
if (this.client) {
this.copyClient();
}
};
$scope.$watch('descriptor.client.active', function(newValue, oldValue) { $scope.$watch('descriptor.client.active', function(newValue, oldValue) {
if (self.client && self.clientOld && self.client.active !== self.clientOld.active) { if (oldValue !== undefined)
var newClient = {id: self.client.id, active: self.client.active, modify: "Active"}; $http.put(`/client/api/Clients/${self.client.id}/activate`, {});
$http.put('/client/api/Clients', newClient).then(
json => {
self.client = json.data;
self.copyClient();
}
);
}
}); });
this.copyClient = function() {
this.clientOld = {};
copyObject(this.client, this.clientOld);
};
} }
}; };
COMPONENT.controller.$inject = ['$http', '$scope', 'copyObject']; COMPONENT.controller.$inject = ['$http', '$scope', 'copyObject'];

View File

@ -6,12 +6,33 @@ module.exports = function(Client) {
Client.validate('payMethod',hasCC,{message: 'Introduzca el iban del cliente'}); Client.validate('payMethod',hasCC,{message: 'Introduzca el iban del cliente'});
function hasCC(err) { function hasCC(err) {
if (this.payMethod == 2 && !this.iban) err(); if (this.payMethod == 2 && !this.iban) err();
} };
Client.validate('payMethod',hasSalesMan,{message: 'No se puede cambiar la forma de pago si no hay comercial asignado'}); Client.validate('payMethod',hasSalesMan,{message: 'No se puede cambiar la forma de pago si no hay comercial asignado'});
function hasSalesMan(err) { function hasSalesMan(err) {
if (this.payMethod && !this.salesPerson) err(); if (this.payMethod && !this.salesPerson) err();
} };
Client.remoteMethod('activate',
{
returns: {
arg: 'active',
type: 'boolean'
},
http: {
path: '/:id/activate', verb: 'put'
}
});
Client.activate = function(cb){
var id = 12;
Client.findById(id, function(err, client) {
if (!err) {
Client.update({id: client.id}, {active: !client.active});
cb(null, !client.active);
}
})
};
// Hooks // Hooks
Client.observe('before save', function (ctx, next) { Client.observe('before save', function (ctx, next) {
@ -27,8 +48,6 @@ module.exports = function(Client) {
if (item.payMethod != ctx.data.payMethod && item.dueDay == ctx.data.dueDay) { if (item.payMethod != ctx.data.payMethod && item.dueDay == ctx.data.dueDay) {
ctx.data.dueDay = 5; ctx.data.dueDay = 5;
} }
if(!ctx.data.name)
ctx.data.name = item.name;
} }
next(); next();
} }