<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>

<script type="text/javascript">

    /* *************************** 模块初始化 ***************************** */
    var editorAppService = {
        //form
        $condition: null,
        $valid:"${model.valid}",
        init: function () {
            this.bindEvents();
            this.initForm();
            this.resolveParam();
        },
        initForm: function () {
            var me = this;
           var data;
            var modelString = "${model.id}";
            if(modelString!=undefined && modelString!=null && modelString.length>0)
            {
                var valid = "${model.valid}";
                if(valid=='1'){
                    valid="有效";
                }else if(valid=='0'){
                    valid="无效";
                }else{
                    valid="空";
                }

                var healthReportType = "${model.healthReportType}";
                if(healthReportType=='1'){
                    healthReportType="推送";
                }else if(healthReportType=='0'){
                    healthReportType="拉取";
                }else{
                    healthReportType="空";
                }
                var metricsReportType = "${model.metricsReportType}";
                if(metricsReportType=='1'){
                    metricsReportType="推送";
                }else if(metricsReportType=='0'){
                    metricsReportType="拉取";
                }else{
                    metricsReportType="空";
                }

                data={
                    id: "${model.id}",
                    name: "${model.name}",
                   code: "${model.code}",
                   appId: "${model.appId}",
                   valid: valid,
                   version: "${model.version}",
                   description: "${model.description}",
                   endpoint: "${model.endpoint}",
                   requestFormat: "${model.requestFormat}".replace(/<br>/ig,"\n"),
                   requestProtocol: "${model.requestProtocol}",
                   requesModule: "${model.requesModule}".replace(/<br>/ig,"\n"),
                   requestMethod: "${model.requestMethod}",
                   healthReportType: healthReportType,
                   healthEndpoint: "${model.healthEndpoint}",
                   responeResult:"${model.responeResult}".replace(/<br>/ig,"\n"),
                   responeError: "${model.responeError}".replace(/<br>/ig,"\n"),
                   metricsReportType: metricsReportType,
                    requestParameterList:'${model.requestParameterList}',
                    metricsEndpoint: "${model.metricsEndpoint}"
                };

            }

            $("#div_info_form").ligerAutoForm({
                data:data,
                validate:{
                    name:"required",
                    version:"required",
                    valid:"required",
                    endpoint: {
                        required:true
                    }

                },

            });
        },
        bindEvents: function () {
            var me = this;

            $(".m-form-bottom").on("click","#btnCancel",function () {
                parent.appService.dialog.close();
            });


            $("#resourceCondition").css("height", (window.screen.height - 200) / 5).css("overflow", "auto");

        },
        resolveParam: function () {
            //将json的参数列表解析出来
            var paramStr = $("#requestParameterList").val();
            if (paramStr != ""){
                var paramJson = $.parseJSON(paramStr);
                var index =1;
                for (var name in paramJson) {
                    var type = paramJson[name];
                    //动态添加参数
                    var html = '<div class="params" dataIndex="' + index + '" id="paramGroup' + index + '">';
                    html += '<div class="m-form-control" controlType="textbox" id="divName' + index + '_div" style="margin-left:0px;">参数' + index + ' : ' +
                            '<input type="text" id="name' + index + '" value='+name+' readonly="readonly"  class="l-textbox"/></div>';
                    html += '<div class="m-form-control" controlType="textbox" id="divType' + index + '_div" style="margin-left:0px;"><div class="l-text-wrapper"><div style="padding-left:10px;width: 100%;height: 100%;line-height:30px;"> 类型:&nbsp;</div></div>' +
                            '<input type="text" id="type' + index + '" value='+type+' data-type="select" readonly="readonly"  class="l-textbox"/></div></div>';

                    $("#paramDiv").append(html);
                    index++;
                }
            }
            $(".l-text-combobox").find("div[class=l-trigger]").remove();
        }
    };



    $(function () {
        editorAppService.init();

    });
</script>