Merge branch 'master' of ssh://git.verdnatura.es:/var/lib/git/salix
This commit is contained in:
commit
50552b8a21
|
@ -11,28 +11,10 @@ export const COMPONENT = {
|
|||
},
|
||||
controller: function($http, $scope, copyObject) {
|
||||
var self = this;
|
||||
this.$onChanges = function(changes) {
|
||||
if (this.client) {
|
||||
this.copyClient();
|
||||
}
|
||||
};
|
||||
|
||||
$scope.$watch('descriptor.client.active', function(newValue, oldValue) {
|
||||
if (self.client && self.clientOld && self.client.active !== self.clientOld.active) {
|
||||
var newClient = {id: self.client.id, active: self.client.active, modify: "Active"};
|
||||
$http.put('/client/api/Clients', newClient).then(
|
||||
json => {
|
||||
self.client = json.data;
|
||||
self.copyClient();
|
||||
}
|
||||
);
|
||||
}
|
||||
if (oldValue !== undefined)
|
||||
$http.put(`/client/api/Clients/${self.client.id}/activate`, {});
|
||||
});
|
||||
|
||||
this.copyClient = function() {
|
||||
this.clientOld = {};
|
||||
copyObject(this.client, this.clientOld);
|
||||
};
|
||||
}
|
||||
};
|
||||
COMPONENT.controller.$inject = ['$http', '$scope', 'copyObject'];
|
||||
|
|
|
@ -6,12 +6,33 @@ module.exports = function(Client) {
|
|||
Client.validate('payMethod',hasCC,{message: 'Introduzca el iban del cliente'});
|
||||
function hasCC(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'});
|
||||
function hasSalesMan(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
|
||||
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) {
|
||||
ctx.data.dueDay = 5;
|
||||
}
|
||||
if(!ctx.data.name)
|
||||
ctx.data.name = item.name;
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue