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

            this.initForm();
            this.bindEvents();
        },
        initForm: function () {
            var me = this;
            $("#userBirthday").ligerDateEditor({format: "yyyy-MM-dd"});
           // me.$form.attrScan();
            var modelString = "${model.id}";
            var data;
            if (modelString != undefined && modelString != null && modelString.length > 0) {
                data={
                    id: "${model.id}",
                    loginCode: "${model.loginCode}",
                    userName: "${model.userName}",
                    userSex: "${model.userSex}",
                    userBirthday: "${model.userBirthday}",
                    userMobile: "${model.userMobile}",
                    userQq: "${model.userQq}",
                    userWechat: "${model.userWechat}",
                    userEmail: "${model.userEmail}"
                };
                me.actionUrl = "${contextRoot}/user/updateUser";
            }

            $("#div_info_form").ligerAutoForm({
                data:data,
                validate:{
                    loginCode:"required",
                    userQq:"digits",
                    userEmail:"email",
                    userMobile:"phone"
                },
                message:{

                    name:"名称不能为空！"
                }

            });
        },
        bindEvents: function () {
            var me = this;
            $("#btnSave").click(function () {
                if (!$("#div_info_form").ligerAutoForm("validate")) {
                    debugger
                    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.user.dialogSuccess(data.message);
                        }
                        else {
                            $.ligerDialog.error(data.message);
                        }
                    },
                    error: function (data) {
                        $.ligerDialog.error("Status:" + data.status + "(" + data.statusText + ")");
                    }
                });
            });

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

        }
    };


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