AnsweredAssumed Answered

Hide Dashlet when customize dashboard *SOLVED*

Question asked by alexcipr on Mar 22, 2011
Latest reply on Aug 8, 2012 by jpfi
My need was to hide some dashlet from view to all user, when they customize share dasboard. I obtain this result modifying customise-dashlets.get.js in ${tomcat_home}/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/dashboard

I've added this function:


function isAvalaibleDashlet(dashletName){
        /*this array contains the script name of dashlet we want to see*/
   var enabledDashlet=["alfresco-network","cmisfeed","my-documents","my-profile","webview"];
        /*————————————————————————————————————————————*/
   for(var j = 0; j < enabledDashlet.length; j++){
      if(enabledDashlet[j] == dashletName){
         return true;
      }
   }
   return false;
}


and modified those two:


// Transform the webscripts to easy-to-access dashlet items for the template
var availableDashlets = [];
for (var i = 0; i < webscripts.length; i++)
{
   var webscript = webscripts[i];
   var uris = webscript.getURIs();
   var scriptId, scriptName, shortNameId, descriptionId;
   if (uris !== null && uris.length > 0 && webscript.shortName !== null)
   {
      // Use the webscript ID to generate a message bundle ID
      //
      // This should really be retrieved from an explicit value but the web scripts framework does not provide
      // a means for storing message bundle IDs, and the web framework is not being used here.
     scriptId = webscript.id;
     scriptName = scriptId.substring(scriptId.lastIndexOf("/") + 1, scriptId.lastIndexOf("."));

        logger.log("******************************  "+scriptName);
        shortNameId = "dashlet." + scriptName + ".shortName";
        descriptionId = "dashlet." + scriptName + ".description";
        if(isAvalaibleDashlet(scriptName)){
         availableDashlets[i] =
           {
             url: uris[0],
             // msg.get(key) returns key if no matching value
             shortName: (msg.get(shortNameId) != shortNameId ? msg.get(shortNameId) : webscript.shortName),
             description: (msg.get(descriptionId) != descriptionId ? msg.get(descriptionId) : webscript.description)
           };
        }
      
   }
  // else skip this webscript since it lacks uri or shortName
}
           logger.log("****************************** END FOR");

[…]


// Transform the webscripts to easy-to-access dashlet items for the template
var columns = [[], [], [], []];
for (i = 0; i < components.length; i++)
{
   var comp = components[i];

   var regionId = comp.properties["region-id"],
      theUrl = comp.properties.url;
   if (regionId !== null && theUrl !== null)
   {
      // Create dashlet
      var shortName, description, d;
      for (var j = 0; j < availableDashlets.length; j++)
      {
         d = availableDashlets[j];
       if(d !== undefined){
          if (d.url == theUrl)
          {
            shortName = d.shortName;
            description = d.description;
            break;
          }
       }
      }
      var dashlet =
      {
         url: theUrl,
         shortName: shortName,
         description: description,
         originalRegionId: regionId
      };

      // Place it in correct column and in a temporary row literal
      if (regionId.match("^component-\\d+-\\d+$"))
      {
         var column = parseInt(regionId.substring(regionId.indexOf("-") + 1, regionId.lastIndexOf("-"))),
            row = parseInt(regionId.substring(regionId.lastIndexOf("-") + 1));
         columns[column-1][row-1] = dashlet;
      }
   }
   // else skip this component since it lacks regionId or shortName
}

[…]


I hope it could be usefull for you

Regards

Alessandro

Outcomes