postCreate method calling multiple times in aikau

379 Views Asked by At

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************.");

}
});
});
1

There are 1 best solutions below

7
Muralidharan Deenathayalan On

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