From 15033f0b1de7c24b406d65c4b99163cd304211db Mon Sep 17 00:00:00 2001 From: erickgonzalez Date: Tue, 29 Aug 2023 15:35:26 -0600 Subject: [PATCH] #25896 include in 22.03.9 --- HOTFIX_TRACKING.md | 3 +- .../contentlet/field/relationship_field.jsp | 48 +++++++++++++++++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/HOTFIX_TRACKING.md b/HOTFIX_TRACKING.md index 8933c4a9c6b5..62fe1188d9a2 100644 --- a/HOTFIX_TRACKING.md +++ b/HOTFIX_TRACKING.md @@ -174,4 +174,5 @@ This maintenance release includes the following code fixes: 145. https://github.com/dotCMS/core/issues/24829 : NavTool method getNav must return only published links #24829 146. https://github.com/dotCMS/core/issues/25371 : PP: pushing new folder with limited user fails #25371 147. https://github.com/dotCMS/core/issues/25797 : When uploading multiple files, the files are always in English #25797 -148. https://github.com/dotCMS/core/issues/25229 : PP - Integrity Checker, fixing conflicts is not populating the contentlet_as_json field #25229 \ No newline at end of file +148. https://github.com/dotCMS/core/issues/25229 : PP - Integrity Checker, fixing conflicts is not populating the contentlet_as_json field #25229 +149. https://github.com/dotCMS/core/issues/25896 : Creating a contentlet in a 2nd language removes related content #25896 \ No newline at end of file diff --git a/dotCMS/src/main/webapp/html/portlet/ext/contentlet/field/relationship_field.jsp b/dotCMS/src/main/webapp/html/portlet/ext/contentlet/field/relationship_field.jsp index 1530ffb953cc..d092a902b63c 100644 --- a/dotCMS/src/main/webapp/html/portlet/ext/contentlet/field/relationship_field.jsp +++ b/dotCMS/src/main/webapp/html/portlet/ext/contentlet/field/relationship_field.jsp @@ -402,23 +402,63 @@ dijit.byId("<%= relationJsName %>Dialog")._doSearchPage1(); } + function createNewList(listRelationships){ + + return newList; + } + + function mapToCheckCurrentLangExists(listRelationships){ + const idExists = new Map(); + for (var indexK = 0; indexK < listRelationships.length; indexK++) { + for (var indexL = 0; indexL < listRelationships.length; indexL++) { + if(listRelationships[indexK]['identifier'] == listRelationships[indexL]['identifier'] && + listRelationships[indexL]['langId'] == <%= contentlet.getLanguageId() %>) { + idExists.set(listRelationships[indexK]['identifier'], true); + break; + } + } + if(!idExists.has(listRelationships[indexK]['identifier'])) { + idExists.set(listRelationships[indexK]['identifier'], false); + } + } + return idExists; + } + //Invoked when a contentlet is selected to fill the contentlet data in the table function <%= relationJsName %>_addRelationshipCallback(selectedData){ - selectedData = selectedData.filter(sibling => sibling.langId == <%= contentlet.getLanguageId() %>); + //selectedData = selectedData.filter(sibling => sibling.langId == <%= contentlet.getLanguageId() %>); + console.log("selectedData"); + console.log(selectedData); + + const mapIdCurrentLangExist = mapToCheckCurrentLangExists(selectedData); + + const newList = []; + for (var indexL = 0; indexL < selectedData.length; indexL++) { + var currentContent = selectedData[indexL]; + var currentContentId = currentContent['identifier']; + var mapValue = mapIdCurrentLangExist.get(currentContentId); + if(mapValue && currentContent['langId'] == <%= contentlet.getLanguageId() %>){ + newList.push(currentContent); + } + if(!mapValue){ + newList.push(currentContent); + } + } + var data = new Array(); var dataToRelate = new Array(); var entries = numberOfRows<%= relationJsName%>(); // Eliminating existing relations - for (var indexJ = 0; indexJ < selectedData.length; indexJ++) { + for (var indexJ = 0; indexJ < newList.length; indexJ++) { var relationExists = (<%=thereCanBeOnlyOne%> && (entries > 0 || dataToRelate.length>0)) ? true : false; for (var indexI = 0; indexI < <%= relationJsName %>_Contents.length; indexI++) { - if(selectedData[indexJ]['id'] == <%= relationJsName %>_Contents[indexI]['id']){ + if(newList[indexJ]['id'] == <%= relationJsName %>_Contents[indexI]['id']){ relationExists = true; } } if(!relationExists){ - dataToRelate[dataToRelate.length] = selectedData[indexJ]; + dataToRelate[dataToRelate.length] = newList[indexJ]; } }