XPages

注册内容窗体的内容来源

开发者可以把自己应用中想要对外展示的数据注册成Xpages的内容源,供其他应用场景使用。

注册方式如下:

第一:注册的三种方式

在应用的扩展插件类中注册xpages内容源的三种主要方式:

第一种例如:

//注册xpages
        Map<String, Object> params4 = new HashMap<String, Object>();
        params4.put("systemName", "我的日程");
        params4.put("urlIdentifier", "com.actionsoft.apps.calendar_xpages");
        params4.put("type", "1");
        params4.put("xpagesContent", "./w?sid=@sid&cmd=com.actionsoft.apps.calendar_xpages");
        list.add(new AppExtensionProfile("我的日程", "aslp://com.actionsoft.apps.addons.xpages/registerApp", params4));

说明:

1、如果您需要注册的内容源只是一个简单的URL,不需要进行参数配置,可以使用type值为1的情况。

2、该种注册方式可以参考日程中的我的日程的注册展示。

展示示例图:

第二种例如:

        //注册xpages
        Map<String, Object> params3 = new HashMap<String, Object>();
        params3.put("systemName", "CMS部件");
        params3.put("functionPre", "cmswidgetid");
        params3.put("urlIdentifier", "com.actionsoft.apps.cms_xpages");
        params3.put("type", "2");
        params3.put("xpagesContent",CmsUtils.getXpagesContent() );
        list.add(new AppExtensionProfile("CMS部件", "aslp://com.actionsoft.apps.addons.xpages/registerApp", params3));

注册用到的Js代码段


// site widget
function getCmsSiteWidgetData() {

     var params = {};
    var url = './jd?sid=' + sid + '&cmd=com.actionsoft.apps.cms_xpages_get_sitedata';
    awsui.ajax.post(url, params, function(responseObject) {
        if (responseObject['result'] == 'ok') {
            var siteList = responseObject["data"]['siteList'];
            var contentStr="<div class='xpageCmsWidget-wrap'>";
            contentStr+="<div class='xpages-label-text'>请选择站点</div>";

            contentStr+="<select class='cms-site-select txt xpages-select-text'>";
            contentStr+="<option value=''>--请选择站点--</option>";
            for (var i=0; i < siteList.length; i++) {
                 var siteInfo=siteList[i];
                contentStr+='<option value="'+siteInfo.id+'" siteindex="'+i+'">'+siteInfo.siteName+'</option>';
            };
            contentStr+="</select>";
            contentStr+="<div class='xpages-label-text '>请选择部件</div>";
            contentStr+="<select  class='cms-widget-select txt xpages-select-text'>";
            contentStr+="</select>";
            contentStr+="<textarea class='url xpagesContent'></textarea>";
            contentStr+="</div>";
            $(".cwapp-right").append(contentStr);




             var cwUrl = getCwUrl();//获取之前的存储的url链接
             if(cwUrl!=null && cwUrl!=undefined && cwUrl!=""){
                 //$(".xpageCmsWidget-wrap").find(".xpagesContent").val(cwUrl);

                 var oldWidgetId = getParamString(cwUrl,"widgetid");
                var siteid = getParamString(cwUrl,"siteid");
                if(oldWidgetId!="" && siteid!=null){
                    $('.cms-site-select').val(siteid);
                    var index = $('.cms-site-select option:selected').attr("siteindex");
                    var widgetList=siteList[index].widgetList;
                    $(".cms-widget-select").empty();

                    //选择站点后渲染部件
                    var widgetStr="";
                    widgetStr+="<option value=''>--请选择部件--</option>";
                    for (var i=0; i < widgetList.length; i++) {
                        var widgetInfo=widgetList[i];
                        widgetStr+='<option value="'+widgetInfo.widgetId+'">'+'板块:['+widgetInfo.boardName+']下的部件:['+widgetInfo.widgetName+']</option>';
                    };
                    $(".cms-widget-select").append(widgetStr);
                    $('.cms-widget-select').val(oldWidgetId);


                }
            }


            //选择站点
            $(".cms-site-select").change(function(){
                 var index = $('.cms-site-select option:selected').attr("siteindex");
                 var widgetList=siteList[index].widgetList;
                 $(".cms-widget-select").empty();

                 //选择站点后渲染部件
                 var widgetStr="";
                widgetStr+="<option value=''>--请选择部件--</option>";
                 for (var i=0; i < widgetList.length; i++) {
                     var widgetInfo=widgetList[i];
                    widgetStr+='<option value="'+widgetInfo.widgetId+'">'+'板块:['+widgetInfo.boardName+']下的部件:['+widgetInfo.widgetName+']</option>';
                 };
                 $(".cms-widget-select").append(widgetStr);
                 $(".xpageCmsWidget-wrap").find(".xpagesContent").val("");
            });


            $(".cms-widget-select").change(function(){
                var widgetid = $('.cms-widget-select option:selected').val();
                var siteid = $('.cms-site-select option:selected').val();
                    if(widgetid!=""){
                        var url="./w?sid=@sid&cmd=com.actionsoft.apps.cms_xpages&siteid="+siteid+"&widgetid="+widgetid;
                        $(".xpageCmsWidget-wrap").find(".xpagesContent").val(url);
                    }else{
                        $(".xpageCmsWidget-wrap").find(".xpagesContent").val("");

                    }
            });

        } else {
            $.simpleAlert(responseObject['msg'], responseObject['result']);
        }
    }, 'json');


}


