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 = {
|
||||
template: template,
|
||||
controllerAs: 'addressData',
|
||||
controller: function($http, $stateParams, copyObject, equalsObject, $window) {
|
||||
controller: function($http, $stateParams, copyObject, equalsObject, $window, modified) {
|
||||
this.address = {};
|
||||
$http.get(`/client/api/Addresses/${$stateParams.addressId}`).then(
|
||||
json => {
|
||||
|
@ -16,14 +16,13 @@ export const COMPONENT = {
|
|||
|
||||
this.submit = function() {
|
||||
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 => {
|
||||
this.address = json.data;
|
||||
this.copyAddress();
|
||||
$window.history.back();
|
||||
}
|
||||
);
|
||||
}
|
||||
$window.history.back();
|
||||
};
|
||||
|
||||
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);
|
||||
|
|
|
@ -9,7 +9,7 @@ export const COMPONENT = {
|
|||
bindings: {
|
||||
client: '<'
|
||||
},
|
||||
controller: function($http, $scope, copyObject) {
|
||||
controller: function($http, $scope) {
|
||||
var self = this;
|
||||
$scope.$watch('descriptor.client.active', function(newValue, oldValue) {
|
||||
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);
|
||||
|
|
|
@ -46,7 +46,7 @@ export const COMPONENT = {
|
|||
};
|
||||
|
||||
function callback(transition) {
|
||||
if (!equalsObject(self.client.account, self.accountOld)) {
|
||||
if (!equalsObject(self.account, self.accountOld) && self.account) {
|
||||
self.state = transition.to().name;
|
||||
var dialog = $element[0].querySelector('dialog');
|
||||
dialog.showModal();
|
||||
|
|
|
@ -5,19 +5,61 @@ module.exports = function(Address) {
|
|||
if (!this.enabled && this.default) err();
|
||||
}
|
||||
|
||||
Address.observe('before save', function (ctx, next) {
|
||||
var data = getData(ctx);
|
||||
if (data.enabled && data.default) {
|
||||
ctx.Model.update({client: data.client}, {default: false});
|
||||
}
|
||||
next();
|
||||
Address.beforeRemote('create',function(ctx, modelInstance, next){
|
||||
var data = ctx.req.body;
|
||||
create(data, next);
|
||||
});
|
||||
|
||||
function create(data, next){
|
||||
if(data.default){
|
||||
removeAllDefault(data.client);
|
||||
}
|
||||
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){
|
||||
if(ctx.data)
|
||||
if (ctx.data)
|
||||
return ctx.data;
|
||||
else
|
||||
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',
|
||||
{
|
||||
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: {
|
||||
arg: 'active',
|
||||
type: 'boolean'
|
||||
|
@ -27,8 +33,7 @@ module.exports = function(Client) {
|
|||
}
|
||||
});
|
||||
|
||||
Client.activate = function(cb){
|
||||
var id = 12;
|
||||
Client.activate = function(id, cb){
|
||||
Client.findById(id, function(err, client) {
|
||||
if(!err) {
|
||||
Client.update({id: client.id}, {active: !client.active});
|
||||
|
|
Loading…
Reference in New Issue