AEM CQ 56 - Disable Component (EditRollOver) Menu Delete

Goal


This post can be useful if you'd like to disable some of the menu options of components added to par on a page, for example, you might want to disable Delete option for targeted components on a page, to avoid deletion by authors (An other ideal way is to statically include the component) Check the demo





Solution


1) Create folder /apps/clientlibs

2) Create /apps/clientlibs/myclientlib of type cq:ClientLibraryFolder and add property categories with String value cq.widgets

3) Create /apps/clientlibs/myclientlib/js.txt of type nt:file, add the following

                       disableDelete.js

4) Create /apps/clientlibs/myclientlib/disableDelete.js of type nt:file and add the following code

CQ.Ext.ns("MyClientLib");

MyClientLib.EditRollover = CQ.Ext.extend(CQ.wcm.EditRollover, {
    handleContextMenu: function(e){
        MyClientLib.EditRollover.superclass.handleContextMenu.call(this, e);

        var component = this.element.linkedEditComponent;

        if (!component || !component.menuComponent) {
            return;
        }

        var menu = component.menuComponent;
        var dTargeting = menu.find('text', "Disable targeting");

        //if Disable targeting menu option doesn't exist, donot disable Delete
        if(!dTargeting || dTargeting.length == 0){
            return;
        }

        var del = menu.find('text', "Delete");

        if(del && del.length > 0){
            del[0].setDisabled(true);
        }
    }
});

CQ.Ext.reg("editrollover", MyClientLib.EditRollover);

6 comments:

  1. Hi Sreekanth,

    My need is to disable the Target option site wide from edit context menu. I followed the above mentioned steps to disable Target option but it did not work. Is it the case that this method only gets called if the component is already targeted?

    ReplyDelete
  2. Thanks but I am now able to make it run. Can you suggest if there is a way to disable the same on editbar layout?

    ReplyDelete
    Replies
    1. Runal could you please provide the code snippet you used to disable the Target option sitewide? I am also trying to do the same thing.

      Thanks in advance

      Delete
  3. Hi, i need to add a new field in this menu.
    Could you give me one example?

    ReplyDelete
    Replies
    1. check this post http://experience-aem.blogspot.com/2014/05/aem-cq-6-msm-setting-jcr-permissions-on-live-copy-components.html

      something like

      var component = this.element.linkedEditComponent;

      if (!component || !component.menuComponent) {
      return;
      }

      var menu = component.menuComponent;

      if (menu.cancelInheritanceSet) {
      return;
      }

      menu.addSeparator();

      menu.add({
      text: "Set Cancel Inheritance",
      handler: function () {
      var dialog = ExperienceAEM.MSM.Blueprint.getCancelInheritanceDialog(path);
      dialog.show();
      }
      });

      Delete
  4. Runal could you please provide the code snippet you used to disable the Target option sitewide? I am also trying to do the same thing

    ReplyDelete