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 ff3982c458..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 @@ -62,6 +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 remoteFileReferencesArray = []; var remoteFileReference; $(document).on("dialog-loaded", function(e) { @@ -108,7 +109,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 +117,18 @@ $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) { + var $fileReferences = $cqFileUpload.find("[data-cq-fileupload-parameter='filereference']"); + $fileReferences.each(function() { + remoteFileReference = $(this).val(); + if (isRemoteFileReference(remoteFileReference)) { + 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(); @@ -248,6 +240,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); @@ -352,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) { @@ -409,15 +417,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() { + remoteFileReference = $(this).val(); + if (filePath.endsWith("/cq:featuredimage")) { + remoteFileReference = data["fileReference"]; + } + if (isRemoteFileReference(remoteFileReference) || filePath.endsWith("/cq:featuredimage")) { + retrieveDAMInfo(remoteFileReference); + } + }); }); }