Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

AEM Cloud Service - Show Asset References in Delete Dialog | AEM Community Blog Seeding

kautuk_sahni
Community Manager
Community Manager

BlogImage.jpg

AEM Cloud Service - Show Asset References in Delete Dialog by Sreekanth Choudry Nalabotu

Abstract

Goal
Adobe Experience Manager 2021.7.5607.20210705T063041Z-210600
Show Asset references in Delete alert box before proceeding with deletion....

Solution
Create a clientlib /apps/eaem-asset-delete-refs/clientlibs/delete-cf-show-refs with categories=dam.gui.actions.coral and dependencies=eaem.lodash and the following code..

(function ($, $document) {
"use strict";

var _ = window._;

$document.on("foundation-contentloaded", function(e) {
var deleteActivator = ".cq-damadmin-admin-actions-delete-activator";

$document.off("click", deleteActivator).on("click", deleteActivator, function(e) {
e.preventDefault();
e.stopPropagation();

showReferences.call(this);
});
});

function showReferences(){
var selectedItems = $(".foundation-selections-item"),
paths = [];

selectedItems.each(function() {
paths.push($(this).get(0).getAttribute("data-foundation-collection-item-id"));
});

var AssetReferences = Dam.AssetReferences;

var refsPromise = AssetReferences.fetchFromPaths(paths, AssetReferences.REF_MODE.ALL);

refsPromise.then(function(references) {
var fui = $(window).adaptTo("foundation-ui"),
options = [{
id: "DELETE",
variant: "warning",
text: "Delete"
},
{
id: "CANCEL",
text: "Cancel"
}];

var message = "Are you sure?";

if(!_.isEmpty(references.localRefs)){
message = "Asset referenced in following paths. Are you sure?" + references.localRefs;
}else if(references.activations.found){
message = "Asset was published. Are you sure?";
}

fui.prompt("Delete", message, "error", options, function (actionId) {
if (actionId === "DELETE") {
deleteAsset(paths);
}
});
});
}

function deleteAsset(paths){
var data = {
path: paths,
cmd: "deletePage",
force: true,
"_charset_": "utf-8"
};

$.ajax({
url: "/bin/wcmcommand", //"/bin/asynccommand",
type: "post",
data: data,
success: function() {
var collection = document.querySelector(".cq-damadmin-admin-childpages"),
pageId = collection.getAttribute("data-foundation-collection-id");

$(collection).adaptTo("foundation-collection").load(pageId);
},
error: function(response) {
showAlert("Error deleting asset", "Error");
}
});
}

function showAlert(message, title, type, callback) {
var fui = $(window).adaptTo("foundation-ui"),
options = [{
id: "ok",
text: "Ok",
primary: true
}];

message = message || "Unknown Error";
title = title || "Error";
type = type || "warning";

fui.prompt(title, message, type, options, callback);
}
}(jQuery, jQuery(document)));


Posted by sreekanth choudry at 11:55 AM
Email This
BlogThis!
Share to Twitter
Share to Facebook
Share to Pinterest

Read Full Blog

AEM Cloud Service - Show Asset References in Delete Dialog

Q&A

Please use this thread to ask the related questions.

AEM AEMEBlogSeeding Experience Manager
0 Replies