<style>
    table th{
        text-align:right;
        padding-right:10px;
    }
</style>

<div class="row">
    <div class="col-md-3">
        <?= $this->render('/common/_left_menu.php') ?>
    </div>
    <div class="col-md-9">

        <div class="ibox">
            <div class="ibox-title">
                <h5>修改密码</h5>
            </div>

            <div class="ibox-content">
                <form id="form" class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">旧密码</label>
                        <div class="col-sm-3">
                            <input type="password" name="ChangePasswordForm[oldPassword]" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">新密码</label>
                        <div class="col-sm-3">
                            <input id="newPassword1" type="password" name="ChangePasswordForm[newPassword1]" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">重复新密码</label>
                        <div class="col-sm-3">
                            <input type="password" name="ChangePasswordForm[newPassword2]" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-3 col-sm-offset-2">
                            <div class="btn btn-primary" id="submit">点我提交</div>
                        </div>
                    </div>
                </form>
            </div>
        </div>

    </div>

</div>

<script type="text/javascript" src="/ui/js/jquery.1.9.1.min.js"></script>
<link href="<?= STATIC_URL ?>/ui/css/plugins/toastr/toastr.min.css" rel="stylesheet">
<script src="<?= STATIC_URL ?>/ui/js/plugins/toastr/toastr.min.js"></script>
<script>
$(document).ready(function(){
    $("#form").validate({
        rules: {
            "ChangePasswordForm[oldPassword]": {
                required: true
            },
            "ChangePasswordForm[newPassword1]": {
                required: true,
                minlength: 6
            },
            "ChangePasswordForm[newPassword2]": {
                required: true,
                equalTo:"#newPassword1",
                minlength: 6
            }
        }
    });
});
$("#submit").on("click", function() {
    if($("#form").valid()){
        $.ajax({
            type: "POST",
            url: "/ib/password/change-password",
            data: $('#form').serialize(),
            dataType: "json",
            success: function(response) {
                if(response.code == 1) {
                    toastr.success(response.message, "提示");
                } else {
                    toastr.error(response.message, "提示");
                }
            }
        });
    }
    return false;
});
</script>