Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / form / PasswordValidator.js

History | View | Annotate | Download (5.01 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.form.PasswordValidator"]){
9
dojo._hasResource["dojox.form.PasswordValidator"]=true;
10
dojo.provide("dojox.form.PasswordValidator");
11
dojo.require("dijit.form._FormWidget");
12
dojo.require("dijit.form.ValidationTextBox");
13
dojo.requireLocalization("dojox.form","PasswordValidator",null,"ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
14
dojo.declare("dojox.form._ChildTextBox",dijit.form.ValidationTextBox,{containerWidget:null,type:"password",reset:function(){
15
dijit.form.ValidationTextBox.prototype._setValueAttr.call(this,"",true);
16
this._hasBeenBlurred=false;
17
},postCreate:function(){
18
this.inherited(arguments);
19
if(!this.name){
20
dojo.removeAttr(this.focusNode,"name");
21
}
22
this.connect(this.focusNode,"onkeypress","_onChildKeyPress");
23
},_onChildKeyPress:function(e){
24
if(e&&e.keyCode==dojo.keys.ENTER){
25
this._setBlurValue();
26
}
27
}});
28
dojo.declare("dojox.form._OldPWBox",dojox.form._ChildTextBox,{_isPWValid:false,_setValueAttr:function(_1,_2){
29
if(_1===""){
30
_1=dojox.form._OldPWBox.superclass.attr.call(this,"value");
31
}
32
if(_2!==null){
33
this._isPWValid=this.containerWidget.pwCheck(_1);
34
}
35
this.inherited(arguments);
36
this.containerWidget._childValueAttr(this.containerWidget._inputWidgets[1].attr("value"));
37
},isValid:function(_3){
38
return this.inherited("isValid",arguments)&&this._isPWValid;
39
},_update:function(e){
40
if(this._hasBeenBlurred){
41
this.validate(true);
42
}
43
this._onMouse(e);
44
},_getValueAttr:function(){
45
if(this.containerWidget._started&&this.containerWidget.isValid()){
46
return this.inherited(arguments);
47
}
48
return "";
49
},_setBlurValue:function(){
50
var _4=dijit.form.ValidationTextBox.prototype._getValueAttr.call(this);
51
this._setValueAttr(_4,(this.isValid?this.isValid():true));
52
}});
53
dojo.declare("dojox.form._NewPWBox",dojox.form._ChildTextBox,{required:true,onChange:function(){
54
this.containerWidget._inputWidgets[2].validate(false);
55
this.inherited(arguments);
56
}});
57
dojo.declare("dojox.form._VerifyPWBox",dojox.form._ChildTextBox,{isValid:function(_5){
58
return this.inherited("isValid",arguments)&&(this.get("value")==this.containerWidget._inputWidgets[1].attr("value"));
59
}});
60
dojo.declare("dojox.form.PasswordValidator",dijit.form._FormValueWidget,{required:true,_inputWidgets:null,oldName:"",templateString:dojo.cache("dojox.form","resources/PasswordValidator.html","<div dojoAttachPoint=\"containerNode\">\n\t<input type=\"hidden\" name=\"${name}\" value=\"\" dojoAttachPoint=\"focusNode\" />\n</div>\n"),_hasBeenBlurred:false,isValid:function(_6){
61
return dojo.every(this._inputWidgets,function(i){
62
if(i&&i._setStateClass){
63
i._setStateClass();
64
}
65
return (!i||i.isValid());
66
});
67
},validate:function(_7){
68
return dojo.every(dojo.map(this._inputWidgets,function(i){
69
if(i&&i.validate){
70
i._hasBeenBlurred=(i._hasBeenBlurred||this._hasBeenBlurred);
71
return i.validate();
72
}
73
return true;
74
},this),"return item;");
75
},reset:function(){
76
this._hasBeenBlurred=false;
77
dojo.forEach(this._inputWidgets,function(i){
78
if(i&&i.reset){
79
i.reset();
80
}
81
},this);
82
},_createSubWidgets:function(){
83
var _8=this._inputWidgets,_9=dojo.i18n.getLocalization("dojox.form","PasswordValidator",this.lang);
84
dojo.forEach(_8,function(i,_a){
85
if(i){
86
var p={containerWidget:this},c;
87
if(_a===0){
88
p.name=this.oldName;
89
p.invalidMessage=_9.badPasswordMessage;
90
c=dojox.form._OldPWBox;
91
}else{
92
if(_a===1){
93
p.required=this.required;
94
c=dojox.form._NewPWBox;
95
}else{
96
if(_a===2){
97
p.invalidMessage=_9.nomatchMessage;
98
c=dojox.form._VerifyPWBox;
99
}
100
}
101
}
102
_8[_a]=new c(p,i);
103
}
104
},this);
105
},pwCheck:function(_b){
106
return false;
107
},postCreate:function(){
108
this.inherited(arguments);
109
var _c=this._inputWidgets=[];
110
dojo.forEach(["old","new","verify"],function(i){
111
_c.push(dojo.query("input[pwType="+i+"]",this.containerNode)[0]);
112
},this);
113
if(!_c[1]||!_c[2]){
114
throw new Error("Need at least pwType=\"new\" and pwType=\"verify\"");
115
}
116
if(this.oldName&&!_c[0]){
117
throw new Error("Need to specify pwType=\"old\" if using oldName");
118
}
119
this.containerNode=this.domNode;
120
this._createSubWidgets();
121
this.connect(this._inputWidgets[1],"_setValueAttr","_childValueAttr");
122
this.connect(this._inputWidgets[2],"_setValueAttr","_childValueAttr");
123
},_childValueAttr:function(v){
124
this.set("value",this.isValid()?v:"");
125
},_setDisabledAttr:function(_d){
126
this.inherited(arguments);
127
dojo.forEach(this._inputWidgets,function(i){
128
if(i&&i.attr){
129
i.attr("disabled",_d);
130
}
131
});
132
},_setRequiredAttribute:function(_e){
133
this.required=_e;
134
dojo.attr(this.focusNode,"required",_e);
135
dijit.setWaiState(this.focusNode,"required",_e);
136
this._refreshState();
137
dojo.forEach(this._inputWidgets,function(i){
138
if(i&&i.attr){
139
i.attr("required",_e);
140
}
141
});
142
},_setValueAttr:function(v){
143
this.inherited(arguments);
144
dojo.attr(this.focusNode,"value",v);
145
},_getValueAttr:function(){
146
return this.inherited(arguments)||"";
147
},focus:function(){
148
var f=false;
149
dojo.forEach(this._inputWidgets,function(i){
150
if(i&&!i.isValid()&&!f){
151
i.focus();
152
f=true;
153
}
154
});
155
if(!f){
156
this._inputWidgets[1].focus();
157
}
158
}});
159
}