1

We are adding some custom actions in Selected Items menu in Faceted search screen 5.1+aikau(100.0.1);

but when i load the page,In Custom widget postCreate method is calling twice and when i select 'Edit properties' then also onSelectedDocumentsAction function calling twice.

if i push one more extra item in selectedItemsActionsGroup then that many times(3 times) its calling.

var selectedItemsActionsGroup = widgetUtils.findObject(model.jsonModel.widgets,"id", "SELECTED_ITEMS_ACTIONS_GROUP");


    selectedItemsActionsGroup.config.widgets.push(
                    {
                        id : "OnActionEditProperties",
                        name : "faceted-search/CustomBulkSelectItems/CustomBulkSelectItems",
                        config : {
                            label : "Edit",
                            iconImage : url.context
                                    + "/res/components/documentlibrary/actions/y-16.png",
                            type : "action-link",
                            permission : "",
                            asset : "",
                            href : "",
                            hasAspect : "",
                            notAspect : "",
                            publishTopic : "BULK_OPS",
                            publishPayload : {
                                action : "onActionEditProperties",
                            }
                        }
                    },
                    {
                        id : "OnActionManaged",
                        name : "faceted-search/CustomBulkSelectItems/CustomBulkSelectItems",
                        config : {
                            label : "Managed",
                            iconImage : url.context
                                    + "/res/components/documentlibrary/actions/x-16.png",
                            type : "action-link",
                            permission : "",
                            asset : "",
                            href : "",
                            hasAspect : "",
                            notAspect : "",
                            publishTopic : "BULK_OPS",
                            publishPayload : {
                                action : "OnActionManaged",
                            }
                        }
                    });

*****************
CustomBulkSelectItems.js
**********************

            define(["dojo/_base/declare",
        "alfresco/services/FormsRuntimeService",
        "alfresco/core/UrlUtilsMixin",
         "alfresco/enums/urlTypes",
        "alfresco/core/Core",
        "alfresco/menus/AlfFilteringMenuItem",
        "alfresco/documentlibrary/_AlfDocumentListTopicMixin",
        "alfresco/core/CoreXhr",
        "dojo/_base/lang",
        "dojo/dom-class",
        "dojo/_base/array",
        "service/constants/Default","alfresco/core/topics"], 
        function(declare,FormsRuntimeService, UrlUtilsMixin,urlTypes,AlfCore ,AlfFilteringMenuItem, _AlfDocumentListTopicMixin,AlfCoreXhr, lang, domClass, 
                array, AlfConstants,topics) {

   return declare([FormsRuntimeService,UrlUtilsMixin,AlfCore,AlfFilteringMenuItem,_AlfDocumentListTopicMixin,AlfCoreXhr], {


       i18nRequirements: [ {i18nFile: "./CustomBulkSeledtItems.properties"} ],


      postCreate: function alfresco_documentlibrary_CustomBulkSelectItems__postCreate() {
         console.log(" bulkops postCreate************.");
         this.alfSubscribe("BULK_OPS", lang.hitch(this, this.onSelectedDocumentsAction));
         this.inherited(arguments);
      } ,

      /**
       * This function handles requests to perform actions on the currently selected documents. It takes the 
       * provided payload and updates it with the 
       *
       * @instance
       * @param {object} payload The payload containing the details of the action being requested
       * @fires alfresco/core/topics#MULTIPLE_ITEM_ACTION_REQUEST
       */
      onSelectedDocumentsAction: function alfresco_documentlibrary_CustomBulkSelectItems__onSelectedDocumentsAction(payload) {  
 console.log(" bulkops onSelectedDocumentsAction************.");

}
});
});
user739115
  • 1,117
  • 5
  • 20
  • 41

1 Answers1

0

I think you're calling same widget faceted-search/CustomBulkSelectItems/CustomBulkSelectItems twice and publishTopic also called twice from the get.js file. After change the widget in the get.js it is looking fine to me.

