如何使用AJAX在Alfresco的新选项卡中打开文件夹?

时间:2016-10-16 22:48:07

标签: alfresco yui alfresco-share

我的View Policy中有custom-toolbar.js按钮。单击按钮时,必须在新选项卡中打开Policy文件夹。这是我到目前为止所做的。

    /**
     * View Policy button click handler  
     * 
     * @method onViewDocument
     * @param e {object} DomEvent
     * 
     */
    onViewPolicy: function DLTB_onViewPolicy(e, p_obj)
    {                   
        var newPath = this.currentPath + "/Policy",

        filter = this.currentFilter;
        filter.filterData = newPath;
        // Refresh the Document Library
        YAHOO.Bubbling.fire("changeFilter", filter);

    }

这将在同一选项卡中打开该文件夹。如何在这种情况下使用Alfresco.util.Ajax.request并在新标签中打开它?如果Policy文件夹没有返回任何内容,也可以显示错误消息吗?

1 个答案:

答案 0 :(得分:0)

如果您只想在新标签页中打开路径,则只需使用window.open(url);

如果您想通过调用webscript进行验证,可以使用Alfresco.util.Ajax.request

示例代码:

 Alfresco.util.Ajax.request({
                type: "GET",
                url: Alfresco.constants.PROXY_URI.replace('share/proxy/alfresco', 'alfresco/service') + {webscript url},
                dataType: 'text',
                headers: {
                    Accept: "application/json",
                    "Access-Control-Allow-Origin": "*",
                    "Access-Control-Allow-Methods": "GET"
                },
                successCallback: {
                    fn: function(response) {
            //collect the output.
            //if json
            output = JSON.parse(response.serverResponse.responseText);
            var result =output["result"];
            //if html is the output
            output = (response.serverResponse.responseText);
            var result =/<body.*?>([\s\S]*)<\/body>/.exec(output)[1];//to get contents inside body tag
            if(result says folder is present)
            {
            window.open(newurl);
            }
            else
            {
            //show error popup.
            }
                    },
                    scope: this
                },
                failureMessage: "",
                execScripts: true
            });