<%@ 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 resourceRestEditer = {

        actionUrl: "${contextRoot}/dict/addDict",

        init: function () {

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

           var data;
            var modelString = "${model.id}";
            if (modelString != undefined && modelString != null && modelString.length > 0) {
               data={
                    id: "${model.id}",
                    dictName: "${model.dictName}",
                    chineseName: "${model.chineseName}",
                    pyCode: "${model.pyCode}",
                    pid: "${model.pid}",
                    relationTable: "${model.relationTable}",
                    relationColCode: "${model.relationColCode}",
                    relationColValue: "${model.relationColValue}",
                    relationColExtend: "${model.relationColExtend}",
                    remark: "${model.remark}"
                };

                me.actionUrl = "${contextRoot}/dict/updateDict";
            }
            $("#div_info_form").ligerAutoForm({
                data:data,
                validate:{
                    dictName:"required",
                    chineseName:"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.dict.dialogSuccess(data.message, "1");
                        }
                        else {
                            $.ligerDialog.error(data.message);
                        }
                    },
                    error: function (data) {
                        $.ligerDialog.error("Status:" + data.status + "(" + data.statusText + ")");
                    }
                });
            });

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

        }
    };


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

    });
</script>