Alfresco Object is not available in extension module in alfresco share

六眼飞鱼酱① 提交于 2019-12-12 03:42:14

问题


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:


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.



来源:https://stackoverflow.com/questions/17335307/alfresco-object-is-not-available-in-extension-module-in-alfresco-share

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!