diff --git a/client/client/src/address-edit/address-edit.html b/client/client/src/address-edit/address-edit.html index 72c6b4136..e0691254c 100644 --- a/client/client/src/address-edit/address-edit.html +++ b/client/client/src/address-edit/address-edit.html @@ -12,7 +12,6 @@ Address - diff --git a/client/client/src/addresses/addresses.html b/client/client/src/addresses/addresses.html index 0df5820f3..1d6538fc6 100644 --- a/client/client/src/addresses/addresses.html +++ b/client/client/src/addresses/addresses.html @@ -1,14 +1,18 @@ - + Addresses - + + + star + star_border +
{{::i.consignee}}
{{::i.street}}
diff --git a/client/client/src/addresses/addresses.js b/client/client/src/addresses/addresses.js index 12c2c380e..bd9d5c6dd 100644 --- a/client/client/src/addresses/addresses.js +++ b/client/client/src/addresses/addresses.js @@ -1,5 +1,19 @@ import ngModule from '../module'; +class ClientAddresses { + constructor($http, $scope) { + this.$http = $http; + this.$scope = $scope; + } + setDefault(id) { + this.$http.patch(`/client/api/Addresses/${id}`, {id: id, default: 1}).then(() => { + this.$scope.index.accept(); + }); + } +} +ClientAddresses.$inject = ['$http', '$scope']; + ngModule.component('vnClientAddresses', { - template: require('./addresses.html') + template: require('./addresses.html'), + controller: ClientAddresses }); diff --git a/client/client/src/addresses/locale/es.json b/client/client/src/addresses/locale/es.json index 5240a6563..dc7a13c4a 100644 --- a/client/client/src/addresses/locale/es.json +++ b/client/client/src/addresses/locale/es.json @@ -1,3 +1,4 @@ { - "Addresses": "Consignatarios" + "Addresses": "Consignatarios", + "Set as default": "Establecer como predeterminado" } \ No newline at end of file diff --git a/client/client/src/index/index.html b/client/client/src/index/index.html index 96338af36..3556b7808 100644 --- a/client/client/src/index/index.html +++ b/client/client/src/index/index.html @@ -1,4 +1,4 @@ - +
diff --git a/client/core/src/lib/crud.js b/client/core/src/lib/crud.js index f515009b5..df5c5d062 100644 --- a/client/core/src/lib/crud.js +++ b/client/core/src/lib/crud.js @@ -3,7 +3,7 @@ import {module} from '../module'; index.$inject = ['mgIndex']; function index(mgIndex) { return Object.assign({}, mgIndex, { - init: 'index.filter={page: 1, size: 4}' + init: 'index.filter={page: 1, size: 5}' }); } module.factory('vnIndex', index); diff --git a/services/client/common/methods/client/addresses.js b/services/client/common/methods/client/addresses.js index 5c11274b7..970c52d4b 100644 --- a/services/client/common/methods/client/addresses.js +++ b/services/client/common/methods/client/addresses.js @@ -37,7 +37,8 @@ module.exports = function(Client) { clientFk: id }, skip: (params.page - 1) * params.size, - limit: params.size + limit: params.size, + order: ['default DESC', 'enabled DESC'] }; Client.app.models.Address.find(filter, function(err, instances) { diff --git a/services/client/common/models/address.js b/services/client/common/models/address.js index c9bcfb0d8..09f95209c 100644 --- a/services/client/common/models/address.js +++ b/services/client/common/models/address.js @@ -16,10 +16,10 @@ module.exports = function(Address) { next(); } - Address.beforeRemote('prototype.updateAttributes',function(ctx, modelInstance, next){ - var data = ctx.req.body; - data.id = ctx.req.params.id; - getAddress(ctx, data, next); + Address.beforeRemote('prototype.patchAttributes',function(ctx, modelInstance, next){ + let newData = ctx.req.body; + newData.id = ctx.req.params.id; + getAddress(ctx, newData, next); }); Address.beforeRemote('findById', function(ctx, modelInstance, next) { @@ -34,19 +34,18 @@ module.exports = function(Address) { 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 getAddress(ctx, newData, next){ + Address.findOne( {where: { id: newData.id}}, function (err, oldData){ + if(oldData) + callbackGetAddress(ctx, newData, oldData, next); }); } - function callbackGetAddress(ctx, data, address, next){ - if (data.default){ - removeAllDefault(address.client); - next(); + function callbackGetAddress(ctx, newData, oldData, next){ + if (newData.default){ + removeAllDefault(oldData.client, next); } - else if (address.default && data.hasOwnProperty('default') && !data.default) + else if (oldData.default && newData.hasOwnProperty('default') && !newData.default) next(generateErrorDefaultAddress()); else next(); @@ -59,8 +58,8 @@ module.exports = function(Address) { return ctx.instance; } - function removeAllDefault(cl){ - Address.update({client: cl}, {default: false}); + function removeAllDefault(client, next){ + Address.updateAll({clientFk: client.id, default: true}, {default: false}, next); } function generateErrorDefaultAddress(){