Alfresco Object is not available in extension modu

2019-09-20 00:53发布

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?

1条回答
狗以群分
2楼-- · 2019-09-20 01:15

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 called AlfrescoUtil.

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.

var jsNode = AlfrescoUtil.getNodeDetails(model.widgets[i].options.nodeRef);

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 the aspects array property.

If you check the source of alfresco-util.js you will see that additional parameters are also supported by getNodeDetails(). It seems to me you can also pass in an optional site name, plus some options if you wish.

查看更多
登录 后发表回答