From 043ae87a2015abcd73c1b5da447b2da90598b23d Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Fri, 4 Sep 2015 13:56:33 -0400 Subject: [PATCH] webstaff: Provide a fieldmapper-aware cloning method Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton Signed-off-by: Jason Stephenson --- Open-ILS/web/js/ui/default/staff/services/idl.js | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) 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 5934063ceb..681a63a48a 100644 --- a/Open-ILS/web/js/ui/default/staff/services/idl.js +++ b/Open-ILS/web/js/ui/default/staff/services/idl.js @@ -20,6 +20,59 @@ angular.module('egCoreMod') var service = {}; + // Clones data structures containing fieldmapper objects + service.Clone = function(old) { + var obj; + if (old._isfieldmapper) { + obj = new service[old.classname]() + + for( var i in old.a ) { + var thing = old.a[i]; + if(thing === null) continue; + + if( thing._isfieldmapper ) { + obj.a[i] = service.Clone(thing); + } else { + + if(angular.isArray(thing)) { + obj.a[i] = []; + + for( var j in thing ) { + + if( thing[j]._isfieldmapper ) + obj.a[i][j] = service.Clone(thing[j]); + else + obj.a[i][j] = angular.copy(thing[j]); + } + } else { + obj.a[i] = angular.copy(thing); + } + } + } + } else { + if(angular.isArray(old)) { + obj = []; + for( var j in old ) { + if( old[j]._isfieldmapper ) + obj[j] = service.Clone(old[j]); + else + obj[j] = angular.copy(old[j]); + } + } else if(angular.isObject(old)) { + obj = {}; + for( var j in old ) { + if( old[j]._isfieldmapper ) + obj[j] = service.Clone(old[j]); + else + obj[j] = angular.copy(old[j]); + } + } else { + obj = angular.copy(old); + } + } + return obj; + }; + service.parseIDL = function() { //console.debug('egIDL.parseIDL()'); -- 2.11.0