/**
 * 后台用户修改相关js
 *
 * @author CaiAoLin
 * @date 2017/6/6
 * @version
 */
let rules = {
    newPassword: {
        required: true,
        minlength: 6
    },
    password: {
        required: true,
        minlength: 4
    }
};
$(document).ready(function() {

    // 新增只有前端需要的验证规则
    rules.confirmPassword = {
        required: true,
        equalTo: "input[name='newPassword']"
    };

    // 表单验证规则
    $("#save-form").validate({
        rules: rules,
        errorPlacement: function(error, element) {
            error.addClass('help-block');
            let parentEle = $(element).parent();
            parentEle.addClass('has-warning');
            $(element).prev('label').addClass('control-label');
            $(element).after('<span class="glyphicon glyphicon-warning-sign form-control-feedback" aria-hidden="true"></span>');
            $(element).after(error);
        },
        errorElement: "span",
        success: function(element) {
            $(element).parent().removeClass('has-warning');
            $(element).siblings('.glyphicon-warning-sign').remove();
        }
    });

    // 保存数据
    $("#save").click(function() {
        $("#save-form").attr('action', '/manager/admin').submit();
    });

});