jsonwidgetalfrescoalfresco-shareaikau

In Aikau. How to get the search query parameters inside a custom widget in a dialog?


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:

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


Solution

  • 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).