From 6c683a1bddf1f1d186b9ee27559bb8ba5723b149 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Thu, 4 May 2017 16:59:07 -0400 Subject: [PATCH] webstaff: Provide a way to get shallow (no nested objects) clones from IDL objects This will have an impact on the webstaff offline interface, which has a similar but less advanced implementation of the same. We want THIS one going forward, not the one from offline. HEAD'S UP! Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- Open-ILS/web/js/ui/default/staff/services/idl.js | 37 ++++++++++++------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/services/idl.js b/Open-ILS/web/js/ui/default/staff/services/idl.js index 444b8202b3..90a62be7e6 100644 --- a/Open-ILS/web/js/ui/default/staff/services/idl.js +++ b/Open-ILS/web/js/ui/default/staff/services/idl.js @@ -21,7 +21,8 @@ angular.module('egCoreMod') 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; @@ -34,23 +35,21 @@ angular.module('egCoreMod') 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); @@ -61,22 +60,24 @@ angular.module('egCoreMod') 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); -- 2.11.0