factoría comprobar modificación datos

This commit is contained in:
nelo 2017-01-23 14:50:39 +01:00
parent b9c0745b73
commit 834eed3357
5 changed files with 45 additions and 12 deletions

View File

@ -9,6 +9,7 @@ export {NAME as INTERPOLATE, Interpolate} from './interpolate';
export {NAME as ROUTES_LOADER, RoutesLoader} from './routesLoader';
export {NAME as COPY_OBJECT} from './copy';
export {NAME as EQUALS_OBJECT} from './equals';
export {NAME as GET_DATA_MODIFIED, factory as Modified} from './modified';
export {NAME as FOCUS, directive as Focus} from './focus';
export {NAME as RULE, directive as Rule} from './rule';

View File

@ -0,0 +1,27 @@
import {module} from './module';
import * as equals from './equals';
export const NAME = 'getDataModified';
export function factory(equalsObject) {
return function getData(object, objectOld) {
var newObject = {};
for (var k in object) {
var val = object[k];
var valOld = objectOld[k];
if (val instanceof Object && !equalsObject(val, valOld)) {
newObject[k] = getData(val, valOld);
}
else if (val instanceof Array && val.length !== valOld.length) {
newObject[k] = val;
}
else if (val !== valOld) {
newObject[k] = val;
}
}
return newObject;
}
}
factory.$inject = ['equalsObject'];
module.factory(NAME, factory);

View File

@ -8,7 +8,7 @@ export const COMPONENT = {
bindings: {
client: '<'
},
controller: function($http, copyObject, equalsObject, $transitions, $element) {
controller: function($http, copyObject, equalsObject, $transitions, $element, modified) {
var self = this;
var deregister = $transitions.onStart({ }, callback);
@ -33,8 +33,10 @@ export const COMPONENT = {
this.submit = function() {
if (!equalsObject(this.client, this.clientOld)) {
this.client.modify = "BasicData";
$http.put('/client/api/Clients', this.client).then(
var newClient = modified(this.client, this.clientOld);
newClient.modify = "BasicData";
newClient.id = this.clientOld.id;
$http.put('/client/api/Clients', newClient).then(
json => {
copyObject(json.data, this.client);
this.copyClient();
@ -50,5 +52,5 @@ export const COMPONENT = {
}
};
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element'];
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element', 'getDataModified'];
module.component(NAME, COMPONENT);

View File

@ -8,13 +8,15 @@ export const COMPONENT = {
bindings: {
client: '<'
},
controller: function($http, copyObject, equalsObject, $transitions, $element) {
controller: function($http, copyObject, equalsObject, $transitions, $element, modified) {
var self = this;
var deregister = $transitions.onStart({ }, callback);
this.submit = function() {
if (!equalsObject(this.client, this.clientOld)) {
this.client.modify = "FiscalData";
var newClient = modified(this.client, this.clientOld);
newClient.modify = "FiscalData";
newClient.id = this.clientOld.id;
$http.put('/client/api/Clients', this.client).then(
json => {
this.client = json.data;
@ -49,6 +51,6 @@ export const COMPONENT = {
};
}
};
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element'];
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element', 'getDataModified'];
module.component(NAME, COMPONENT);

View File

@ -8,15 +8,16 @@ export const COMPONENT = {
bindings: {
client: '<'
},
controller: function($http, copyObject, equalsObject, $transitions, $element) {
controller: function($http, copyObject, equalsObject, $transitions, $element, modified) {
var self = this;
var deregister = $transitions.onStart({ }, callback);
this.submit = function() {
if (!equalsObject(this.account, this.accountOld)) {
this.client.modify = "WebAccess";
this.account.id = this.client.id;
$http.put('/client/api/Accounts', this.account).then(
var newAccount = modified(this.account, this.accountOld);
newAccount.modify = "WebAccess";
newAccount.id = this.client.id;
$http.put('/client/api/Accounts', newAccount).then(
json => {
this.account = json.data;
self.copyAccount();
@ -59,5 +60,5 @@ export const COMPONENT = {
};
}
};
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element'];
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element', 'getDataModified'];
module.component(NAME, COMPONENT);