Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.widget.ValidationTextbox");
13
dojo.provide("dojo.widget.ValidationTextbox");
12
dojo.require("dojo.widget.Textbox");
14
dojo.require("dojo.widget.Textbox");
13
dojo.require("dojo.i18n.common");
15
dojo.require("dojo.i18n.common");
14
dojo.widget.defineWidget("dojo.widget.ValidationTextbox", dojo.widget.Textbox, function () {
16
dojo.widget.defineWidget("dojo.widget.ValidationTextbox", dojo.widget.Textbox, function () {
15
	this.flags = {};
17
	this.flags = {};
16
}, {required:false, rangeClass:"range", invalidClass:"invalid", missingClass:"missing", classPrefix:"dojoValidate", size:"", maxlength:"", promptMessage:"", invalidMessage:"", missingMessage:"", rangeMessage:"", listenOnKeyPress:true, htmlfloat:"none", lastCheckedValue:null, templateString:"<span style='float:${this.htmlfloat};'>\n\t<input dojoAttachPoint='textbox' type='${this.type}' dojoAttachEvent='onblur;onfocus;onkeyup'\n\t\tid='${this.widgetId}' name='${this.name}' size='${this.size}' maxlength='${this.maxlength}'\n\t\tclass='${this.className}' style=''>\n\t<span dojoAttachPoint='invalidSpan' class='${this.invalidClass}'>${this.messages.invalidMessage}</span>\n\t<span dojoAttachPoint='missingSpan' class='${this.missingClass}'>${this.messages.missingMessage}</span>\n\t<span dojoAttachPoint='rangeSpan' class='${this.rangeClass}'>${this.messages.rangeMessage}</span>\n</span>\n", templateCssString:".dojoValidateEmpty{\n\tbackground-color: #00FFFF;\n}\n.dojoValidateValid{\n\tbackground-color: #cfc;\n}\n.dojoValidateInvalid{\n\tbackground-color: #fcc;\n}\n.dojoValidateRange{\n\tbackground-color: #ccf;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/Validate.css"), invalidSpan:null, missingSpan:null, rangeSpan:null, getValue:function () {
18
}, {required:false, rangeClass:"range", invalidClass:"invalid", missingClass:"missing", classPrefix:"dojoValidate", size:"", maxlength:"", promptMessage:"", invalidMessage:"", missingMessage:"", rangeMessage:"", listenOnKeyPress:true, htmlfloat:"none", lastCheckedValue:null, templateString:"<span style='float:${this.htmlfloat};'>\n\t<input dojoAttachPoint='textbox' type='${this.type}' dojoAttachEvent='onblur;onfocus;onkeyup'\n\t\tid='${this.widgetId}' name='${this.name}' size='${this.size}' maxlength='${this.maxlength}'\n\t\tclass='${this.className}' style=''>\n\t<span dojoAttachPoint='invalidSpan' class='${this.invalidClass}'>${this.messages.invalidMessage}</span>\n\t<span dojoAttachPoint='missingSpan' class='${this.missingClass}'>${this.messages.missingMessage}</span>\n\t<span dojoAttachPoint='rangeSpan' class='${this.rangeClass}'>${this.messages.rangeMessage}</span>\n</span>\n", templateCssString:".dojoValidateEmpty{\n\tbackground-color: #00FFFF;\n}\n.dojoValidateValid{\n\tbackground-color: #cfc;\n}\n.dojoValidateInvalid{\n\tbackground-color: #fcc;\n}\n.dojoValidateRange{\n\tbackground-color: #ccf;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/Validate.css"), invalidSpan:null, missingSpan:null, rangeSpan:null, getValue:function () {
17
	return this.textbox.value;
19
	return this.textbox.value;
18
}, setValue:function (value) {
20
}, setValue:function (value) {
19
	this.textbox.value = value;
21
	this.textbox.value = value;
20
	this.update();
22
	this.update();
21
}, isValid:function () {
23
}, isValid:function () {
22
	return true;
24
	return true;
23
}, isInRange:function () {
25
}, isInRange:function () {
24
	return true;
26
	return true;
25
}, isEmpty:function () {
27
}, isEmpty:function () {
26
	return (/^\s*$/.test(this.textbox.value));
28
	return (/^\s*$/.test(this.textbox.value));
27
}, isMissing:function () {
29
}, isMissing:function () {
28
	return (this.required && this.isEmpty());
30
	return (this.required && this.isEmpty());
29
}, update:function () {
31
}, update:function () {
30
	this.lastCheckedValue = this.textbox.value;
32
	this.lastCheckedValue = this.textbox.value;
31
	this.missingSpan.style.display = "none";
33
	this.missingSpan.style.display = "none";
32
	this.invalidSpan.style.display = "none";
34
	this.invalidSpan.style.display = "none";
33
	this.rangeSpan.style.display = "none";
35
	this.rangeSpan.style.display = "none";
34
	var empty = this.isEmpty();
36
	var empty = this.isEmpty();
35
	var valid = true;
37
	var valid = true;
36
	if (this.promptMessage != this.textbox.value) {
38
	if (this.promptMessage != this.textbox.value) {
37
		valid = this.isValid();
39
		valid = this.isValid();
38
	}
40
	}
39
	var missing = this.isMissing();
41
	var missing = this.isMissing();
40
	if (missing) {
42
	if (missing) {
41
		this.missingSpan.style.display = "";
43
		this.missingSpan.style.display = "";
42
	} else {
44
	} else {
43
		if (!empty && !valid) {
45
		if (!empty && !valid) {
44
			this.invalidSpan.style.display = "";
46
			this.invalidSpan.style.display = "";
45
		} else {
47
		} else {
46
			if (!empty && !this.isInRange()) {
48
			if (!empty && !this.isInRange()) {
47
				this.rangeSpan.style.display = "";
49
				this.rangeSpan.style.display = "";
48
			}
50
			}
49
		}
51
		}
50
	}
52
	}
51
	this.highlight();
53
	this.highlight();
52
}, updateClass:function (className) {
54
}, updateClass:function (className) {
53
	var pre = this.classPrefix;
55
	var pre = this.classPrefix;
54
	dojo.html.removeClass(this.textbox, pre + "Empty");
56
	dojo.html.removeClass(this.textbox, pre + "Empty");
55
	dojo.html.removeClass(this.textbox, pre + "Valid");
57
	dojo.html.removeClass(this.textbox, pre + "Valid");
56
	dojo.html.removeClass(this.textbox, pre + "Invalid");
58
	dojo.html.removeClass(this.textbox, pre + "Invalid");
57
	dojo.html.addClass(this.textbox, pre + className);
59
	dojo.html.addClass(this.textbox, pre + className);
58
}, highlight:function () {
60
}, highlight:function () {
59
	if (this.isEmpty()) {
61
	if (this.isEmpty()) {
60
		this.updateClass("Empty");
62
		this.updateClass("Empty");
61
	} else {
63
	} else {
62
		if (this.isValid() && this.isInRange()) {
64
		if (this.isValid() && this.isInRange()) {
63
			this.updateClass("Valid");
65
			this.updateClass("Valid");
64
		} else {
66
		} else {
65
			if (this.textbox.value != this.promptMessage) {
67
			if (this.textbox.value != this.promptMessage) {
66
				this.updateClass("Invalid");
68
				this.updateClass("Invalid");
67
			} else {
69
			} else {
68
				this.updateClass("Empty");
70
				this.updateClass("Empty");
69
			}
71
			}
70
		}
72
		}
71
	}
73
	}
72
}, onfocus:function (evt) {
74
}, onfocus:function (evt) {
73
	if (!this.listenOnKeyPress) {
75
	if (!this.listenOnKeyPress) {
74
		this.updateClass("Empty");
76
		this.updateClass("Empty");
75
	}
77
	}
76
}, onblur:function (evt) {
78
}, onblur:function (evt) {
77
	this.filter();
79
	this.filter();
78
	this.update();
80
	this.update();
79
}, onkeyup:function (evt) {
81
}, onkeyup:function (evt) {
80
	if (this.listenOnKeyPress) {
82
	if (this.listenOnKeyPress) {
81
		this.update();
83
		this.update();
82
	} else {
84
	} else {
83
		if (this.textbox.value != this.lastCheckedValue) {
85
		if (this.textbox.value != this.lastCheckedValue) {
84
			this.updateClass("Empty");
86
			this.updateClass("Empty");
85
		}
87
		}
86
	}
88
	}
87
}, postMixInProperties:function (localProperties, frag) {
89
}, postMixInProperties:function (localProperties, frag) {
88
	dojo.widget.ValidationTextbox.superclass.postMixInProperties.apply(this, arguments);
90
	dojo.widget.ValidationTextbox.superclass.postMixInProperties.apply(this, arguments);
89
	this.messages = dojo.i18n.getLocalization("dojo.widget", "validate", this.lang);
91
	this.messages = dojo.i18n.getLocalization("dojo.widget", "validate", this.lang);
90
	dojo.lang.forEach(["invalidMessage", "missingMessage", "rangeMessage"], function (prop) {
92
	dojo.lang.forEach(["invalidMessage", "missingMessage", "rangeMessage"], function (prop) {
91
		if (this[prop]) {
93
		if (this[prop]) {
92
			this.messages[prop] = this[prop];
94
			this.messages[prop] = this[prop];
93
		}
95
		}
94
	}, this);
96
	}, this);
95
}, fillInTemplate:function () {
97
}, fillInTemplate:function () {
96
	dojo.widget.ValidationTextbox.superclass.fillInTemplate.apply(this, arguments);
98
	dojo.widget.ValidationTextbox.superclass.fillInTemplate.apply(this, arguments);
97
	this.textbox.isValid = function () {
99
	this.textbox.isValid = function () {
98
		this.isValid.call(this);
100
		this.isValid.call(this);
99
	};
101
	};
100
	this.textbox.isMissing = function () {
102
	this.textbox.isMissing = function () {
101
		this.isMissing.call(this);
103
		this.isMissing.call(this);
102
	};
104
	};
103
	this.textbox.isInRange = function () {
105
	this.textbox.isInRange = function () {
104
		this.isInRange.call(this);
106
		this.isInRange.call(this);
105
	};
107
	};
106
	dojo.html.setClass(this.invalidSpan, this.invalidClass);
108
	dojo.html.setClass(this.invalidSpan, this.invalidClass);
107
	this.update();
109
	this.update();
108
	this.filter();
110
	this.filter();
109
	if (dojo.render.html.ie) {
111
	if (dojo.render.html.ie) {
110
		dojo.html.addClass(this.domNode, "ie");
112
		dojo.html.addClass(this.domNode, "ie");
111
	}
113
	}
112
	if (dojo.render.html.moz) {
114
	if (dojo.render.html.moz) {
113
		dojo.html.addClass(this.domNode, "moz");
115
		dojo.html.addClass(this.domNode, "moz");
114
	}
116
	}
115
	if (dojo.render.html.opera) {
117
	if (dojo.render.html.opera) {
116
		dojo.html.addClass(this.domNode, "opera");
118
		dojo.html.addClass(this.domNode, "opera");
117
	}
119
	}
118
	if (dojo.render.html.safari) {
120
	if (dojo.render.html.safari) {
119
		dojo.html.addClass(this.domNode, "safari");
121
		dojo.html.addClass(this.domNode, "safari");
120
	}
122
	}
121
}});
123
}});
122
 
124