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

        actionUrl:"${contextRoot}/dict/"+("${mode}" != "modify"?"addDictItem":"updateDictItem"),

        $dictName:$("#dictName"),
        init: function () {

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

            this.$dictName.ligerComboBox({dict: true, dictName: "SYSTEM_DICT"});
            var data;
            var modelString = "${model.id}";
            var modelDictString="${model.dictName}"
            if(modelDictString!=undefined && modelDictString!=null && modelDictString.length>0)
            {
                data={
                    id: "${model.id}",

                    dictName: "${model.dictName}",
                    code:"${model.code}",
                    value: "${model.value}",
                    pyCode: "${model.pyCode}",
                    sort: "${model.sort}"
                };
            }
           else  if(modelString!=undefined && modelString!=null && modelString.length>0)
            {

               data={
                    id: "${model.id}",

                    dictName: "${model.dictName}",
                    code:"${model.code}",
                    value: "${model.value}",
                    pyCode: "${model.pyCode}",
                    sort: "${model.sort}"
                };

                me.actionUrl = "${contextRoot}/dict/updateDictItem";
            }
            $("#div_info_form").ligerAutoForm({
                data:data,
                validate:{
                    dictName:"required",

                    value: {
                        required:true
                    }

                },

            });
        },
        bindEvents: function () {
            var me = this;
            $("#btnSave").click(function () {
                if (!$("#div_info_form").ligerAutoForm("validate")) {
                    return;
                }

                var data = $("#div_info_form").ligerAutoForm("getData");
                debugger
                var dictName = data.dictName;
                $.ajax({ //ajax处理
                    type: "POST",
                    url : me.actionUrl,
                    dataType : "json",
                    data:data,
                    cache:false,
                    success :function(data){
                        if(data.successFlg) {
                            //parent.dict.$dictItemGrid.loadServerData({dictId:dictName});
                            parent.dict.dialogSuccess(data.message,"2");
                        }
                        else{
                            $.ligerDialog.error(data.message);
                        }
                    },
                    error :function(data){
                    $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
            }
                });
            });

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

        }
    };



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

    });
</script>