Skip to content

Commit

Permalink
#25896 #24415 create map, create list of relationships according to map
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Aug 29, 2023
1 parent e894bb1 commit ec11c18
Showing 1 changed file with 46 additions and 4 deletions.
Expand Up @@ -403,23 +403,65 @@
}
//Invoked when a contentlet is selected to fill the contentlet data in the table
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];
}
}
Expand Down

0 comments on commit ec11c18

Please sign in to comment.