<%@ 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 editorMenu = {
        //form
        //$form: $("#div_info_form"),
        actionUrl:"${contextRoot}/menu/addMenu",
        //validator: null,
        init: function () {

            this.initForm();
            this.bindEvents();
        },
        initForm: function () {
            var me = this;
            $("#pid").ligerComboBox({dict:true,dictName:"SYSTEM_MENU_PID"});
            $("#openType").ligerComboBox({dict:true,dictName:"SYSTEM_MENU_OPENTYPE"});

           // me.$form.attrScan();
            var modelString = "${model.id}";
            var data;

            if(modelString!=undefined && modelString!=null && modelString.length>0)
            {
                data={
                    id: "${model.id}",
                    code: "${model.code}",
                    sort:"${model.sort}",
                    openType:"${model.openType}",
                    name: "${model.name}",
                    pyCode: "${model.pyCode}",
                    pid: "${model.pid}",
                    url: "${model.url}",
                    remark: "${model.remark}"
                };

                me.actionUrl = "${contextRoot}/menu/updateMenu";
            }
            $("#div_info_form").ligerAutoForm({
                data:data,
                validate:{
                    code:"required",
                    name: {
                        required:true
                    }
                },
                message:{
                    code:"代码不能为空！",
                    name:"名称不能为空！"
                }
            });
        },
        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.menu.dialogSuccess(data.message);
                        }
                        else{
                            $.ligerDialog.error(data.message);
                        }
                    },
                    error :function(data){
                        $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                    }
                });
            });

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

        }
    };



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

    });
</script>