This repository has been archived by the owner on Jan 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CGFormObject.js
executable file
·156 lines (132 loc) · 4.68 KB
/
CGFormObject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
///////////////////////////////////////////////////////
// CGFormObject (Constructor Function)
// Philip Saa ([email protected])
// May 17, 2003
///////////////////////////////////////////////////////
_global.CGFormObject = function(){
this.Initialize();
}
/***********************************************
- Need to complete CGClass definition
- CGFormObject.prototype = new CGClass();
***********************************************/
///////////////////////////////////////////////////////
CGFormObject.prototype.Initialize = function(){
// Public Properties
this._action = ""; // default value is null
this._method = "GET"; // default value is "GET" - [GET, POST]
// Private Properties
this.DataInput = new Array();
this.DataValidationHandler = new String("");
}
///////////////////////////////////////////////////////
// Public Methods
///////////////////////////////////////////////////////
CGFormObject.prototype.AddInput = function(textField, type, maxlength){
if (arguments.length < 1){ return; }
var InputObject = new Object();
InputObject.textField = textField;
InputObject.type = (type != undefined) ? type : "text"; // available types[text, number, email, url]
InputObject.maxlength = (maxlength != undefined) ? maxlength : 0; // default value is 0 [unlimited]
this.DataInput.push(InputObject);
}
CGFormObject.prototype.Validate = function(){
return true;
}
CGFormObject.prototype.Submit = function(){
// Collect Data
var DataTransfer = new LoadVars();
var InputData = this._getInputData();
// Validate
var iScore = 0;
var max = InputData.length;
for (var iInt = 0; iInt < max; iInt++){
if (this._validate(InputData[iInt].value, InputData[iInt].type)){
iScore += 1;
DataTransfer[InputData[iInt].textField._name] = InputData[iInt].value;
} else {
iScore += 0;
InputData[iInt].textField.text = "Invalid Data!";
InputData[iInt].textField.textColor = 0x000000;
InputData[iInt].textField.onSetFocus = function(oldFocus){
this.text = "";
this.textColor = "0xFF0000";
}
}
}
// Send Data
if (iScore == max){
var sAction = this.action;
var sMethod = this.method;
DataTransfer["process"] = "submit"
DataTransfer.sendAndLoad(sAction, this, sMethod);
trace("killa")
this.onSubmit();
}
}
CGFormObject.prototype.Reset = function(){
var max = this.DataInput.length;
for (var iInt = 0; iInt < max; iInt++){
this.DataInput[iInt].textField.text = "";
this.DataInput[iInt].textField.borderColor = "0x000000"
}
}
///////////////////////////////////////////////////////
// Private Methods
///////////////////////////////////////////////////////
CGFormObject.prototype._getInputData = function(){
var InputData = new Array();
var max = this.DataInput.length;
for (var iInt = 0; iInt < max; iInt++){
var InputObj = this.DataInput[iInt];
var InputInstance = eval(this.DataInput[iInt].textField);
InputData.push({textField:InputObj.textField, value:InputInstance.text, type:InputObj.type, maxlength:InputObj.maxlength})
}
return InputData;
}
CGFormObject.prototype._validate = function(value, type){
var bValid = false;
if (type == "text"){
bValid += (value.length > 0) ? true : false;
}
if (type == "number"){
bValid += (isNaN(parseInt(value))) ? true : false;
}
if (type == "email"){
bValid += (this._validateEmail(value)) ? true : false;
}
if (type == "url"){
bValid += (this._validateUrl(value)) ? true : false;
}
return bValid;
}
CGFormObject.prototype._validateEmail = function(value){
var bValid = false;
var test1 = (value.indexOf("@") > 0);
var test2 = ((value.indexOf("@") +2) < value.lastIndexOf("."));
var test3 = (value.lastIndexOf(".") < (value.length -2));
bValid = (test1 & test2 && test3) ? true : false;
return bValid
}
CGFormObject.prototype._validateUrl = function(value){
var bValid = false;
var test1 = (value.indexOf("http://") == 0);
var test2 = (value.lastIndexOf(".") < (value.length -2));
bValid = (test1 && test2) ? true : false;
return bValid
}
CGFormObject.prototype._getAction = function(){ return this._action; }
CGFormObject.prototype._setAction = function(sValue){ this._action = sValue; }
CGFormObject.prototype._getMethod = function(){ return this._method; }
CGFormObject.prototype._setMethod = function(sValue){ this._method = sValue; }
///////////////////////////////////////////////////////
// Properties
///////////////////////////////////////////////////////
CGFormObject.prototype.addProperty("action", this._getAction, this._setAction);
CGFormObject.prototype.addProperty("method", this._getMethod, this._setMethod);
///////////////////////////////////////////////////////
// Usage
///////////////////////////////////////////////////////
//
//
///////////////////////////////////////////////////////