2

I am using Alfresco 5.1.e

In the search page "/share/page/dp/ws/faceted-search". I have included a button "AlfDynamicPayloadButton".

When the button is clicked it opens a dialog with "ALF_CREATE_DIALOG_REQUEST" and inside of it my custom widget.

I need the current search parameters into that widget to create a special visualisation.

My code in the file "faceted-search.get.js":

 var myWidget = {
   name : "alfresco/buttons/AlfDynamicPayloadButton",
   config : {
     label : "My Button",
     useHash : true,
     hashDataMapping : {
        "hashFragmentParameterName" : "buttonPayloadProperty"
     },
     publishPayloadSubscriptions : [ {
       topic : "ALF_SEARCH_REQUEST"
     }],

     publishTopic : "ALF_CREATE_DIALOG_REQUEST",
     publishPayloadType : "PROCESS",
     publishPayloadModifiers : [ "processDataBindings" ],
     publishPayload : {
       dialogTitle : "My Title",
       widgetsContent : [ {
         name : "myPackage/Example",
         config : {
           width : 400,
           height : 500
           // other configurations
         }
       }]
     }
   }
 };

 var widget = widgetUtils.findObject(model.jsonModel.widgets, "id",
   "FCTSRCH_TOP_MENU_BAR");
 widget.config.widgets.push(myWidget);

My Widget:

define(
[ 
  "dojo/_base/declare", 
  "dijit/_WidgetBase", 
  "alfresco/core/Core",
  "dijit/_TemplatedMixin", 
  "dojo/_base/lang",
  "dojo/text!./html/Example.html" 
],
function(declare, _Widget, Core, _Templated, lang, template) {
    [ _Widget, Core, _Templated ],{
  templateString : template,
  i18nRequirements : [ {
    i18nFile : "./i18n/Example.properties"
  } ],
  cssRequirements : [ {
     cssFile : "./css/Example.css"
  } ],
  constructor : function example__constructor() {
    // the widget is created each time the button is pressed
    this.alfSubscribe("ALF_SEARCH_REQUEST", 
      lang.hitch(this, this.upgradeSearchParameter));
    this.inherited(arguments);  
  }, 
  upgradeSearchParameter: 
      function example__upgradeSearchParameter(args){
    // this line never run
    this.searchParameter = args;
   }
  });
});

So far I have tried:

  • Subscribe inside the widget to ALF_SEARCH_REQUEST. The problem with that is the widget haven't been created when topic is published.
  • Include "alfresco/services/SearchService" has dependency of my widget. I can access with that to some information of the query like the "sort", "site", "sortAscending", etc, but not the "term".
  • Include "alfresco/search/AlfSearchList" has dependency of my widget. I have "searchTerm", but it is always empty "".
  • Using "publishPayloadSubscriptions" in my button. All the information of the parameters of the query are inside of the dialog, but it not exists option to populate my widget with that information

    publishPayloadSubscriptions : [ {
      topic : "ALF_SEARCH_REQUEST"
    }],
    

Is there some way to get all the parameters of the last query in my custom widget?

Troncador
  • 3,356
  • 3
  • 23
  • 40

2 Answers2

2

I think you're on the right path with subscribing to the ALF_SEARCH_REQUEST topic. If you're finding that the initial ALF_SEARCH_REQUEST topic (on loading the page) is being published before your AlfDynamicPayloadButton has registered its subscription then you might want to consider upgrading to a more recent Aikau release.

We fixed an issue in the 1.0.68 release to ensure that no publications are fired until all widgets have completed loading on the page (this was actually to address the scenario where there are multiple Surf components on the page which shouldn't be the case on the faceted search page!). We work around this problem by having a shared singleton PubQueue that doesn't release any publications until after all widgets and services have been created.

I suppose this could depends where you're creating your AlfDynamicPayloadButton - for example, if it's in the search results then it will be created after the ALF_SEARCH_REQUEST topic has been published.

Have you checked the DebugLog to ensure that the subscription in your button is being setup correctly (for example that there are no scoping issues?).

Have you verified that a fixed payload (with hard-coded data) will result in the displaying the dialog as you require? Have you verified that the button is not successfully subscribing to the topic but just not building the payload as required.

Could you also update your question to show the configuration for your AlfDynamicPayloadButton as this might help me figure out what the problem is.

Dave Draper
  • 1,837
  • 11
  • 25
  • I made some changes in my question, I put my code . At the end what I want is to have the last "search parameters" inside my widget. And apparently each time the button is clicked it creates a new instance of my widget destroying everything inside it . With inspect element I have checked that all the parameters of the search query are inside of the dialog widget but I don't know how to pass them to my widget. I think my code is not working because the event "ALF_SEARCH_REQUEST" is triggered before my widget has been created. Is there somewhere store the last search request parameters? – Troncador Sep 09 '16 at 04:57
2

OK, now that you've added the model I think I might be able to provide a better answer...

It looks like you've just copied the example from the JSDoc. Where you've set the hashDataMapping configuration you can actually reconfigure this to get the search term.

Each time you search, the search text is set on the URL as the searchTerm hash parameter. This means that with useHash configured to be true you can configure the AlfDynamicPayloadButton like this:

{
  name: "alfresco/buttons/AlfDynamicPayloadButton",
  config : {
    label : "My Button",
    useHash : true,
    hashDataMapping : {
      searchTerm: "widgetsContent.0.config.searchTerm"
    },
    publishPayloadSubscriptions: [],
    publishTopic: "ALF_CREATE_DIALOG_REQUEST",
    publishPayload: {
      dialogTitle: "My Title",
      widgetsContent: [
        {
          name: "myPackage/Example",
          config: {
            width : 400,
            height : 500
            // other configurations
          }
        }
      ]
    }
  }
};

The key thing here is that you are mapping the searchTerm URL hash value to the widgetsContent.0.config.searchTerm property of your publishPayload. This means that your custom widget within your dialog will be assigned the last search term that was used (to an attribute also called searchTerm that your widget can reference).

Dave Draper
  • 1,837
  • 11
  • 25