From d25c48f5ff9a5fd21984fa31f61c98879482f753 Mon Sep 17 00:00:00 2001 From: Frederick Borges Date: Fri, 4 Feb 2022 11:37:51 +0100 Subject: [PATCH] B #5238: Sunstone not to override unmodified templates (#1752) on VM instantiation --- .../templates-tab/form-panels/instantiate.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js index 76208144f8..a578056b2c 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js @@ -190,15 +190,18 @@ define(function(require) { }); } - function diffValues(finder, inElement){ + function diffValues(newValues, oldValues){ var diff = []; - if(finder && inElement){ - var Template = Array.isArray(inElement)? inElement: [inElement]; - var Finder = Array.isArray(finder)? finder: [finder]; - var x = Template.map(function(internalTemplate){return JSON.stringify(internalTemplate);}); - Finder.forEach(function(fnd) { - if($.inArray(JSON.stringify(fnd),x) === -1){ - diff.push(fnd); + if(oldValues && newValues){ + oldValues = Array.isArray(oldValues)? oldValues: [oldValues]; + newValues = Array.isArray(newValues)? newValues: [newValues]; + var oldValuesString = oldValues.map(function(internalValue){ + return JSON.stringify(internalValue); + }); + + newValues.forEach(function (newValue){ + if($.inArray(JSON.stringify(newValue),oldValuesString) === -1){ + diff.push(newValue); } }); }