From 6df0999844bde2a0097ab486d8ed73700128d839 Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 18 Jan 2017 08:41:22 +0100 Subject: [PATCH 1/3] paging --- @salix/crud/src/client/addresses/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/@salix/crud/src/client/addresses/index.js b/@salix/crud/src/client/addresses/index.js index fe1d24796..934be634c 100644 --- a/@salix/crud/src/client/addresses/index.js +++ b/@salix/crud/src/client/addresses/index.js @@ -8,10 +8,9 @@ export const COMPONENT = { bindings: { client: '<' }, - controller: function($http, $state) - { + controller: function($http, $state) { var self = this; - let numPerPage = 2; + let numPerPage = 5; let numRecords = 0; this.$onChanges = function(changes) { @@ -31,13 +30,14 @@ export const COMPONENT = { ); }; $http.get('/client/api/Addresses').then( - json => this.addresses = json.data + json => { + this.addresses = json.data; + } ); this.getNumPages = () => { var nPages = numRecords / numPerPage; - if (nPages > 0) - self.numPages = (nPages % 2) ? Math.ceil(nPages) : Math.ceil(nPages) + 1; + self.numPages = Math.ceil(nPages); }; this.figureOutToDisplay = () => { From 2694b14c53da1b795780b80c312e15451eb3935e Mon Sep 17 00:00:00 2001 From: nelo Date: Wed, 18 Jan 2017 10:42:53 +0100 Subject: [PATCH 2/3] =?UTF-8?q?validaci=C3=B3n=20consignatarios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/client/common/models/Address.js | 14 ++++++++++++++ services/client/common/models/Address.json | 1 + 2 files changed, 15 insertions(+) create mode 100644 services/client/common/models/Address.js diff --git a/services/client/common/models/Address.js b/services/client/common/models/Address.js new file mode 100644 index 000000000..7db31bc7f --- /dev/null +++ b/services/client/common/models/Address.js @@ -0,0 +1,14 @@ +module.exports = function(Address) { + + Address.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'}); + function isEnabled(err) { + if (!this.enabled && this.default) err(); + } + + Address.observe('before save', function (ctx, next) { + if (ctx.data.enabled && ctx.data.default) { + ctx.Model.update({client: ctx.data.client}, {default: false}); + } + next(); + }); +}; \ No newline at end of file diff --git a/services/client/common/models/Address.json b/services/client/common/models/Address.json index 9a60529e5..7bd9d2ddb 100644 --- a/services/client/common/models/Address.json +++ b/services/client/common/models/Address.json @@ -1,6 +1,7 @@ { "name": "Address", "base": "PersistedModel", + "validateUpsert": true, "properties": { "id": { "type": "Number", From 28451aced92a53618d186d810c8cd35c786a8384 Mon Sep 17 00:00:00 2001 From: nelo Date: Wed, 18 Jan 2017 10:50:51 +0100 Subject: [PATCH 3/3] =?UTF-8?q?comprobaci=C3=B3n=20modificaci=C3=B3n=20con?= =?UTF-8?q?signatario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/client/addresses-data-edit/index.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/@salix/crud/src/client/addresses-data-edit/index.js b/@salix/crud/src/client/addresses-data-edit/index.js index 0e35bddf6..57b6089d7 100644 --- a/@salix/crud/src/client/addresses-data-edit/index.js +++ b/@salix/crud/src/client/addresses-data-edit/index.js @@ -5,10 +5,13 @@ export const NAME = 'vnClientAddressesDataEdit'; export const COMPONENT = { template: template, controllerAs: 'addressData', - controller: function($http, $stateParams) { + controller: function($http, $stateParams, copyObject, equalsObject) { this.address = {}; $http.get(`/client/api/Addresses/${$stateParams.addressId}`).then( - json => this.address = json.data + json => { + this.address = json.data; + this.copyAddress(); +  } ); $http.get('/client/api/Agencies').then( json => this.agencies = json.data @@ -18,10 +21,23 @@ export const COMPONENT = { ); this.submit = function() { - $http.put('/client/api/Addresses', this.address); + if (!equalsObject(this.address, this.addressOld)) { + $http.put('/client/api/Addresses', this.address).then( + json => { + this.address = json.data; + this.copyAddress(); + } + ); + + } + }; + + this.copyAddress = () => { + this.addressOld = {}; + copyObject(this.address, this.addressOld); }; } }; -COMPONENT.controller.$inject = ['$http', '$stateParams']; +COMPONENT.controller.$inject = ['$http', '$stateParams', 'copyObject', 'equalsObject']; module.component(NAME, COMPONENT);