【问题标题】:Add username to url in share configured action bean link将用户名添加到共享配置的操作 bean 链接中的 url
【发布时间】:2013-12-04 10:37:47
【问题描述】:

我在 share-config xml 文件中定义了一个有效的 alfresco 共享操作,如下所示:

<action id="myAction" type="link" label="sv.menu.label" icon="my-icon">
    <evaluator>my.custom.evaluator</evaluator>
    <param name="itemKind">action</param>
    <param name="itemId">scanvelopAction</param>
    <param name="href">/myapp/prefilled?prop1={node.properties.custom_prop}&amp;prop2={node.properties.custom_prop2}</param>
    <param name="target">_blank</param>
</action>

这很好用。一旦点击操作链接,它就会调用定义的 url 并插入属性。

现在,我想添加正在单击操作链接的当前活动用户的用户名。为此,我补充说:

&amp;amp;u={person.properties.userName}

我也尝试过,根据ScriptNode API、{person.properties.name} 和简单的{person.name}

该操作继续像以前一样工作,但仅将新输入作为文字打印到 URL 中,就好像未定义此属性一样(所以我猜它不是)。我已经尝试了上述的变体,但结果保持不变。我根本找不到关于 ScriptNode API 的个人特定 properties 的文档,而且我发现我尝试过但没有成功的示例(见上文)。

我怎样才能做到这一点?

编辑

我也尝试过user.nameuser.userName 的变体。

【问题讨论】:

    标签: properties action alfresco-share


    【解决方案1】:

    我不确定您是否可以完全按照您的尝试去做(我还寻找了 share-config 根范围的对象)。 “魔法”动作对象或多或少地被硬编码(有人知道在哪里吗?)。

    您可以在 Share/Surf server-javaScript 中使用 root-scoped object: 'user' 或使用存储库 root-scoped object: 'person' in repository server-javascript 获取当前用户

    在存储库 Java 中使用 AuthentificationUtils。

    所以你通常不需要将当前登录的用户传递给 webscripts,他们已经知道了!

    在共享客户端,您通常具有以下值:Alfresco.constants.USERNAME

    所以无论你在哪里真正执行,你都有它

    【讨论】:

    • 好吧,我正在共享客户端上执行,但正如您所见,url 是通过 spring 连接的。我想知道节点对象是如何可用的,以及其他对象是什么。
    【解决方案2】:

    服务器上的弹簧配置线,我猜用户信息不能从那里配置的任何东西中获得。因此,我使用自定义 javascript 操作处理程序解决了这个问题。

    首先,我在 share-config-custom.xml 中连接了我的自定义 javascript,如下所示:

    <config>
        <forms>
            <dependencies>
                <js src="/components/documentlibrary/my-actions.js" />
            </dependencies>
        </forms>
    </config>
    

    在这个 javascript 文件中,我定义了一个用于操作处理的 javascript 函数:

    /**
     * Call a given url like an action of type 'link' would, but allows for configuration of the window.open call and 
     * appends the username of the active user in share to the url.
     * 
     * Uses the 'href' param to form the URL, and allows for the 'name' and 'specs' param.
     * 
     * @method onMyUserActionLink
     * @param record {object} Object literal representing one file or folder to be actioned
     * @param owner
     */
    onMyUserActionLink : function dlA_onMyUserActionLink(record, owner) {
        Alfresco.logger.debug("onMyUserActionLink");
        var scope = this, nodeRef = record.nodeRef, jsNode = record.jsNode;
        Alfresco.logger.debug("Scope formed");
    
        // Get action & params
        var params = this.getAction(record, owner).params;
        Alfresco.logger.debug("Params retrieved");
    
        // Get URL
        var url = params.href;
        Alfresco.logger.debug("URL: " + url);
    
        // Append username
        var appendage;
        if(url.contains("?")) {
            appendage = "&u="+Alfresco.constants.USERNAME;
        } else {
            appendage = "?u="+Alfresco.constants.USERNAME;
        }
        url += appendage;
    
        Alfresco.logger.debug("URL+u: "+url);
    
        // Check for name
        var name = "_blank";
        if(params["name"]) {
            name = params["name"];
        }
        Alfresco.logger.debug("Name: "+name);
    
        // Check for specs
        var specs = "channelmode=yes,directories=no,fullscreen=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=yes,top=0,left=0";
        if(params["specs"]) {
            specs = params["specs"];
        }
        Alfresco.logger.debug("specs: "+specs);
        Alfresco.logger.debug("Opening window with url: "+url +", specs: "+specs+", name: "+name);
        window.open(url, name, specs);
    }
    

    然后我为几个 Action 上下文注册了处理程序:

    (function() {
    
        if (Alfresco.DocumentList) {
            YAHOO.lang.augmentProto(Alfresco.DocumentList, MY.doclib.FolderActions);
        }
    
        if (Alfresco.DocListToolbar) {
            YAHOO.lang.augmentProto(Alfresco.DocListToolbar, MY.doclib.FolderActions);
        }
    
        if (Alfresco.DocumentActions) {
            YAHOO.lang.augmentProto(Alfresco.DocumentActions, MY.doclib.FolderActions);
        }
    
        if (Alfresco.FolderActions) {
            YAHOO.lang.augmentProto(Alfresco.FolderActions, MY.doclib.FolderActions);
        }
    
        if (Alfresco.doclib.Actions) {
            YAHOO.lang.augmentProto(Alfresco.doclib.Actions, MY.doclib.FolderActions);
        }
    
        if (Alfresco.doclib.FolderActions) {
            YAHOO.lang.augmentProto(Alfresco.doclib.FolderActions, MY.doclib.FolderActions);
        }
    
    })();
    

    我在 share-config-custom.xml 中更改了我的操作 bean 配置以使用它:

    <action id="myaction" type="javascript" label="actions.mine.menu.label" icon="my-icon">
        <param name="function">onMyUserActionLink</param>
        <param name="itemKind">action</param>
        <param name="itemId">myAction</param>
        <param name="mode">create</param>
        <param name="destination">{node.nodeRef}</param>
        <param name="successMessage">actions.mine.success</param>
        <param name="failureMessage">actions.mine.fail</param>
        <param name="href">/mylink/linky?id={node.properties.my_idProp}&amp;prop2={node.properties.my_prop2}</param>
        <param name="name">_blank</param>
        <evaluator>evaluator.oa.action.isWhatIWant</evaluator>
    </action>
    

    该操作调用我的自定义 javascript,它附加用户名,然后继续作为链接工作。

    很遗憾,即使是 alfresco 的员工也无法对此做出回应,但我确实希望在互联网上目前缺乏共享客户端 javascript 的情况下,这将有助于大量开发人员!

    提示:例如 bean 配置,请查看 share\WEB-INF\classes\alfresco\share-documentlibrary-config.xml。比如javascript,看share\js\documentlibrary-actions.js

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-24
      • 2016-02-03
      • 1970-01-01
      • 2012-01-12
      • 1970-01-01
      相关资源
      最近更新 更多