function getParamString(url,name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = url.match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

function getCwUrl(){
    //修改时默认参数定位
    var subcwid = $("#cw-manage-dlg-content").find("li.current").attr("subcwid");
    var cwUrl = $(".nav-config-panel[subcwid="+subcwid+"]").find("#cwUrl").val();
    return cwUrl;
}

说明:

1、如果您需要注册的内容源只是一个不需要保存在校验的配置项, 可以使用type值为2的情况。

2、该种注册方式可以参考内容管理的cms部件的注册。

3、使用类似于可以标识自己应用分类的class(例如:xpageCmsWidget-wrap)对注册代码进行包裹

展示示例图:

第三种例如:

        //注册功能快捷栏

        String linkqPage = HtmlPageTemplate.merge(XPagesConstant.APP_XPAGES, "xpages.linkquickly.register.html", null);
        Map<String, Object> linkq = new HashMap<String, Object>();
        linkq.put("systemName", "功能快捷栏");
        linkq.put("urlIdentifier", "com.actionsoft.apps.addons.xpages_link_quickly");
        linkq.put("functionPre", "linkquickly");
        linkq.put("type", "3");
        linkq.put("xpagesContent", linkqPage);
        list.add(new AppExtensionProfile("功能快捷栏", "aslp://com.actionsoft.apps.addons.xpages/registerApp", linkq));

注册的代码段

<div class="xpageLinkQuickly-wrap" id = "xpageLinkQuickly-wrap">
<link rel="stylesheet" type="text/css" href="../apps/com.actionsoft.apps.addons.xpages/css/xpages.linkquickly.register.css">
<script type="text/javascript"  name="xpageLinkjsContext" src="../apps/com.actionsoft.apps.addons.xpages/js/xpages.linkquickly.register.js"></script>
<textarea style="display: none;" class="xpagesContent"></textarea>
<table id="xpageLinkQuicklytable" cellspacing="0" cellpadding="2" style="font-size:13px;width:100%;">
    <colgroup>
        <col width="24%"/>
        <col width="76%"/>
    </colgroup>
    <tr>
        <td>分类</td>
        <td class="required">
            <select id="groupKey" style="width: 200px;"></select>
        </td>
    </tr>
    <tr>
        <td>显示方式</td>
        <td>
            <select id="viewType" style="width:200px;"></select>
        </td>
    </tr>
    <tr>
        <td>个人添加</td>
        <td>
            <select id="isAllowAdd"></select>
        </td>
    </tr>
    <tr>
        <td>设管理员</td>
        <td style="position:relative;">
            <div id="linkquicklyAC" class="awsui-iconfont" style="position:absolute;left:0px;bottom:3px;font-size:14px;color:#E8574E;cursor:pointer;">&#59212;</div>
            <div id="linkgroup_ac_content" class="txt" style="width: 95%;display: none;"></div>
        </td>
    </tr>
    <tr>
        <td>URL地址</td>
        <td><textarea id="linkquicklyUrlText" type="text" class="txt awsui-textbox" style="height:68px;resize: none;width:244px;" spellcheck="false"></textarea></td>
    </tr>
    <!--<tr>
        <td colspan="2"><span id="saveGroupBtn" class="button blue">保存分类</span></td>
    </tr>-->
</table>

<script>
    linkQuicklyUrltool.init();

    function linkquickly_getUrl(){
        var groupKey = $("#select2-groupKey-container").text();
        if (typeof (groupKey)=="undefined"||groupKey=="") {
          $.simpleAlert("请填写分类");
          return false;
       }
        var params = {
            groupKey: groupKey,
            viewType:viewTypeVal,
            isAllowAdd:isAllowAdd
        };
        var url = './jd?sid=' + sid + '&cmd=com.actionsoft.apps.addons.xpages_linkquickly_saveconfig';
        awsui.ajax.post(url, params, function (responseObject) {
            linkQuicklyUrltool.setText();
            $.simpleAlert(responseObject['msg'], responseObject['result']);
        }, 'json');

    }
</script>
</div>

注册用到的Js

var resourceId ,resourceType = "xpages.link.group.ac";
var groupKey;
var viewTypeVal="0";
var isAllowAdd="0";
var linkQuicklyUrltool = {
    xpageInit: function () {
        this.initLinkGroup();
        this.initViewType();
        this.initLocked();

        var cwUrl = $("#cwUrl").val();
        var linkUrlobj = linkQuicklyUrltool.getLinkquicklyParams(cwUrl);
        //是否需要初始化默认值
        if (linkUrlobj != null && linkUrlobj.cmd != null && linkUrlobj.cmd == "com.actionsoft.apps.addons.xpages_link_quickly") {
            groupKey = linkUrlobj.groupKey.trim();
            isAllowAdd = linkUrlobj.isAllowAdd;
            viewTypeVal = linkUrlobj.viewType;
            resourceId = "XPAGES-QUICKLY-"+groupKey;
            this.getGroupId({
                callback:function (groupId) {
                    $("#groupKey").val(groupId).trigger("change");
                }
            });

            $("#viewType").val("viewType_"+viewTypeVal).trigger("change");
            $("#isAllowAdd").val("locked_"+isAllowAdd).trigger("change");
            this.setText();
        }

        //this.saveGroup();
        this.settingACEvent(resourceId,resourceType);
    },
    getGroupId:function(opt){
        var param = {
            url: './jd',
            type: 'POST',
            dataType: "json",
            data: {
                cmd: "com.actionsoft.apps.addons.xpages_linkquickly_get_groupId",
                sid: sid,
                groupKey:groupKey.trim()
            },
            alert: false,
            success: function (ro) {
                if (ro.result == "ok") {
                    if (opt.callback) {
                        opt.callback(ro.data.groupId);
                    }
                }
            }
        }
        awsui.ajax.request(param);
    },
    getLinkquicklyParams: function (url) {
        var params = {};
        try {
            var ps = url.split("?")[1].split("&");
            for (var i = 0, size_i = ps.length; i < size_i; i++) {
                var paramStr = ps[i];
                var map = paramStr.split("=");
                if (map.length == 2) {
                    params[map[0]] = map[1];
                }
            }
        } catch (e) {
        }
        return params;
    },
    initLinkGroup:function(){
        var that = this;
       /* $("#groupKey").blur(function(){
            debugger;
            groupKey = $("#groupKey").val();
            that.setText();
        });*/
        /*var groupKeyParam = {
            width : 250,
            data : groupDatas
        }
        $("#groupKey").select2(groupKeyParam);

        $("#groupKey").on("select2:select", function (evt) {
            groupKey = evt.params.data.value;
            that.setText();
        });*/
        that.getGroupDataSel({
            callback: function (list) {
                that.selectList = list;
                $("#groupKey").select2({
                    data: list,
                    width:250,
                    tags:true
                });
                var cwUrl = $("#cwUrl").val();
                var linkUrlobj = linkQuicklyUrltool.getLinkquicklyParams(cwUrl);
                //是否需要初始化默认值
                if (linkUrlobj != null && linkUrlobj.cmd != null && linkUrlobj.cmd == "com.actionsoft.apps.addons.xpages_link_quickly") {
                    groupKey = linkUrlobj.groupKey;
                    isAllowAdd = linkUrlobj.isAllowAdd;
                    viewTypeVal = linkUrlobj.viewType;
                    resourceId = "XPAGES-QUICKLY-"+groupKey;
                    debugger;
                    $("#groupKey").val(groupKey).trigger("change");
                    $("#viewType").val("viewType_"+viewTypeVal).trigger("change");
                    $("#isAllowAdd").val("locked_"+isAllowAdd).trigger("change");
                }
                $("#groupKey").trigger("change");
                that.setText();
            }
        });

        $("#groupKey").on("select2:select", function (evt) {
            groupKey = evt.params.data.text.trim();
            that.setText();
        });
    },
    getGroupDataSel: function (opt) {
        var value = opt.value;
        if (value == "")
            return;
        var param = {
            url: './jd',
            type: 'POST',
            dataType: "json",
            data: {
                cmd: "com.actionsoft.apps.addons.xpages_linkquickly_get_groupkey",
                sid: sid
            },
            alert: false,
            success: function (ro) {
                if (ro.result == "ok") {
                    if (opt.callback) {
                        opt.callback(ro.data.datas);
                    }
                }
            }
        }
        awsui.ajax.request(param);
    },
    settingACEvent:function(resourceId,resourceType){
        var that = this;
        $("#linkquicklyAC").unbind('click').bind('click',function(){
            if (typeof (groupKey.trim())=="undefined"||groupKey.trim()=="") {
                $.simpleAlert("请填写分类");
                return false;
            }
            that.openLinkGroupAC(resourceId,resourceType);
        });

    },
    //打开AC授权窗口
    openLinkGroupAC:function (resourceId,resourceType){
        resourceId = "XPAGES-QUICKLY-"+groupKey.trim();
        var dlg = FrmDialog.open({
            title : "授权",
            width : 700,
            height : 380,
            url : "./w",
            id:"testmylink",
            data : {
                sid : sid,
                cmd : "CLIENT_COMMON_AC_ACTION_OPEN",
                resourceId : resourceId,
                resourceType : resourceType
            },
            buttons : [{
                text : '添加',
                cls : "blue",
                handler : function() {
                    dlg.win().saveAC();
                    //that.getAcData(resourceId,resourceType);
                }
            }, {
                text : '关闭',
                handler : function() {
                    dlg.close();
                    //that.getAcData(resourceId,resourceType);
                }
            }]
        });
    },
    getAcData:function(resourceId,resourceType){
        var params={
            resourceId:resourceId,
            resourceType:resourceType
        };
        var url = './jd?sid=' + sid + '&cmd=com.actionsoft.apps.addons.xpages_linkgroup_aclist';
        awsui.ajax.post(url, params, function(responseObject) {
            if(responseObject['result'] == 'ok'){
                var userModelList = responseObject["data"]['userModelList'];
                if (userModelList.length>0){
                    for (var i=0;i<userModelList.length;i++){
                        var user = userModelList[i];
                        var name = user.name;
                        $("#linkgroup_ac_content").text(name);
                    }
                }
            }else{
                $.simpleAlert(responseObject['msg'], responseObject['result']);
            }
        }, 'json');
    },

    initViewType:function(){
        var that = this;
        //显示方式
        var viewType = {
            width : 250,
            data : [
                {id:"viewType_0",text:"图标",value:"0"},
                {id:"viewType_1",text:"列表",value:"1"}
            ]};
        $("#viewType").select2(viewType);

        $("#viewType").on("select2:select", function (evt) {
            viewTypeVal = evt.params.data.value;
            that.setText();
        });
    },
    initLocked: function (){
        var that = this;
        //是否允許個人添加
        var lockParam = {
            width : 250,
            data : [
                {id:"locked_0",text:"不允许",value:"0"},
                {id:"locked_1",text:"允许",value:"1"}
            ]};
        $("#isAllowAdd").select2(lockParam);

        $("#isAllowAdd").on("select2:select", function (evt) {
            isAllowAdd = evt.params.data.value;
            that.setText();
        });
    },
    init: function () {
        this.xpageInit();
    },
    setText: function () {
        var groupKey = $("#select2-groupKey-container").text();
        var str = "./w?sid=@sid&cmd=com.actionsoft.apps.addons.xpages_link_quickly&groupKey="+groupKey.trim()+"&viewType="+viewTypeVal+"&isAllowAdd="+isAllowAdd;
        $("#linkquicklyUrlText").val(str);
        $("#xpageLinkQuickly-wrap").find(".xpagesContent").val(str);
    },
    saveGroup:function () {
        /*debugger;*/
        var that = this;
        /*$(".cwurldlg-ok-btn").unbind('click').bind('click',function(){
            /!*if (typeof (groupKey)=="undefined"||groupKey=="") {
                $.simpleAlert("请填写分类");
                return false;
            }*!/
            var params = {
                groupKey: groupKey,
                viewType:viewTypeVal,
                isAllowAdd:isAllowAdd
            };
            var url = './jd?sid=' + sid + '&cmd=com.actionsoft.apps.addons.xpages_linkquickly_saveconfig';
            awsui.ajax.post(url, params, function (responseObject) {
                that.setText();
                //回填url
                var subCwId = $(".select-cwurl-btn").parents(".nav-config-panel").attr("subcwid");
                if (responseObject['result']=="ok"){
                    setUrlEvent(subCwId);
                }
                $.simpleAlert(responseObject['msg'], responseObject['result']);
            }, 'json');
        });*/
    }
};

要求,页面中有:

注册代码最外部使用div包裹 id 和class要可以标识到自己的代码段
例如:
<div  class="xpageLinkQuickly-wrap" id = "xpageLinkQuickly-wrap"><div>

存储url的文本域
<textarea style="display: none;" class="xpagesContent"></textarea>

把自己通过配置项生成的url,复制给该文本域,例如:

var str='url';
$("#xpageLinkQuickly-wrap").find(".xpagesContent").val(str);

说明:

1、如果您需要注册的内容源需要有一些自己的校验方法,可以在注册代码中添加校验方法,按照方法名前缀加上_getUrl,不满足条件时,return false;

2、该种注册方式可以参考功能快捷栏

展示示例图:

第二、特别说明

1、要求需要根据Xpages回填的默认URL可以自动定位到已选参数值。 获取已经选择的url可以使用方法getCwUrl() 获取url中的参数值可以使用法法getParamString()


function getParamString(url,name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = url.match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}

function getCwUrl(){
    //修改时默认参数定位
    var subcwid = $("#cw-manage-dlg-content").find("li.current").attr("subcwid");
    var cwUrl = $(".nav-config-panel[subcwid="+subcwid+"]").find("#cwUrl").val();
    return cwUrl;
}

2、第一种和第二种的注册方式在内容源切换时会被重新渲染,第三种会默认渲染到内容源页面中。切换内容源导航树时,不会被重新渲染。

3、配置项布局展示说明,如果是配置项较多,可以用左右布局,例如KMS知识目录等;如果配置项较少,可以用上下布局,如cms部件等

样式特别说明

label 可使用xpages的内置class值,xpages-label-text

请选择站点

select 可使用xpages的内置class值,xpages-select-text