﻿//自定义组件，用于验证密码强度

Type.registerNamespace('NBBS.CustomControl');

NBBS.CustomControl.PasswordValidator = function(associatedElement) {
    NBBS.CustomControl.PasswordValidator.initializeBase(this, [associatedElement]);
}

NBBS.CustomControl.PasswordValidator.prototype = {
    _data: null,
    _isPass :false,
    
    get_data: function() {
        return this._data;
    },

    set_data: function(value) {
        if (this._data !== value) {
            this._data = value;
            this.raisePropertyChanged('data');
        }
    },
    
    get_isPass: function() {
    return this._isPass;
    },

    set_isPass: function(value) {
        if (this._isPass !== value) {
            this._isPass = value;
            this.raisePropertyChanged('isPass');
        }
    },

    initialize: function() {
        //构造函数
        NBBS.CustomControl.PasswordValidator.callBaseMethod(this, 'initialize');
    
        this.get_element().innerHTML="<font color=\"#CCCCCC\">密码可以由字母、数字和符号组成</font>";
        this.set_isPass(false);
    },

    dispose: function() {
        //析构函数
        if(this.get_element())
        {
            this.get_element().innerHTML="";
        }
    
        NBBS.CustomControl.PasswordValidator.callBaseMethod(this, 'dispose');
    },

    validate: function() {
        //验证数据
        this.get_element().innerHTML="<img src=\"Icons/loading_validate.gif\" alt=\"\" />&nbsp;<font color=\"CCCCCC\">正在检测密码强度……</font>";
        Validate.ValidatePassword(this.get_data(),this.onSucceeded,this.onFailed,this);
    },

    onSucceeded: function(result,validator) {
        //执行成功时的回调函数
        switch(result)
        {
            case 0:
                validator.get_element().innerHTML="<font color=\"#FF0000\">密码不合法，密码长度必须在6位以上</font>";
                validator.set_isPass(false);
                break;
            case 1:
                validator.get_element().innerHTML="<font color=\"#FF6600\">密码强度-低</font>";
                validator.set_isPass(true);
                break;
            case 2:
                validator.get_element().innerHTML="<font color=\"#0000FF\">密码强度-中</font>";
                validator.set_isPass(true);
                break;
            case 3:
                validator.get_element().innerHTML="<font color=\"#339933\">密码强度-高</font>";
                validator.set_isPass(true);
                break;
            default:
                break; 
        }
    },
    
    onFailed: function(error,validator) {
        validator.get_element().innerHTML="<font color=\"#FF0000\">内部错误，无法完成检验，请与管理员联系</font>";
    }
}

NBBS.CustomControl.PasswordValidator.registerClass('NBBS.CustomControl.PasswordValidator', Sys.UI.Control);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
