Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Asset Collections Action Condition

Avatar

Level 3

Hello Community,

1809549_pastedImage_0.png

Need help with new requirement. I want to provide certain actions for collections for the user who has created the collection Eg: I need to provide the Delete button only if the collection is created by the editing user and should be hidden to rest of the users.

How can i achieve this through render conditions upon selecting the collection.?

Please let me know if you guys have any thoughts on this.

Thanks,

Vinay

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

Granite Renderer works only when the resource is getting rendered(page load).

In your case, you can write a servlet, which will be triggered when you select the collection then check the selected collection items created and modified by user and return true and false and based on that hide delete button.

// on select event get collection item

$(document).on("click", ".'coral-masonry-item.foundation-collection-item coral-quickactions>button[title="Select"]', listviewSelector, colummnviewSelector", function () {

var item = $(this).closest('.foundation-collection-item').attr('data-foundation-collection-item-id')

console.log(item);
// ajax call to servlet

$.get('/bin/dam/collections/checkUser?item='+item,  // url

      function (data, textStatus, jqXHR) {  // success callback

          alert('status: ' + textStatus + ', data:' + data);

// hide delete button

          if(data.flag=="false"){

          $('.granite-collection-selectionbar coral-actionbar-primary coral-actionbar-item>button.cq-damadmin-admin-actions-delete-activator').addClass('foundation-collection-action-hidden');

          }

    });

});

This is a sample code for card view you need to do same for list and column view as well by adding correct selectors

listviewSelector

colummnviewSelector



Arun Patidar

View solution in original post

9 Replies

Avatar

Community Advisor

Create a custom rendered and check collections modified by and with current user.

eaxmple

/libs/dam/gui/content/assets/jcr:content/actions/selection/managepublication/granite:rendercondition/mainasset

/libs/dam/gui/coral/components/commons/renderconditions/mainasset/mainasset.jsp



Arun Patidar

Avatar

Level 1

Add Info: the issue is that the rendercondition does not trigger while selecting a specific asset but it triggers only during page load,

anyway to trigger the render condition when i select the (tick mark) while hovering over the collection

1809712_pastedImage_0.png

Avatar

Correct answer by
Community Advisor

Hi,

Granite Renderer works only when the resource is getting rendered(page load).

In your case, you can write a servlet, which will be triggered when you select the collection then check the selected collection items created and modified by user and return true and false and based on that hide delete button.

// on select event get collection item

$(document).on("click", ".'coral-masonry-item.foundation-collection-item coral-quickactions>button[title="Select"]', listviewSelector, colummnviewSelector", function () {

var item = $(this).closest('.foundation-collection-item').attr('data-foundation-collection-item-id')

console.log(item);
// ajax call to servlet

$.get('/bin/dam/collections/checkUser?item='+item,  // url

      function (data, textStatus, jqXHR) {  // success callback

          alert('status: ' + textStatus + ', data:' + data);

// hide delete button

          if(data.flag=="false"){

          $('.granite-collection-selectionbar coral-actionbar-primary coral-actionbar-item>button.cq-damadmin-admin-actions-delete-activator').addClass('foundation-collection-action-hidden');

          }

    });

});

This is a sample code for card view you need to do same for list and column view as well by adding correct selectors

listviewSelector

colummnviewSelector



Arun Patidar

Avatar

Level 3

Hi Arun Patidar

It is not invoking servlet on clicking on asset in any view. It is caching value of flag and got invoked only on refresh.

Avatar

Level 2
I am facing a similar issue? Did you manage to fix it ?

Avatar

Level 3

Arun Patidar

This JS is not working. Select action is not being handled by this JS.

Avatar

Level 3

When I use the same script as it is in

(function($, $document) {

'use strict';

   var requestForDeletion1 = ".coral-masonry-item.foundation-collection-item";

   $(document).on("click", ".'coral-masonry-item.foundation-collection-item coral-quickactions>button[title=\"Select\"]', listviewSelector, colummnviewSelector", function () {

var item = $(this).closest('.foundation-collection-item').attr('data-foundation-collection-item-id')

console.log(item);

// ajax call to servlet

$.get('/bin/dam/collections/checkUser?item='+item,  // url

      function (data, textStatus, jqXHR) {  // success callback

          alert('status: ' + textStatus + ', data:' + data);

// hide delete button

          if(data.flag=="false"){

          $('.granite-collection-selectionbar coral-actionbar-primary coral-actionbar-item>button.cq-damadmin-admin-actions-delete-activator').addClass('founda tion-collection-action-hidden');

          }

    });

});

})(jQuery, jQuery(document));

this query is throwing an error on Uncaught SyntaxError: missing ) after argument list

on line

$(document).on("click", ".'coral-masonry-item.foundation-collection-item coral-quickactions>button[title="Select"]', listviewSelector, colummnviewSelector", function () {

I have changed it to button[title=\"Select\"]' to remove compilation error

then it throws an error

jquery.js:1502 Uncaught Error: Syntax error, unrecognized expression: .'coral-masonry-item.foundation-collection-item coral-quickactions>button[title="Select"]', listviewSelector, colummnviewSelector

    at Function.Sizzle.error (jquery.js:1502)

    at Sizzle.tokenize (jquery.js:2159)

    at Sizzle.compile (jquery.js:2547)

    at Sizzle.select (jquery.js:2638)

    at Function.Sizzle [as find] (jquery.js:903)

    at HTMLDocument.handlers (jquery.js:5278)

    at HTMLDocument.dispatch (jquery.js:5207)

    at HTMLDocument.elemData.handle (jquery.js:4878)

    at HTMLElement.Coral.Component.trigger (coralui3.js:7082)

    at HTMLElement._proxyClick (coralui3.js:42733)

Please guide what I am doing wrong in above. I am not expert of JS.Arun PatidardvnSudheer

Avatar

Community Advisor

Hi,

This is not the complete code, I shared the example/approach to show hide menu item on onclick event.

To work above code below variables/ can be removed or should be defined as a selector for list and column view like card view to specify click item.

var cardViewSelector = $('coral-masonry-item.foundation-collection-item coral-quickactions>button[title="Select"]');

var listviewSelector = define selector like above

var colummnviewSelector = define selector like above



Arun Patidar

Avatar

Level 4

Hi @mkumar ,

Please give a guidance on how you achieved this scenario. That would be very helpful for me to complete the requirement.

Thanks & Regards,

Bhavani Bharanidharan