<%@ 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 resourceRestDetailEditer = {
        //form
        $form: $("#div_info_form"),
        validator: null,
        actionUrl: "${contextRoot}/resourceRest/addResourceRestDetail",
        init: function () {
            this.initForm();
            this.bindEvents();
        },
        initForm: function () {
            $("#resourceRestId").ligerComboBox({dict: true, dictName: "RESOURCE_REST_ID"});
            $("#paramType").ligerComboBox({dict: true, dictName: "SYSTEM_PARAM_TYPE"});
            $("#returnType").ligerComboBox({dict: true, dictName: "SYSTEM_PARAM_TYPE"});
            $("#httpType").ligerComboBox({dict: true, dictName: "HTTP_TYPE"});
            var me = this;
            me.$form.attrScan();
            var modelString = "${model.id}";
            var data;
            if (modelString != undefined && modelString != null && modelString.length > 0) {
               data={
                    id: "${model.id}",
                    name: "${model.name}",
                    code: "${model.code}",
                    namespace: "${model.namespace}",
                    type: "${model.type}",
                    resourceRestId: "${model.resourceRestId}",
                    param: "${model.param}",
                    paramType: "${model.paramType}",
                    returnValue: "${model.returnValue}",
                    returnType: "${model.returnType}"
                };

                me.actionUrl = "${contextRoot}/resourceRest/updateResourceRestDetail";
            }
            this.$form.ligerAutoForm({
                data:data,
                validate:{
                    name:"required",
                    code:"required",
                    namespace:"required",
                    resourceRestId:"required"
                }
            })
        },
        bindEvents: function () {
            var me = this;
            $("#btnSave").click(function () {
                if (!$("#div_info_form").ligerAutoForm("validate")) {
                    return;
                }
                var data = $("#div_info_form").ligerAutoForm("getData")
                $.ajax({ //ajax处理
                    type: "POST",
                    url: me.actionUrl,
                    dataType: "json",
                    data: data,
                    cache: false,
                    success: function (data) {
                        if (data.successFlg) {
                            parent.resourceRest.dialogSuccess(data.message);
                        }
                        else {
                            $.ligerDialog.error(data.message);
                        }
                    },
                    error: function (data) {
                        $.ligerDialog.error("Status:" + data.status + "(" + data.statusText + ")");
                    }
                });
            });

            $("#btnCancel").click(function () {
                parent.resourceRest.$dialog.close();
            });

        }
    };


    $(function () {
        resourceRestDetailEditer.init();
    });
</script>