Share your thoughts.

I changed your something like below and the output is like that.

enter image description here

enter image description here

var selectedItemsActionsGroup = widgetUtils.findObject(model.jsonModel.widgets,"id", "SELECTED_ITEMS_ACTIONS_GROUP");

selectedItemsActionsGroup.config.widgets.push(
                    {
                        id : "OnActionEditProperties",
                        name : "faceted-search/CustomBulkSelectItems/CustomBulkSelectItems",
                        config : {
                            label : "Edit",
                            iconImage : url.context
                                    + "/res/components/documentlibrary/actions/y-16.png",
                            type : "action-link",
                            permission : "",
                            asset : "",
                            href : "",
                            hasAspect : "",
                            notAspect : "",
                            publishTopic : "BULK_OPS",
                            publishPayload : {
                                action : "onActionEditProperties",
                            }
                        }
                    },
                    {
                        id : "OnActionManaged",
                        name : "faceted-search/CustomBulkSelectItems/CustomBulkSelect",
                        config : {
                            label : "Managed",
                            iconImage : url.context
                                    + "/res/components/documentlibrary/actions/x-16.png",
                            type : "action-link",
                            permission : "",
                            asset : "",
                            href : "",
                            hasAspect : "",
                            notAspect : "",
                            publishTopic : "BULK_OPS_1",
                            publishPayload : {
                                action : "OnActionManaged",
                            }
                        }
                    });

CustomBulkSelectItems.js

define(["dojo/_base/declare",
        "alfresco/services/FormsRuntimeService",
        "alfresco/core/UrlUtilsMixin",
         "alfresco/enums/urlTypes",
        "alfresco/core/Core",
        "alfresco/menus/AlfFilteringMenuItem",
        "alfresco/documentlibrary/_AlfDocumentListTopicMixin",
        "alfresco/core/CoreXhr",
        "dojo/_base/lang",
        "dojo/dom-class",
        "dojo/_base/array",
        "service/constants/Default","alfresco/core/topics"], 
        function(declare,FormsRuntimeService, UrlUtilsMixin,urlTypes,AlfCore ,AlfFilteringMenuItem, _AlfDocumentListTopicMixin,AlfCoreXhr, lang, domClass, 
                array, AlfConstants,topics) {

   return declare([FormsRuntimeService,UrlUtilsMixin,AlfCore,AlfFilteringMenuItem,_AlfDocumentListTopicMixin,AlfCoreXhr], {


       i18nRequirements: [ {i18nFile: "./CustomBulkSeledtItems.properties"} ],


      postCreate: function alfresco_documentlibrary_CustomBulkSelectItems__postCreate() {
         console.log(" bulkops postCreate************.");
         this.alfSubscribe("BULK_OPS", lang.hitch(this, this.onSelectedDocumentsAction));
         this.inherited(arguments);
      } ,

      /**
       * This function handles requests to perform actions on the currently selected documents. It takes the 
       * provided payload and updates it with the 
       *
       * @instance
       * @param {object} payload The payload containing the details of the action being requested
       * @fires alfresco/core/topics#MULTIPLE_ITEM_ACTION_REQUEST
       */
      onSelectedDocumentsAction: function alfresco_documentlibrary_CustomBulkSelectItems__onSelectedDocumentsAction(payload) {  
 console.log(" bulkops onSelectedDocumentsAction************.");

}
});
});

CustomBulkSelect.js

