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

            this.initForm();
            this.bindEvents();
        },
        initForm: function () {
            var me = this;
            $("#category").ligerComboBox({dict: true, dictName: "RESOURCE_DIMENSION"});
            $("#type").ligerComboBox({dict: true, dictName: "RESOURCE_DIMENSION_TYPE"});
            var data;
            var modelString = "${model.id}";
            if (modelString != undefined && modelString != null && modelString.length > 0) {
                data={
                    id: "${model.id}",
                    name: "${model.name}",
                    category: "${model.category}",
                    type: "${model.type}",
                    dictCode: "${model.dictCode}",
                };

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

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

        }
    };


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