Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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) {
Expand Down Expand Up @@ -109,35 +110,26 @@
polarisRepositoryId = JSON.parse(cfg).repositoryId;
if (polarisRepositoryId) {
isPolarisEnabled = true;
remoteFileReference = $cqFileUpload.find("input[name='./fileReference']").val();
remoteFileReferencesArray = $cqFileUpload.find("[data-cq-fileupload-parameter='filereference']");
}
}

retrieveInstanceInfo(imagePath);
$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() {
$altTextField.adaptTo("foundation-field").setRequired(false);
Expand Down Expand Up @@ -298,6 +290,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);
Expand Down Expand Up @@ -405,11 +413,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) {
Expand Down Expand Up @@ -465,15 +473,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);
}
});
});
}

Expand Down
Loading