define(["dojo/_base/declare",
        "alfresco/services/FormsRuntimeService",
        "alfresco/core/UrlUtilsMixin",
         "alfresco/enums/urlTypes",
        "alfresco/core/Core",
        "alfresco/menus/AlfFilteringMenuItem",
        "alfresco/documentlibrary/_AlfDocumentListTopicMixin",
        "alfresco/core/CoreXhr",
        "dojo/_base/lang",
        "dojo/dom-class",
        "dojo/_base/array",
        "service/constants/Default","alfresco/core/topics"], 
        function(declare,FormsRuntimeService, UrlUtilsMixin,urlTypes,AlfCore ,AlfFilteringMenuItem, _AlfDocumentListTopicMixin,AlfCoreXhr, lang, domClass, 
                array, AlfConstants,topics) {

   return declare([FormsRuntimeService,UrlUtilsMixin,AlfCore,AlfFilteringMenuItem,_AlfDocumentListTopicMixin,AlfCoreXhr], {


       i18nRequirements: [ {i18nFile: "./CustomBulkSeledtItems.properties"} ],


      postCreate: function alfresco_documentlibrary_CustomBulkSelectItems__postCreate() {
         console.log(" CustomBulkSeledt bulkops postCreate************.");
         this.alfSubscribe("BULK_OPS_1", lang.hitch(this, this.onSelectedDocumentsAction));
         this.inherited(arguments);
      } ,

      /**
       * This function handles requests to perform actions on the currently selected documents. It takes the 
       * provided payload and updates it with the 
       *
       * @instance
       * @param {object} payload The payload containing the details of the action being requested
       * @fires alfresco/core/topics#MULTIPLE_ITEM_ACTION_REQUEST
       */
      onSelectedDocumentsAction: function alfresco_documentlibrary_CustomBulkSelectItems__onSelectedDocumentsAction(payload) {  
 console.log(" CustomBulkSeledt bulkops onSelectedDocumentsAction************.");

}
});
});

Updated info

Please look at the AlfFilteringMenuItem.js and

postCreate: function alfresco_menus_AlfFilteringMenuItem____postCreate() {
         this.filterTopic && this.alfSubscribe(this.filterTopic, lang.hitch(this, this.filter));
         this.inherited(arguments);
      },

and

filter: function alfresco_menus_AlfFilteringMenuItem__filter(payload) {
         this.alfLog("warn", "No implementation of filtering extension point", payload);
      }

There is no specific implemenation is found. If you enable debug logs, you should be able to the warn messages.

I looked at the aikau logs and you can see the default behaviour also having muliple requests( each request for each widger) similar to yours. The only difference is , filter method and publish (lang.hitch) stuffs. Hope you're clear now. enter image description here

  • If you see the OOB faceted-search.get.js ,they have used same name as "alfresco/documentlibrary/AlfDocumentActionMenuItem" and topic as 'ALF_SELECTED_DOCUMENTS_ACTION_REQUEST' for multiple actions(Copy To,Move To,Download as Zip,Start Workflow etc).For my custom actions I don't think It will be a good logic if we create new files for every custom action. – user739115 Mar 14 '17 at 13:41
  • Thanks for pointing out and you're correct. Let me check the OOB stuffs and will update you. – Muralidharan Deenathayalan Mar 14 '17 at 14:41
  • I updated the answer (**Updated info**), please take a look. – Muralidharan Deenathayalan Mar 14 '17 at 16:57
  • so you mean its existing behaviour and whatever logic I have written is correct.In that case Can I use same Name 'name : "faceted-search/CustomBulkSelectItems/CustomBulkSelectItems" and publishTopic : "BULK_OPS" for our multiple custom actions? ' – user739115 Mar 15 '17 at 06:27
  • Yes, but it will trigger the event multiple times. Do you really publishTopic there.. I would recommend debug more for the deleteaction to understand how the publishtopic is handled in Aikau. – Muralidharan Deenathayalan Mar 15 '17 at 06:30
  • If I dont mention the publishTopic then How come our custom method[onSelectedDocumentsAction] will be called?.publishTopic is subscribed in postCreate method so that our method[onSelectedDocumentsAction] will be called.Do you see anything wrong? – user739115 Mar 15 '17 at 06:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/138079/discussion-between-user739115-and-muralidharan-deenathayalan). – user739115 Mar 15 '17 at 06:49