cancel
Showing results for 
Search instead for 
Did you mean: 

Extending Alfresco.dashlet.SiteSearch

torben_lauritze
Champ in-the-making
Champ in-the-making
There might be a problem with the Site Search dashlet.

I have added a child folder (containing documents) to a site, using nodeService.addChild(…):


nodeService.addChild(siteFolderContainer, myFolder.getNodeRef(), ContentModel.ASSOC_CONTAINS,
  QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
  QName.createValidLocalName(myFolder.properties[ContentModel.PROP_NAME])));


When I then use the Site Search dashlet, I get an error stating that 'site is undefined'.

The problem is in the <em>renderDescription</em> function in <em>share/components/dashlets/site-search.js</em>:


renderDescription: function SiteSearch_renderDescription(elCell, oRecord, oColumn, oData)
{
    var type = oRecord.getData("type"),
    name = oRecord.getData("name"),
    displayName = oRecord.getData("displayName"),
    site = oRecord.getData("site"),
    path = oRecord.getData("path"),
    nodeRef = oRecord.getData("nodeRef"),
    container = oRecord.getData("container"),
    modifiedOn = oRecord.getData("modifiedOn"),
    siteShortName = site.shortName,
    siteTitle = site.title,
    modified = Alfresco.util.formatDate(Alfresco.util.fromISO8601(modifiedOn)),
    resultType = this.buildTextForType(type),
    href = this.getBrowseUrl(name, type, site, path, nodeRef, container, modified);

    elCell.innerHTML = this.buildNameWithHref(href, displayName) + this.buildDescription(resultType, siteShortName, siteTitle) + this.buildPath(type, path, site);
      },



which uses 'site' unconditionally. I therefore want to YAHOO.extend <em>Alfresco.dashlet.SiteSearch</em> like this:



(function()
{
   Alfresco.dashlet.MagentaSiteSearch = function MagentaSiteSearch_constructor(htmlId)
   {
       Alfresco.dashlet.MagentaSiteSearch.superclass.constructor.call(this, "Alfresco.dashlet.MagentaSiteSearch", htmlId, ["container", "datasource", "datatable"]);

       this.name = "Alfresco.dashlet.MagentaSiteSearch";

       return this;
   };

   /**
    * Extend from Alfresco.dashlet.SiteSearch
    */
   YAHOO.extend(Alfresco.dashlet.MagentaSiteSearch, Alfresco.dashlet.SiteSearch,
   {
      /**
       * Called by the DataTable to render the 'description' cell
       *
       * @method renderThumbnail
       * @param elCell {object}
       * @param oRecord {object}
       * @param oColumn {object}
       * @param oData {object|string}
       */
      renderDescription: function MagentaSiteSearch_renderDescription(elCell, oRecord, oColumn, oData)
      {
         var type = oRecord.getData("type"),
            name = oRecord.getData("name"),
            displayName = oRecord.getData("displayName"),
            site = oRecord.getData("site"),
            path = oRecord.getData("path"),
            nodeRef = oRecord.getData("nodeRef"),
            container = oRecord.getData("container"),
            modifiedOn = oRecord.getData("modifiedOn"),
           
            siteShortName = site ? site.shortName : "undefined",
            siteTitle = site ? site.title : "undefined",
           
            modified = Alfresco.util.formatDate(Alfresco.util.fromISO8601(modifiedOn)),
            resultType = this.buildTextForType(type),
            href = this.getBrowseUrl(name, type, site, path, nodeRef, container, modified);

         elCell.innerHTML = this.buildNameWithHref(href, displayName) + this.buildDescription(resultType, siteShortName, siteTitle) + this.buildPath(type, path, site);
      }
   });
  
})();


But alas, it does not work… The constructor gets called but nothing is shown in the dashlet - and no JavaScript errors are thrown. I have seen this behaviour before, when I had a class that needed some (not supplied) dependencies in the constructor, but I cannot see any missing dependencies this time.

I can extend <em>Alfresco.component.SearchBase</em> and make it work using the entire content of <em>Alfresco.dashlet.SiteSearch</em>, but that is not feasible.

Another way to do it, ugly as it is, is to make my new class <em>Alfresco.dashlet.MagentaSiteSearch</em> wrap <em>Alfresco.dashlet.SiteSearch</em> and overwrite the <em>renderDescription</em> function like this:


Alfresco.dashlet.NukidocSiteSearch = function SiteSearch_constructor(htmlId) {
    var siteSearch = new Alfresco.dashlet.SiteSearch(htmlId);
    siteSearch.renderDescription = function NukidocSiteSearch_renderDescription(elCell, oRecord, oColumn, oData) {
        var type = oRecord.getData("type"),                                
        name = oRecord.getData("name"),                                    
        displayName = oRecord.getData("displayName"),                      
        site = oRecord.getData("site"),                                    
        path = oRecord.getData("path"),                                   
        nodeRef = oRecord.getData("nodeRef"),                              
        container = oRecord.getData("container"),                          
        modifiedOn = oRecord.getData("modifiedOn"),                                                
        siteShortName = site ? site.shortName : "undefined",               
        siteTitle = site ? site.title : "undefined",                                                                  
        modified = Alfresco.util.formatDate(Alfresco.util.fromISO8601(modifiedOn)),
        resultType = this.buildTextForType(type),                          
        href = this.getBrowseUrl(name, type, site, path, nodeRef, container, modified);                                                                    
        elCell.innerHTML = this.buildNameWithHref(href, displayName) + this.buildDescription(resultType, siteShortName, siteTitle) + this.buildPath(type, path, site);
    };
    return siteSearch;                                                     
};                                                                


Can anyone help me doing this the right way (which I think is the YAHOO.extend way)?

Sincerely,
Torben
3 REPLIES 3

ermannorusso
Champ in-the-making
Champ in-the-making
Hi, I just had a very similar issue. I think your problem might be the way you are calling the superclass constructor:
<blockcode>
Alfresco.dashlet.MagentaSiteSearch.superclass.constructor.call(this, "Alfresco.dashlet.MagentaSiteSearch", htmlId, ["container", "datasource", "datatable"]);
</blockcode>

you are passing the parameters required by the Alfresco.component.SearchBase constructor, but they are not the ones required for the Alfresco.dashlet.SiteSearch one. So just try something like this:

<blockcode>
Alfresco.dashlet.MagentaSiteSearch.superclass.constructor.call(this, htmlId);
</blockcode>

Let me know if it works.


Hi ErmannoRusso.

But of course it works… 🙂

Thank you for taking the time to read and answer my problem!

- Torben

torben_lauritze
Champ in-the-making
Champ in-the-making
Hi ErmannoRusso.

But of course it works… 🙂

Thank you for taking the time to read and answer my problem!

- Torben