var service = {};
// Clones data structures containing fieldmapper objects
- service.Clone = function(old) {
+ service.Clone = function(old, depth) {
+ if (depth === undefined) depth = 100;
var obj;
if (typeof old == 'undefined') {
return old;
if (typeof thing == 'undefined') {
obj.a[i] = thing;
- } else if (thing._isfieldmapper) {
- obj.a[i] = service.Clone(thing);
+ } else if (depth && thing._isfieldmapper) {
+ if (depth) obj.a[i] = service.Clone(thing, depth - 1);
} else {
if(angular.isArray(thing)) {
obj.a[i] = [];
- if(angular.isArray(thing)) {
- obj.a[i] = [];
-
for( var j in thing ) {
- if (typeof thing[j] == 'undefined')
+ if (typeof thing[j] == 'undefined') {
obj.a[i][j] = thing[j];
- else if( thing[j]._isfieldmapper )
- obj.a[i][j] = service.Clone(thing[j]);
- else
+ } else if( thing[j]._isfieldmapper ) {
+ if (depth) obj.a[i][j] = service.Clone(thing[j], depth - 1);
+ } else {
obj.a[i][j] = angular.copy(thing[j]);
+ }
}
} else {
obj.a[i] = angular.copy(thing);
if(angular.isArray(old)) {
obj = [];
for( var j in old ) {
- if (typeof old[j] == 'undefined')
+ if (typeof old[j] == 'undefined') {
obj[j] = old[j];
- else if( old[j]._isfieldmapper )
- obj[j] = service.Clone(old[j], depth - 1);
- else
+ } else if( old[j]._isfieldmapper ) {
+ if (depth) obj[j] = service.Clone(old[j], depth - 1);
+ } else {
obj[j] = angular.copy(old[j]);
+ }
}
} else if(angular.isObject(old)) {
obj = {};
for( var j in old ) {
- if (typeof old[j] == 'undefined')
+ if (typeof old[j] == 'undefined') {
obj[j] = old[j];
- else if( old[j]._isfieldmapper )
- obj[j] = service.Clone(old[j], depth - 1);
- else
+ } else if( old[j]._isfieldmapper ) {
+ if (depth) obj[j] = service.Clone(old[j], depth - 1);
+ } else {
obj[j] = angular.copy(old[j]);
+ }
}
} else {
obj = angular.copy(old);