From 967fc089e0a8eb0378a9672655ecff856e4a4377 Mon Sep 17 00:00:00 2001 From: Mohit Arora Date: Thu, 20 Jun 2024 20:44:21 +0530 Subject: [PATCH 1/3] SITES-22935 NGDM remote image issue Make changes work for multiple fileupload instances present in a custom multifield component. --- .../v3/image/clientlibs/editor/js/image.js | 68 +++++++++++-------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js b/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js index 40ac63156c..78b3fe3efd 100644 --- a/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js +++ b/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js @@ -62,7 +62,7 @@ var polarisRepositoryId; var imagePresetRadio = ".cmp-image__editor-dynamicmedia-presettype input[name='./dmPresetType'][value='imagePreset']"; var smartCropRadio = ".cmp-image__editor-dynamicmedia-presettype input[name='./dmPresetType'][value='smartCrop']"; - var remoteFileReference; + var remoteFileReferencesArray = []; $(document).on("dialog-loaded", function(e) { altTextFromPage = undefined; @@ -108,7 +108,7 @@ polarisRepositoryId = JSON.parse(cfg).repositoryId; if (polarisRepositoryId) { isPolarisEnabled = true; - remoteFileReference = $cqFileUpload.find("input[name='./fileReference']").val(); + remoteFileReferencesArray = $cqFileUpload.find("[data-cq-fileupload-parameter='filereference']"); } } @@ -116,27 +116,19 @@ $cqFileUpload.on("assetselected", function(e) { fileReference = e.path; // if it is a remote asset - remoteFileReference = $cqFileUpload.find("input[name='./fileReference']").val(); - if (fileReference === undefined && remoteFileReference && remoteFileReference !== "" && - remoteFileReference.includes("urn:aaid:aem")) { - fileReference = remoteFileReference; - smartCropRenditionFromJcr = "NONE"; // for newly selected asset we clear the smartcrop selection dropdown - } - retrieveDAMInfo(fileReference).then( - function() { - if (isDecorative) { - altTuple.hideCheckbox(isDecorative.checked); - } - captionTuple.hideCheckbox(false); - altTuple.reinitCheckbox(); - captionTuple.reinitCheckbox(); - toggleAlternativeFieldsAndLink(imageFromPageImage, isDecorative); - if (areDMFeaturesEnabled && !isPolarisEnabled) { - selectPresetType($(presetTypeSelector), "imagePreset"); - resetSelectField($dynamicMediaGroup.find(smartCropRenditionDropDownSelector)); + if (fileReference === undefined) { + var $fileReferences = $cqFileUpload.find("[data-cq-fileupload-parameter='filereference']"); + $fileReferences.each(function() { + var remoteFileReference = $(this).val(); + if (remoteFileReference && remoteFileReference !== "" && + remoteFileReference.includes("urn:aaid:aem")) { + smartCropRenditionFromJcr = "NONE"; // for newly selected asset we clear the smartcrop selection dropdown + processFileReference(remoteFileReference); } - } - ); + }); + } else { + processFileReference(fileReference); + } }); $cqFileUpload.on("click", "[coral-fileupload-clear]", function() { altTuple.reset(); @@ -239,6 +231,22 @@ } }); + function processFileReference(fileReference) { + retrieveDAMInfo(fileReference).then(function() { + if (isDecorative) { + altTuple.hideCheckbox(isDecorative.checked); + } + captionTuple.hideCheckbox(false); + altTuple.reinitCheckbox(); + captionTuple.reinitCheckbox(); + toggleAlternativeFieldsAndLink(imageFromPageImage, isDecorative); + if (areDMFeaturesEnabled && !isPolarisEnabled) { + selectPresetType($(presetTypeSelector), "imagePreset"); + resetSelectField($dynamicMediaGroup.find(smartCropRenditionDropDownSelector)); + } + }); + } + function updateImageThumbnail() { var linkValue; var thumbnailConfigPath = $(dialogContentSelector).find(pageImageThumbnailSelector).attr(pageImageThumbnailConfigPathAttribute); @@ -396,15 +404,19 @@ // we need to get saved value of 'smartCropRendition' of Core Image component smartCropRenditionFromJcr = data["smartCropRendition"]; } - if (filePath.endsWith("/cq:featuredimage")) { - remoteFileReference = data["fileReference"]; - } + // we want to call retrieveDAMInfo after loading the dialog so that saved smartcrop rendition of remote asset // can be shown on initial load. Also adding condition filePath.endsWith("/cq:featuredimage") to trigger alt // update for page properties. - if (remoteFileReference && remoteFileReference !== "" && (remoteFileReference.includes("urn:aaid:aem") || filePath.endsWith("/cq:featuredimage"))) { - retrieveDAMInfo(remoteFileReference); - } + remoteFileReferencesArray.each(function() { + var remoteFileReference = $(this).val(); + if (filePath.endsWith("/cq:featuredimage")) { + remoteFileReference = data["fileReference"]; + } + if (remoteFileReference && remoteFileReference !== "" && remoteFileReference.includes("urn:aaid:aem") || filePath.endsWith("/cq:featuredimage")) { + retrieveDAMInfo(remoteFileReference); + } + }); }); } From 4cc7295df3e58eb27673160b2c4092801aa59f62 Mon Sep 17 00:00:00 2001 From: Mohit Arora Date: Tue, 25 Jun 2024 13:03:18 +0530 Subject: [PATCH 2/3] SITES-22935 NGDM remote image issue Incorporate review comments. --- .../components/image/v3/image/clientlibs/editor/js/image.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js b/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js index 78b3fe3efd..a2a7959b2a 100644 --- a/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js +++ b/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js @@ -116,12 +116,11 @@ $cqFileUpload.on("assetselected", function(e) { fileReference = e.path; // if it is a remote asset - if (fileReference === undefined) { + if (!fileReference) { var $fileReferences = $cqFileUpload.find("[data-cq-fileupload-parameter='filereference']"); $fileReferences.each(function() { var remoteFileReference = $(this).val(); - if (remoteFileReference && remoteFileReference !== "" && - remoteFileReference.includes("urn:aaid:aem")) { + if (remoteFileReference && remoteFileReference.includes("urn:aaid:aem")) { smartCropRenditionFromJcr = "NONE"; // for newly selected asset we clear the smartcrop selection dropdown processFileReference(remoteFileReference); } From f97f697da691c152e2dce1cd671cd8b775a9fc98 Mon Sep 17 00:00:00 2001 From: Mohit Arora Date: Tue, 2 Jul 2024 03:05:41 +0530 Subject: [PATCH 3/3] SITES-22935 NGDM remote image issue Incorporate changes done in other PR - https://github.com/adobe/aem-core-wcm-components/commit/b5e6a560f3d4c29a68313ae07b9670b265067d7a --- .../image/v3/image/clientlibs/editor/js/image.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js b/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js index 8ffcda1b3b..80f61aecac 100644 --- a/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js +++ b/content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js @@ -63,6 +63,7 @@ var imagePresetRadio = ".cmp-image__editor-dynamicmedia-presettype input[name='./dmPresetType'][value='imagePreset']"; var smartCropRadio = ".cmp-image__editor-dynamicmedia-presettype input[name='./dmPresetType'][value='smartCrop']"; var remoteFileReferencesArray = []; + var remoteFileReference; $(document).on("dialog-loaded", function(e) { altTextFromPage = undefined; @@ -119,8 +120,8 @@ if (!fileReference) { var $fileReferences = $cqFileUpload.find("[data-cq-fileupload-parameter='filereference']"); $fileReferences.each(function() { - var remoteFileReference = $(this).val(); - if (remoteFileReference && remoteFileReference.includes("urn:aaid:aem")) { + remoteFileReference = $(this).val(); + if (isRemoteFileReference(remoteFileReference)) { smartCropRenditionFromJcr = "NONE"; // for newly selected asset we clear the smartcrop selection dropdown processFileReference(remoteFileReference); } @@ -359,11 +360,11 @@ } function isRemoteFileReference(fileReference) { - return fileReference && fileReference !== "" && fileReference.includes("urn:aaid:aem"); + return fileReference && fileReference.includes("urn:aaid:aem"); } function retrieveDAMInfo(fileReference) { - if (fileReference.startsWith("/urn:aaid:aem")) { + if (isRemoteFileReference(fileReference)) { return new Promise((resolve, reject) => { fileReference = fileReference.substring(0, fileReference.lastIndexOf("/")); if (isPolarisEnabled && areDMFeaturesEnabled) { @@ -421,11 +422,11 @@ // can be shown on initial load. Also adding condition filePath.endsWith("/cq:featuredimage") to trigger alt // update for page properties. remoteFileReferencesArray.each(function() { - var remoteFileReference = $(this).val(); + remoteFileReference = $(this).val(); if (filePath.endsWith("/cq:featuredimage")) { remoteFileReference = data["fileReference"]; } - if (remoteFileReference && remoteFileReference !== "" && remoteFileReference.includes("urn:aaid:aem") || filePath.endsWith("/cq:featuredimage")) { + if (isRemoteFileReference(remoteFileReference) || filePath.endsWith("/cq:featuredimage")) { retrieveDAMInfo(remoteFileReference); } });