cancel
Showing results for 
Search instead for 
Did you mean: 

How to customize the client script in Alfresco

skumar_us
Champ in-the-making
Champ in-the-making
How to customize the client script in Alfresco.Is it possible to modify the existing client js file and put in somefolder like web-exension which we  do for controller script while customizing ??
2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator
Hello,

the common approach is to customize the FTL or config XML (via Surf extension modules) and load custom scripts in Addition or instead of standard scripts. There is no mechanism in place that works like web-extension for web scripts.

Regards
Axel

muralidharand
Star Contributor
Star Contributor
Hi,
The response may be a delayed and hopefully will help you + someone in the future also.
In Alfresco 4.1.X, we extended the existing client javascript(YUI Based) to override few methods in the object-finder.js.
We placed the new javascript file in the components\object-finder\ directory and used Alfresco Module Deploy option to inject the new javascript in the runtime.

Here is the detailed explanation.
We wanted to change a bit of "_generatePickerChildrenUrlParams" method in the object-finder.js file.

We created a new javascript, with the name of "object-finder-extended.js" file and placed the components\object-finder\ director.
While extending the existing method, you've to use "prototype" keyword  and don't use ":" as mentioned below.


    Alfresco.ObjectRenderer.prototype._generatePickerChildrenUrlParams = function …..(){}

We added the current site-id in the request….
siteId = Alfresco.constants.SITE;


var $html = Alfresco.util.encodeHTML,
      $hasEventInterest = Alfresco.util.hasEventInterest,
      $combine = Alfresco.util.combinePaths;


Alfresco.ObjectRenderer.prototype._generatePickerChildrenUrlParams = function ObjectRenderer__generatePickerChildrenUrlParams(searchTerm)
      {

       try
         {
      
             //Basically we wanted to sent the current site name to the repository.            
            siteId = Alfresco.constants.SITE;
            //If the user is not in the Site context, read the value from the workflow hidden variable
            if (siteId =="")
                siteId = Dom.get('workflow_siteId').value;
          
         }
         catch(err)
         {
            //Don't do anything. If the object finder does not find anything, picker control will throw exception.
         }
        
       //site param is added. This is used to control group search in group review workflow
         var params = "?selectableType=" + this.options.itemType + "&searchTerm=" + encodeURIComponent(searchTerm) +
                      "&size=" + this.options.maxSearchResults+"&siteId="+siteId;                
        
         // if an XPath start location has been provided and it has not been resolved
         // yet, pass it to the pickerchildren script as a parameter
         if (!this.startLocationResolved && this.options.startLocation &&
              this.options.startLocation.charAt(0) == "/")
         {
            params += "&xpath=" + encodeURIComponent(this.options.startLocation);
         }
        
         // has a rootNode been specified?
         if (this.options.rootNode)
         {
            var rootNode = null;

            if (this.options.rootNode.charAt(0) == "{")
            {
               if (this.options.rootNode == "{companyhome}")
               {
                  rootNode = "alfresco://company/home";
               }
               else if (this.options.rootNode == "{userhome}")
               {
                  rootNode = "alfresco://user/home";
               }
               else if (this.options.rootNode == "{siteshome}")
               {
                  rootNode = "alfresco://sites/home";
               }
            }
            else
            {
               // rootNode is either an xPath expression or a nodeRef
               rootNode = this.options.rootNode;
            }
            if (rootNode !== null)
            {
               params += "&rootNode=" + encodeURIComponent(rootNode);
            }
         }
        
         if (this.options.params)
         {
            params += "&" + encodeURI(this.options.params);
         }
        
         return params;
      }