Merge branch 'master' of ssh://git.verdnatura.es:/var/lib/git/salix
This commit is contained in:
commit
a2d56480f3
|
@ -5,7 +5,7 @@ export const NAME = 'vnClientAddressesDataEdit';
|
||||||
export const COMPONENT = {
|
export const COMPONENT = {
|
||||||
template: template,
|
template: template,
|
||||||
controllerAs: 'addressData',
|
controllerAs: 'addressData',
|
||||||
controller: function($http, $stateParams, copyObject, equalsObject, $window) {
|
controller: function($http, $stateParams, copyObject, equalsObject, $window, modified) {
|
||||||
this.address = {};
|
this.address = {};
|
||||||
$http.get(`/client/api/Addresses/${$stateParams.addressId}`).then(
|
$http.get(`/client/api/Addresses/${$stateParams.addressId}`).then(
|
||||||
json => {
|
json => {
|
||||||
|
@ -16,14 +16,13 @@ export const COMPONENT = {
|
||||||
|
|
||||||
this.submit = function() {
|
this.submit = function() {
|
||||||
if (!equalsObject(this.address, this.addressOld)) {
|
if (!equalsObject(this.address, this.addressOld)) {
|
||||||
$http.put('/client/api/Addresses', this.address).then(
|
var newAddress = modified(this.address, this.addressOld);
|
||||||
|
$http.put(`/client/api/Addresses/${this.addressOld.id}`, newAddress).then(
|
||||||
json => {
|
json => {
|
||||||
this.address = json.data;
|
$window.history.back();
|
||||||
this.copyAddress();
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$window.history.back();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.copyAddress = () => {
|
this.copyAddress = () => {
|
||||||
|
@ -33,5 +32,5 @@ export const COMPONENT = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
COMPONENT.controller.$inject = ['$http', '$stateParams', 'copyObject', 'equalsObject', '$window'];
|
COMPONENT.controller.$inject = ['$http', '$stateParams', 'copyObject', 'equalsObject', '$window', 'getDataModified'];
|
||||||
module.component(NAME, COMPONENT);
|
module.component(NAME, COMPONENT);
|
||||||
|
|
|
@ -9,7 +9,7 @@ export const COMPONENT = {
|
||||||
bindings: {
|
bindings: {
|
||||||
client: '<'
|
client: '<'
|
||||||
},
|
},
|
||||||
controller: function($http, $scope, copyObject) {
|
controller: function($http, $scope) {
|
||||||
var self = this;
|
var self = this;
|
||||||
$scope.$watch('descriptor.client.active', function(newValue, oldValue) {
|
$scope.$watch('descriptor.client.active', function(newValue, oldValue) {
|
||||||
if (oldValue !== undefined)
|
if (oldValue !== undefined)
|
||||||
|
@ -17,5 +17,5 @@ export const COMPONENT = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
COMPONENT.controller.$inject = ['$http', '$scope', 'copyObject'];
|
COMPONENT.controller.$inject = ['$http', '$scope'];
|
||||||
module.component(NAME, COMPONENT);
|
module.component(NAME, COMPONENT);
|
||||||
|
|
|
@ -46,7 +46,7 @@ export const COMPONENT = {
|
||||||
};
|
};
|
||||||
|
|
||||||
function callback(transition) {
|
function callback(transition) {
|
||||||
if (!equalsObject(self.client.account, self.accountOld)) {
|
if (!equalsObject(self.account, self.accountOld) && self.account) {
|
||||||
self.state = transition.to().name;
|
self.state = transition.to().name;
|
||||||
var dialog = $element[0].querySelector('dialog');
|
var dialog = $element[0].querySelector('dialog');
|
||||||
dialog.showModal();
|
dialog.showModal();
|
||||||
|
|
|
@ -5,14 +5,42 @@ module.exports = function(Address) {
|
||||||
if (!this.enabled && this.default) err();
|
if (!this.enabled && this.default) err();
|
||||||
}
|
}
|
||||||
|
|
||||||
Address.observe('before save', function (ctx, next) {
|
Address.beforeRemote('create',function(ctx, modelInstance, next){
|
||||||
var data = getData(ctx);
|
var data = ctx.req.body;
|
||||||
if (data.enabled && data.default) {
|
create(data, next);
|
||||||
ctx.Model.update({client: data.client}, {default: false});
|
});
|
||||||
|
|
||||||
|
function create(data, next){
|
||||||
|
if(data.default){
|
||||||
|
removeAllDefault(data.client);
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
|
Address.beforeRemote('prototype.updateAttributes',function(ctx, modelInstance, next){
|
||||||
|
var data = ctx.req.body;
|
||||||
|
data.id = ctx.req.params.id;
|
||||||
|
getAddress(ctx, data, next);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getAddress(ctx, data, next){
|
||||||
|
var address = Address.findOne( {where: { id: data.id}}, function (err, address){
|
||||||
|
if(address)
|
||||||
|
callbackGetAddress(ctx, data, address, next)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function callbackGetAddress(ctx, data, address, next){
|
||||||
|
if (data.default){
|
||||||
|
removeAllDefault(address.client);
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
else if (address.default && !data.default)
|
||||||
|
next(generateErrorDefaultAddress());
|
||||||
|
else
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
function getData(ctx){
|
function getData(ctx){
|
||||||
if (ctx.data)
|
if (ctx.data)
|
||||||
return ctx.data;
|
return ctx.data;
|
||||||
|
@ -20,4 +48,18 @@ module.exports = function(Address) {
|
||||||
return ctx.instance;
|
return ctx.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeAllDefault(cl){
|
||||||
|
Address.update({client: cl}, {default: false});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function generateErrorDefaultAddress(){
|
||||||
|
var error = new Error();
|
||||||
|
error.message = "No se puede desmarcar el consignatario predeterminado";
|
||||||
|
error.status = 500;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,12 @@ module.exports = function(Client) {
|
||||||
|
|
||||||
Client.remoteMethod('activate',
|
Client.remoteMethod('activate',
|
||||||
{
|
{
|
||||||
|
description: 'Activate or deactive client',
|
||||||
|
accepts: {arg: 'id', type: 'number', required: true, http: function(ctx) {
|
||||||
|
var id = ctx && ctx.req && ctx.req.params.id
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
},
|
||||||
returns: {
|
returns: {
|
||||||
arg: 'active',
|
arg: 'active',
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
|
@ -27,8 +33,7 @@ module.exports = function(Client) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Client.activate = function(cb){
|
Client.activate = function(id, cb){
|
||||||
var id = 12;
|
|
||||||
Client.findById(id, function(err, client) {
|
Client.findById(id, function(err, client) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
Client.update({id: client.id}, {active: !client.active});
|
Client.update({id: client.id}, {active: !client.active});
|
||||||
|
|
Loading…
Reference in New Issue