I am trying to override the javascript controller node-header.js of components\node-details with the extension module of alfresco share
This is my 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[i].id == "NodeHeader")
{
if(model.widgets[i].options.nodeRef!=null)
{
var jsNode = new Alfresco.util.Node(model.widgets[i].options.nodeRef);
if(jsNode.hasAspect("custom:intranetFile")){
model.widgets[i].options.showFavourite = false;
model.widgets[i].options.showLikes = false;
}
}
}
}
I am getting this error
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)
Error lies in this line
var jsNode = new Alfresco.util.Node(model.widgets[i].options.nodeRef);
as Alfresco object is not available how can I get it?
Based on my answer yesterday on the share-extras-devel list:
Your issue is that you are mixing up your web script JS with client-side JavaScript.
Alfresco.util.Node
is a client-side helper class and is therefore available to client-side JS running in the web browser, but not to your web script code which runs on the server.If you look at the source of
alfresco-util.js
, which you are including, you will see that there is a helper class there but it is calledAlfrescoUtil
.To get some information on this given node I would suggest that you want to use the static method
AlfrescoUtil.getNodeDetails()
from that class, e.g.The structure of the
jsNode
object will be as per the JSON returned by the doclist-v2 webscripts, so you should be able to check for the presence of your custom aspect in theaspects
array property.If you check the source of
alfresco-util.js
you will see that additional parameters are also supported bygetNodeDetails()
. It seems to me you can also pass in an optional site name, plus some options if you wish.