diff --git a/client/client/routes.json b/client/client/routes.json index fc931bd3f..aff34bc6f 100644 --- a/client/client/routes.json +++ b/client/client/routes.json @@ -22,7 +22,7 @@ "state": "clientCard.basicData", "component": "vn-client-basic-data", "params": { - "client": "card.client" + "client": "$ctrl.client" }, "menu": { "description": "Datos básicos", @@ -33,7 +33,7 @@ "state": "clientCard.fiscalData", "component": "vn-client-fiscal-data", "params": { - "client": "card.client" + "client": "$ctrl.client" }, "menu": { "description": "Datos fiscales", @@ -44,7 +44,7 @@ "state": "clientCard.billingData", "component": "vn-client-billing-data", "params": { - "client": "card.client" + "client": "$ctrl.client" }, "menu": { "description": "Datos facturación", @@ -60,7 +60,7 @@ "state": "clientCard.addresses.list", "component": "vn-client-addresses", "params": { - "client": "card.client" + "client": "$ctrl.client" }, "menu": { "description": "Consignatarios", @@ -79,7 +79,7 @@ "state": "clientCard.webAccess", "component": "vn-client-web-access", "params": { - "client": "card.client" + "client": "$ctrl.client" }, "menu": { "description": "Acceso web", @@ -95,7 +95,7 @@ "state": "clientCard.notes.list", "component": "vn-client-notes", "params": { - "client": "card.client" + "client": "$ctrl.client" }, "menu": { "description": "Notas", diff --git a/client/client/src/card/card.html b/client/client/src/card/card.html index 0319c72fd..e9ebd07a0 100644 --- a/client/client/src/card/card.html +++ b/client/client/src/card/card.html @@ -1,13 +1,13 @@ diff --git a/client/client/src/card/card.js b/client/client/src/card/card.js index 06689a697..b21c3f636 100644 --- a/client/client/src/card/card.js +++ b/client/client/src/card/card.js @@ -9,6 +9,5 @@ export default class Controller { ngModule.component('vnClientCard', { template: require('./card.html'), - controller: Controller, - controllerAs: 'card' + controller: Controller }); diff --git a/client/core/src/lib/equals.js b/client/core/src/lib/equals.js index 40b36cca0..2e211153e 100644 --- a/client/core/src/lib/equals.js +++ b/client/core/src/lib/equals.js @@ -1,6 +1,48 @@ import {module} from '../module'; const isEqual = angular.equals; + +export const myEqual = (objA, objB, estrict) => { + let equals = true; + let estrictMode = estrict || true; + + if (Object.keys(objA).length !== Object.keys(objB).length) { + return false; + } + + for (let k in objA) { + if (!objB.hasOwnProperty(k)) { + return false; + } + if (estrictMode) { + if (typeof objA[k] !== typeof objB[k]) { + return false; + } + if (typeof objA[k] !== 'object' && objA[k] !== objB[k]) { + return false; + } + if (typeof objA[k] === 'object') { + equals = myEqual(objA[k], objB[k], estrictMode); + if (!equals) { + return false; + } + } + } else { + if (typeof objA[k] !== 'object' && objA[k] != objB[k]) { + return false; + } + if (typeof objA[k] === 'object') { + equals = myEqual(objA[k], objB[k], estrictMode); + if (!equals) { + return false; + } + } + } + } + + return equals; +}; + export default isEqual; export const NAME = 'equalsObject'; diff --git a/client/core/src/watcher/watcher.js b/client/core/src/watcher/watcher.js index bf085db4e..87b3d552c 100644 --- a/client/core/src/watcher/watcher.js +++ b/client/core/src/watcher/watcher.js @@ -1,8 +1,8 @@ import {module} from '../module'; import Component from '../lib/component'; import getModifiedData from '../lib/modified'; -// import copyObject from '../lib/copy'; -import isEqual from '../lib/equals'; +import copyObject from '../lib/copy'; +import {myEqual} from '../lib/equals'; /** * Component that checks for changes on a specific model property and @@ -11,12 +11,13 @@ import isEqual from '../lib/equals'; * properties are provided. */ export default class Watcher extends Component { - constructor($element, $scope, $state, $transitions, $http, vnApp, $translate) { + constructor($element, $scope, $state, $transitions, $http, vnApp, $translate, $timeout) { super($element); this.$scope = $scope; this.$state = $state; this.$http = $http; this.$translate = $translate; + this.$timeout = $timeout; this.vnApp = vnApp; this.state = null; @@ -48,7 +49,7 @@ export default class Watcher extends Component { // return new Promise((resolve, reject) => { this.$http.get(`${this.url}/${id}`).then( json => { - this.data = this.copyObject(json.data); + this.data = copyObject(json.data); this.copyData(); } // json => reject(json) @@ -126,11 +127,13 @@ export default class Watcher extends Component { } writeData(json, resolve) { - Object.keys(this.data).forEach( + /* Object.keys(this.data).forEach( key => { this.data[key] = json.data[key]; } - ); + );*/ + + this.data = Object.assign(this.data, json.data); this.copyData(); resolve(json); @@ -159,8 +162,13 @@ export default class Watcher extends Component { if (data) { Object.keys(data).forEach( val => { - if (data[val] !== "" && data[val] !== undefined && data[val] !== null) - copy[val] = data[val]; + if (data[val] !== "" && data[val] !== undefined && data[val] !== null) { + if (typeof data[val] === 'object') { + copy[val] = this.copyObject(data[val]); + } else { + copy[val] = data[val]; + } + } } ); } @@ -180,20 +188,21 @@ export default class Watcher extends Component { dataChanged() { let newData = this.copyObject(this.data); - return !isEqual(newData, this.orgData); + return !myEqual(newData, this.orgData); } onConfirmResponse(response) { if (response === 'ACCEPT') { - this.data = this.copyObject(this.orgData); + Object.assign(this.data, this.orgData); this.$state.go(this.state); + } else { this.state = null; } } } -Watcher.$inject = ['$element', '$scope', '$state', '$transitions', '$http', 'vnApp', '$translate']; +Watcher.$inject = ['$element', '$scope', '$state', '$transitions', '$http', 'vnApp', '$translate', '$timeout']; module.component('vnWatcher', { template: require('./watcher.html'),