cancel
Showing results for 
Search instead for 
Did you mean: 

how to override the javascript controller with extension module

mitpatoliya
Star Collaborator
Star Collaborator
I am trying to override the javascript controller node-header.js of components\node-details
as suggested in this post by dave.


now my question is how can I ensure my extension files are loaded and overriding the original files?
6 REPLIES 6

mitpatoliya
Star Collaborator
Star Collaborator
Finally I am able to achieve this but there is one more hurdle how can I check weather particular aspect is applied to that node or not?
Please check
https://forums.alfresco.com/comment/135587#comment-135587

rjohnson
Star Contributor
Star Contributor
Javascript supports hasAspect on a document object. You can check this directly (repository webscripts) or on the client side you will have to get the repository web script to send back a flag.

With actions, you can use the hasAspect evaluator.

Bob Johnson

mitpatoliya
Star Collaborator
Star Collaborator
Actually I am aware about that API but the problem lies even before that
this is my extension javascript controller file. This is extension of OOTB webscript controller.

I am trying to extend node-header.get.js


<import resource="classpath:/alfresco/templates/org/alfresco/import/alfresco-util.js">
for (var i=0; i<model.widgets.length; i++)
{
if (model.widgets.id == "NodeHeader")
{

  if(model.widgets.options.nodeRef!=null)
    {
     var jsNode = new Alfresco.util.Node(model.widgets.options.nodeRef);
     if(jsNode.hasAspect("custom:customAspect")){
        model.widgets.options.showFavourite = false;
        model.widgets.options.showLikes = false;
       
     }
    }
}

}


Error I am getting with this is as follow.
Error Message: 05270002 Failed to execute script 'classpath*:webscripts/custom/nodeheader/hidelikesync/node-header.get.js': 05270001 ReferenceError: "Alfresco" is not defined. (jar:file:/C:/Alfresco/Alfresco42/tomcat/webapps/share/WEB-INF/lib/customshare.jar!/webscripts/custom/nodeheader/hidelikesync/node-header.get.js#1555)

ddraper
World-Class Innovator
World-Class Innovator
It looks like you're trying to use a client-side JavaScript function(the Alfresco.util.Node) on the WebScript tier… this isn't going to work. I think you should actually already have most of the information available to you already and shouldn't need to try to create the js node… I'd suggest you attach the JavaScript debugger (enabled via the WebScripts home page) and set a break point and inspect what data is actually available to you… you should (although I'm not 100% on this) have all the aspect data somewhere in the model.

Unfortunately I don't have time to check this out for you at the moment - but hopefully this should get you going.

mitpatoliya
Star Collaborator
Star Collaborator
Ohhh Ok Dave Thanks again to clarify,

I will try to figure out things as you suggested.
Meanwhile could you please suggest(if there are any) alternate way to hide this favorites and like link from the document details page based on aspects?

Hi Mits,

I'd personally do it using surf extensions (if you're on the recent Alfresco versions)
- Extend the .get.js
Code pretty similar to what you already wrote. The point is to return option flags for each entry to decide if the client-side will display the buttons

- Extend the .get.html
More precisely <@markup id="js"> in order to include your own client-side javascript file

- Create a client side-javascript file
This file is standalone, don't override any other file, and will be included via the previous html extension.
This file will override the Alfresco.DocumentList.generateFavourite and Alfresco.DocumentList.generateLikes to add the check for the custom flags included by your .get.js

But maybe it's overkill for such a simple customisation…
Anyway, good luck with your customisation.