-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserForm.mxml
229 lines (190 loc) · 7.19 KB
/
UserForm.mxml
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
remove="exit(event)" creationComplete="created(event)"
>
<fx:Script>
<![CDATA[
import com.alfo.utils.VirtualKeyboard;
import events.KioskError;
import events.KioskEvent;
import events.UserEvent;
import events.ViewEvent;
import model.Settings;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.validators.Validator;
[Bindable]
protected var validatorArr:Array;
[Bindable]
public var data:Object;
protected var currentURN:String;
public var optin_marketing:Boolean;
public var optin_terms:Boolean;
private var virtualKeyboard:VirtualKeyboard;
private var settings:Settings;
public function created(event:FlexEvent=null):void
{
this.addEventListener( Event.INIT, init);
}
public function init(event:Event=null):void
{
clearData();
settings = Settings.instance;
if (this.parentApplication.data!=null)
{
//this.userFirstName.setFocus();
data = this.parentApplication.data;
this.currentURN = data.urn;
optin_marketing = data.optin_marketing;
optin_terms = data.optin_terms;
} else
{
//Console.log("NO CURRENT URN", this);
}
validatorArr = new Array();
validatorArr.push(validateName);
validatorArr.push(validateSurname);
validatorArr.push(validateEmail);
saveData.url = (this.parentApplication).localURL+'register.php';
}
protected function clearData():void
{
userFirstName.text = "";
userLastName.text = "";
userEmail.text = "";
termsCheck.selected = false;
premierLeagueCheck.selected = false;
clubCheck.selected = false;
barclaysCheck.selected = false;
}
protected function exit(event:Event=null):void
{
trace("*** INIT USERFORM ***");
}
protected function submit(event:MouseEvent):void
{
var validatorErrorArray:Array = Validator.validateAll(validatorArr);
var isValidForm:Boolean = validatorErrorArray.length == 0;
if (isValidForm)
{
//send data
saveData.send({urn: settings.userData.urn,
firstname:userFirstName.text,
lastname: userLastName.text,
email: userEmail.text,
optInTerms: termsCheck.selected ? 1 : 0,
optInPremier: premierLeagueCheck.selected ? 1 : 0,
optInClub:premierLeagueCheck.selected ? 1 : 0,
optInBarclays:barclaysCheck.selected ? 1 : 0
});
// save();
}
}
protected function clearForm():void
{
userEmail.text="";
userEmail.errorString="";
userFirstName.text="";
userFirstName.errorString="";
userLastName.text="";
userLastName.errorString="";
termsCheck.selected = false;
premierLeagueCheck.selected = false;
clubCheck.selected = false;
barclaysCheck.selected = false;
}
protected function save(e:ResultEvent=null):void
{
// -> Do we need to send an isRegistered? We should divide Facebook and Direct registration perhaps
if(e.result)
{
if (e.result.result=="OK")
{
this.parentApplication.dispatchEvent( new UserEvent(UserEvent.REGISTERED, "classic"));
this.parentApplication.dispatchEvent( new ViewEvent( ViewEvent.LOCATION_SELECT_GAME_TEAM, {type: "GAME" } ));
} else
{
this.parentApplication.dispatchEvent(new KioskError(KioskError.ERROR, e.result.message.toString(), "COMMUNICATION ERROR"));
}
}else
{
this.parentApplication.dispatchEvent( new UserEvent(UserEvent.REGISTERED, "classic"));
this.parentApplication.dispatchEvent( new ViewEvent( ViewEvent.LOCATION_REGISTRATION_COMPLETE ) );
//this.parentApplication.dispatchEvent(new KioskError(KioskError.ERROR, "THE SERVER SENT AN EMPTY RESPONSE", "COMMUNICATION ERROR"));
}
}
protected function error(e:FaultEvent):void
{
this.parentApplication.dispatchEvent(new KioskError(KioskError.ERROR, e.fault.message.toString(), "COMMUNICATION ERROR"));
}
protected function tandcd_clickHandler(event:MouseEvent):void
{
this.parentApplication.dispatchEvent(new KioskEvent(KioskEvent.TERMS_NOTIFY));
}
protected function keyHandler(event : KeyboardEvent):void
{
if(event.keyCode == 13)
{
if(stage)
{
stage.focus = null;
}
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:StringValidator id="validateName"
source="{userFirstName}"
property="text"
minLength="2">
</mx:StringValidator>
<mx:StringValidator id="validateSurname"
source="{userLastName}"
property="text"
minLength="2">
</mx:StringValidator>
<mx:EmailValidator id="validateEmail"
source="{userEmail}"
property="text">
</mx:EmailValidator>
<s:HTTPService id="saveData" resultFormat="flashvars" method="POST" url="{(this.parentApplication).localURL+'register.php'}" result="save(event)" fault="error(event)" />
</fx:Declarations>
<s:Form width="100%" id="userform" horizontalCenter="105" verticalCenter="-10">
<s:layout>
<s:FormLayout/>
</s:layout>
<s:FormHeading id="frontMessage" label="PLEASE ENTER YOUR DETAILS" />
<s:Spacer height="30" />
<s:FormItem label="First Name:" skinClass="skins.BarclaysFormItem" >
<s:TextInput id="userFirstName" width="500" height="54" skinClass="skins.BarclaysTextInput" keyDown="keyHandler(event)"/>
</s:FormItem>
<s:FormItem label="Last Name:" skinClass="skins.BarclaysFormItem">
<s:TextInput id="userLastName" width="500" height="54" skinClass="skins.BarclaysTextInput" keyDown="keyHandler(event)"/>
</s:FormItem>
<s:FormItem label="Email address:" skinClass="skins.BarclaysFormItem">
<s:TextInput id="userEmail" width="500" height="54" skinClass="skins.BarclaysTextInput" keyDown="keyHandler(event)"/>
</s:FormItem>
<s:Spacer height="30"/>
<s:HGroup width="417">
<s:CheckBox id="termsCheck" width="145" styleName="tcaccept" label="ACCEPT " skinClass="skins.BarclaysCheckBox" />
<s:Label color="0x00AEEF" styleName="tclink" paddingTop="4" buttonMode="true" text="TERMS AND CONDITIONS" click="tandcd_clickHandler(event)" />
</s:HGroup>
<s:Spacer height="20"/>
<s:CheckBox id="premierLeagueCheck" width="145" styleName="tcaccept" label="I WOULD LIKE TO RECEIVE INFORMATION FROM THE PREMIER LEAGUE " skinClass="skins.BarclaysCheckBox" />
<s:Spacer height="20"/>
<s:CheckBox id="clubCheck" width="145" styleName="tcaccept" label="I WOULD LIKE TO RECEIVE INFORMATION FROM MY CLUB " skinClass="skins.BarclaysCheckBox" />
<s:Spacer height="20"/>
<s:CheckBox id="barclaysCheck" width="145" styleName="tcaccept" label="I WOULD LIKE TO RECEIVE INFORMATION FROM BARCLAYS " skinClass="skins.BarclaysCheckBox" />
<s:Spacer height="30"/>
<s:HGroup width="100%" horizontalAlign="center">
<s:Button label="CANCEL" click="clearForm()" skinClass="skins.barclaysButton"/>
<s:Spacer width="50" />
<s:Button label="SUBMIT" click="submit(event)" skinClass="skins.barclaysButton"/>
</s:HGroup>
</s:Form>
</s:Group>