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

            this.initForm();
            this.bindEvents();
        },
        initForm: function () {
            var me = this;
            var modelString = "${model.id}";
            var data;
            if(modelString!=undefined && modelString!=null && modelString.length>0)
            {
                data={
                    id: "${model.id}",
                    name: "${model.name}",
                };

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

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

        }
    };



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

    });
</script>