Web Script: org/alfresco/components/dashboard/customise-dashboard.post
Generated from /share/service/script/org/alfresco/components/dashboard/customise-dashboard.post on Jun 13, 2026 9:38:04 PM

Script Properties
Id:org/alfresco/components/dashboard/customise-dashboard.post
Short Name:Save Customise Dashboard
Description:Saves the result from Customise dashlets & layout components
Authentication:none
Transaction:none
Method:POST
URL Template:/components/dashboard/customise-dashboard
Format Style:any
Default Format:json
Negotiated Formats:[undefined]
Implementation:class org.alfresco.web.scripts.DeclarativeWebScript
Extensions:[undefined]

Store: classpath:alfresco/site-webscripts

File: org/alfresco/components/dashboard/customise-dashboard.post.desc.xml
<webscript>
   <shortname>Save Customise Dashboard</shortname>
   <description>Saves the result from Customise dashlets &amp; layout components</description>
   <format default="json"/>
   <url>/components/dashboard/customise-dashboard</url>
</webscript>
File: org/alfresco/components/dashboard/customise-dashboard.post.json.ftl
{
   "success": true
}
File: org/alfresco/components/dashboard/customise-dashboard.post.json.js
// Get clients json request as a "normal" js object literal
var clientRequest = json.toString();
var clientJSON = eval('(' + clientRequest + ')');

// The dashboard we are modifiying
var dashboardPage = clientJSON.dashboardPage;
var newDashlets = clientJSON.dashlets;

// Change the dashbpards template
var templateId = clientJSON.templateId;
sitedata.associateTemplate(templateId, dashboardPage);

// Get existing dashlets/component bindings for the page
var oldComponents = sitedata.findComponents("page", null, dashboardPage, null);
if (oldComponents === undefined || oldComponents.length === 0)
{
   oldComponents = [];
}

// Unbind all components, old properties will be stored in the oldComponents list.
for (var oi = 0; oi < oldComponents.length; oi++)
{
   var oldComponent = oldComponents[oi];
   var regionId = oldComponent.properties["region-id"];
   if (regionId.match("^component-\\d+-\\d+$"))
   {
      // Unbind the component if it has been delete or moved
      var existingDashlet = null;
      for (var ni = 0; ni < newDashlets.length; ni++)
      {
         var newDashlet = newDashlets[ni];
         if (newDashlet.originalRegionId == regionId)
         {
            existingDashlet = newDashlet;
            break;
         }
      }
      if (existingDashlet == null || existingDashlet.regionId != existingDashlet.originalRegionId)
      {
         // Delete dashlet if it has been removed or moved         
         sitedata.unbindComponent("page", regionId, dashboardPage);
      }
   }
}

// Create bindings for new and moved dashlets.
var newDashlets = clientJSON.dashlets;
for (var ni = 0; ni < newDashlets.length; ni++)
{
   var newDashlet = newDashlets[ni];
   if (newDashlet.originalRegionId)
   {
      if (newDashlet.originalRegionId != newDashlet.regionId)
      {
         // An existing/moved dashlet
         var existingDashlet = null;
         for (var oi = 0; oi < oldComponents.length; oi++)
         {
            var oldDashlet = oldComponents[oi];
            if (oldDashlet.properties["region-id"] == newDashlet.originalRegionId)
            {
               existingDashlet = oldDashlet;
               break;
            }
         }
         if (existingDashlet != null)
         {
            // Its an old component that has been moved, use object from the list so we don't loose the properties            
            var comp = sitedata.newComponent("page", newDashlet.regionId, dashboardPage);
            for (var propertyKey in existingDashlet.properties)
            {
               comp.properties[propertyKey] = existingDashlet.properties[propertyKey];
            }
            comp.properties["region-id"] = newDashlet.regionId;
            comp.properties.url = newDashlet.url;
            comp.save();
         }
      }
   }
   else
   {
      // An new/added dashlet
      var comp = sitedata.newComponent("page", newDashlet.regionId, dashboardPage);
      comp.properties.url = newDashlet.url;
      comp.save();
   }
}

Store: classpath:alfresco/webscripts

[No implementation files]