registerView.as 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. import com.adobe.crypto.SHA256;
  2. import com.hurlant.math.bi_internal;
  3. import com.imt.intimamedia.events.user.RegisterEvent;
  4. import com.imt.intimamedia.events.user.SearchCitiesEvent;
  5. import com.imt.intimamedia.events.user.SearchZipCodesEvent;
  6. import com.imt.intimamedia.events.user.TermsEvent;
  7. import com.imt.intimamedia.events.user.ValidateAccountEvent;
  8. import com.imt.intimamedia.helpers.FormatString;
  9. import com.imt.intimamedia.helpers.TextInputWithSkin;
  10. import com.imt.intimamedia.helpers.WindowShadeButton;
  11. import com.imt.intimamedia.model.ApplicationModelLocator;
  12. import com.imt.intimamedia.views.common.ImtToaster;
  13. import com.imt.intimamedia.views.general.register.ApplicationDatabaseTermsPopUp;
  14. import com.imt.intimamedia.views.general.register.ApplicationTermsPopUp;
  15. import com.imt.intimamedia.vo.HospitalVo;
  16. import com.imt.intimamedia.vo.PersonVo;
  17. import com.imt.intimamedia.vo.ProbeVo;
  18. import com.imt.intimamedia.vo.UltraSoundScannerVo;
  19. import com.imt.intimamedia.vo.UserVo;
  20. import flash.events.Event;
  21. import flash.events.MouseEvent;
  22. import flash.net.URLLoader;
  23. import flash.net.URLRequest;
  24. import flash.net.URLStream;
  25. import mx.automation.delegates.controls.TextInputAutomationImpl;
  26. import mx.collections.ArrayCollection;
  27. import mx.containers.FormItem;
  28. import mx.controls.Alert;
  29. import mx.controls.ComboBox;
  30. import mx.controls.Menu;
  31. import mx.core.Application;
  32. import mx.events.ListEvent;
  33. import mx.events.MenuEvent;
  34. import mx.events.ToolTipEvent;
  35. import mx.events.ValidationResultEvent;
  36. import mx.managers.PopUpManager;
  37. import mx.resources.ResourceManager;
  38. import mx.utils.ObjectUtil;
  39. import mx.validators.Validator;
  40. import flash.net.navigateToURL;
  41. [Bindable]
  42. private var _model : ApplicationModelLocator = ApplicationModelLocator.getInstance();
  43. [Bindable]
  44. private var _maxYear : int = new Date().fullYear;
  45. [Bindable]
  46. private var _otherActivityActive : Boolean = false;
  47. private var _updateAddressManually : Boolean = false;
  48. private var _conditionsAreRead : Boolean = false;
  49. [Bindable]
  50. private var _partOneValid : Boolean = false;
  51. [Bindable]
  52. private var _partTwoValid : Boolean = false;
  53. [Bindable]
  54. private var _partThreeValid : Boolean = false;
  55. private var _terms : URLLoader;
  56. private var _idTermsAccepted : int = 0;
  57. private var _countrySelected : String = "";
  58. private function actionOnZonesFromErrors( event : Event, zone : String ) : void
  59. {
  60. /*switch( zone )
  61. {
  62. case "ZoneOne":
  63. ids.opened = !ids.opened;
  64. if( ids.opened )
  65. {
  66. organization.opened = false;
  67. user.opened = false;
  68. scanner.opened = false;
  69. vatContainer.opened = false;
  70. mathContainer.opened = false;
  71. }
  72. break;
  73. case "ZoneTwo":
  74. organization.opened = !organization.opened;
  75. user.opened = !user.opened;
  76. scanner.opened = !scanner.opened;
  77. if( organization.opened )
  78. {
  79. ids.opened = false;
  80. vatContainer.opened = false;
  81. mathContainer.opened = false;
  82. }
  83. break;
  84. }*/
  85. }
  86. private function actionOnZones( event : Event, zone : String ) : void
  87. {
  88. /*if( event.target is WindowShadeButton )
  89. {
  90. switch( zone )
  91. {
  92. case "ZoneOne":
  93. ids.opened = !ids.opened;
  94. if( ids.opened )
  95. {
  96. organization.opened = false;
  97. user.opened = false;
  98. scanner.opened = false;
  99. vatContainer.opened = false;
  100. mathContainer.opened = false;
  101. }
  102. break;
  103. case "ZoneTwo":
  104. organization.opened = !organization.opened;
  105. user.opened = !user.opened;
  106. scanner.opened = !scanner.opened;
  107. if( organization.opened )
  108. {
  109. ids.opened = false;
  110. vatContainer.opened = false;
  111. mathContainer.opened = false;
  112. }
  113. break;
  114. case "ZoneThree":
  115. vatContainer.opened = !vatContainer.opened;
  116. mathContainer.opened = !mathContainer.opened;
  117. if( vatContainer.opened )
  118. {
  119. ids.opened = false;
  120. organization.opened = false;
  121. user.opened = false;
  122. scanner.opened = false;
  123. }
  124. break;
  125. }
  126. }*/
  127. }
  128. private function displayShippingAddress( selected : Boolean ) : void
  129. {
  130. _updateAddressManually = selected;
  131. shippingAddressTextInput.text = "";
  132. shippingAddressLabel.visible = selected;
  133. shippingAddressLabel.includeInLayout = selected;
  134. copyAddress( invoiceAddressTextInput.text );
  135. }
  136. private function copyAddress( address : String ) : void
  137. {
  138. if( !_updateAddressManually )
  139. shippingAddressTextInput.text = address;
  140. }
  141. private function copyCountry( ) : void
  142. {
  143. if( countryComboBox.selectedIndex != -1 )
  144. _countrySelected = countryComboBox.selectedItem.code;
  145. }
  146. private function searchCityWithZipCode() : void
  147. {
  148. if( countryComboBox.selectedIndex != -1 )
  149. {
  150. _model.cities = new ArrayCollection();
  151. new SearchCitiesEvent( zipCodeTextInput.text, countryComboBox.selectedItem.code ).dispatch();
  152. var menuZipCode : Menu = Menu.createMenu( null, _model.cities, false );
  153. menuZipCode.addEventListener( MenuEvent.ITEM_CLICK, citySelected );
  154. menuZipCode.width = cityTextInput.width;
  155. menuZipCode.show( 258, 307 );
  156. } else {
  157. var toastMessage : ImtToaster = new ImtToaster();
  158. toastMessage.titleMessage = ResourceManager.getInstance().getString( 'labels', 'register.searchImpossibleTitle' );
  159. toastMessage.message = ResourceManager.getInstance().getString( 'labels', 'register.searchImpossibleZip' );
  160. toastMessage.level = ImtToaster.WARNING;
  161. ApplicationModelLocator.getInstance().toaster.toast( toastMessage );
  162. }
  163. }
  164. private function searchZipCodeWithCity() : void
  165. {
  166. if( countryComboBox.selectedIndex != -1 )
  167. {
  168. _model.zipCodes = new ArrayCollection();
  169. new SearchZipCodesEvent( cityTextInput.text, countryComboBox.selectedItem.code ).dispatch();
  170. var menuZipCode : Menu = Menu.createMenu( null, _model.zipCodes, false );
  171. menuZipCode.addEventListener( MenuEvent.ITEM_CLICK, zipCodeSelected );
  172. menuZipCode.width = cityTextInput.width;
  173. menuZipCode.show( 258, 279 );
  174. } else {
  175. var toastMessage : ImtToaster = new ImtToaster();
  176. toastMessage.titleMessage = ResourceManager.getInstance().getString( 'labels', 'register.searchImpossibleTitle' );
  177. toastMessage.message = ResourceManager.getInstance().getString( 'labels', 'register.searchImpossibleCity' );
  178. toastMessage.level = ImtToaster.WARNING;
  179. ApplicationModelLocator.getInstance().toaster.toast( toastMessage );
  180. }
  181. }
  182. private function zipCodeSelected( event : MenuEvent ) : void
  183. {
  184. zipCodeTextInput.text = event.item.toString();
  185. }
  186. private function citySelected( event : MenuEvent ) : void
  187. {
  188. cityTextInput.text = event.item.toString();
  189. }
  190. private function changeQuestion( event : ListEvent, comboBox : ComboBox ) : void
  191. {
  192. var newSelection : Object = ( event.currentTarget as ComboBox ).selectedItem;
  193. var otherListSelection : Object = comboBox.selectedItem;
  194. var index : int = 0;
  195. comboBox.dataProvider = ObjectUtil.copy( _model.questions ) as ArrayCollection;
  196. for( index = 0; index < comboBox.dataProvider.length; index++ )
  197. {
  198. if( comboBox.dataProvider[ index ].code == newSelection.code )
  199. {
  200. ( comboBox.dataProvider as ArrayCollection ).removeItemAt( index );
  201. break;
  202. }
  203. }
  204. for( index = 0; index < comboBox.dataProvider.length; index++ )
  205. {
  206. if( otherListSelection != null && comboBox.dataProvider[ index ].code == otherListSelection.code )
  207. {
  208. comboBox.selectedIndex = index;
  209. break;
  210. }
  211. }
  212. }
  213. private function onChangeActivity( event : ListEvent ) : void
  214. {
  215. if( event.currentTarget.selectedItem.code == "S09" )
  216. _otherActivityActive = true;
  217. else
  218. _otherActivityActive = false;
  219. }
  220. private function onTermsAndConditions() : void
  221. {
  222. _conditionsAreRead = true;
  223. /*if (_countrySelected == "")
  224. {
  225. var toastMessage : IMTToaster = new IMTToaster();
  226. toastMessage.titleMessage = ResourceManager.getInstance().getString( 'labels', 'warning.use' );
  227. toastMessage.message = ResourceManager.getInstance().getString( 'labels', 'register.noCountrySelected' );
  228. toastMessage.level = IMTToaster.WARNING;
  229. ApplicationModelLocator.getInstance().toaster.toast( toastMessage );
  230. }
  231. else*/
  232. new TermsEvent(_model.connectedUser, ResourceManager.getInstance().getString('labels', 'lang'), this).dispatch();
  233. }
  234. public function displayConditions( idterms : int, urlterms : String ) : void
  235. {
  236. _conditionsAreRead = true;
  237. _terms = new URLLoader();
  238. _idTermsAccepted = idterms;
  239. _terms.addEventListener(Event.COMPLETE, onReadConditionsCompleteHandler);
  240. /*_terms.addEventListener(Event.OPEN, openHandler);
  241. _terms.addEventListener(ProgressEvent.PROGRESS, progressHandler);
  242. _terms.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
  243. _terms.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
  244. _terms.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);*/
  245. _terms.load(new URLRequest(urlterms));
  246. }
  247. private function onReadConditionsCompleteHandler(event:Event) : void
  248. {
  249. var loader:URLLoader = URLLoader(event.target);
  250. var _applicationTermsPopUp : ApplicationTermsPopUp = new ApplicationTermsPopUp();
  251. _applicationTermsPopUp.setTermsAndConditions(loader.data);
  252. PopUpManager.addPopUp( _applicationTermsPopUp, this, true );
  253. PopUpManager.centerPopUp( _applicationTermsPopUp );
  254. }
  255. private function onReadDatabase( event : Event) : void
  256. {
  257. var _applicationDatabaseTermsPopUp : ApplicationDatabaseTermsPopUp = new ApplicationDatabaseTermsPopUp();
  258. PopUpManager.addPopUp( _applicationDatabaseTermsPopUp, this, true );
  259. PopUpManager.centerPopUp( _applicationDatabaseTermsPopUp );
  260. }
  261. // Affichage du fichier Pdf de la licence
  262. private function onReadLicence( event : Event) : void
  263. {
  264. if (licenceAgreeCheckBox.selected == true)
  265. {
  266. _conditionsAreRead = true;
  267. var req : URLRequest = new URLRequest("http://www.ipsocloud.com/151001IMT_CLOUDSoftware_License_Agreement.pdf");
  268. navigateToURL( req, "_blank" );
  269. }
  270. }
  271. private function checkTextInputEntry (textInputWithSkin : *, formItem : FormItem) : void
  272. {
  273. if (textInputWithSkin.errorString)
  274. {
  275. formItem.setStyle("color", "#7c0b13");
  276. formItem.setStyle("fontWeight", "bold");
  277. }
  278. else
  279. {
  280. formItem.setStyle("color", "#555557");
  281. formItem.setStyle("fontWeight", "normal");
  282. }
  283. }
  284. private function checkComboBoxEntry (comboBox : ComboBox, formItem : FormItem) : void
  285. {
  286. if (!comboBox.selectedItem)
  287. {
  288. formItem.setStyle("color", "#7c0b13");
  289. formItem.setStyle("fontWeight", "bold");
  290. }
  291. else
  292. {
  293. formItem.setStyle("color", "#555557");
  294. formItem.setStyle("fontWeight", "normal");
  295. }
  296. }
  297. private function onRegister( event : * ) : void
  298. {
  299. var toastMessage : ImtToaster = new ImtToaster();
  300. var validatorsPartOne : Array = [ mailValidator, passwordValidator, confirmPasswordValidator, answerOneValidator,
  301. answerTwoValidator, questionOneValidator, questionTwoValidator ];
  302. var validatorsPartTwo : Array = [ countryValidator, phoneCenterValidator, lastNameValidator, firstNameValidator,
  303. phoneValidator, activityValidator, cityValidator, zipCodeValidator,
  304. invoiceAddressValidator, shippingAddressValidator, hospitalValidator,
  305. frequencyValidator, brandValidator ];
  306. var validatorsPartThree : Array = [ ];
  307. var validators : Array = [ mailValidator, passwordValidator, confirmPasswordValidator, answerOneValidator,
  308. answerTwoValidator, questionOneValidator, questionTwoValidator, countryValidator,
  309. phoneCenterValidator, lastNameValidator, firstNameValidator, phoneValidator,
  310. activityValidator,cityValidator, zipCodeValidator,
  311. invoiceAddressValidator, shippingAddressValidator, hospitalValidator,
  312. frequencyValidator, brandValidator
  313. ];
  314. if( _otherActivityActive )
  315. {
  316. validatorsPartTwo.push( otherActivityValidator );
  317. validators.push( otherActivityValidator );
  318. }
  319. var validatorsError : Array = Validator.validateAll( validators );
  320. var validatorsPartOneError : Array = Validator.validateAll( validatorsPartOne );
  321. var validatorsPartTwoError : Array = Validator.validateAll( validatorsPartTwo );
  322. var validatorsPartThreeError : Array = Validator.validateAll( validatorsPartThree );
  323. _partOneValid = true;
  324. _partTwoValid = true;
  325. _partThreeValid = true;
  326. if( validatorsPartOneError.length != 0 )
  327. partOne.enabled = true;
  328. else
  329. partOne.enabled = false;
  330. if( validatorsPartTwoError.length != 0 )
  331. partTwo.enabled = true;
  332. else
  333. partTwo.enabled = false;
  334. if( validatorsPartThreeError.length != 0 )
  335. partThree.enabled = true;
  336. else
  337. partThree.enabled = false;
  338. var textInputWithSkinList : Array = [ mailTextInput, passwordTextInput, confirmPasswordTextInput, answerOneTextInput,
  339. answerTwoTextInput, hospitalTextInput, invoiceAddressTextInput, shippingAddressTextInput,
  340. cityTextInput, zipCodeTextInput, phoneCenterTextInput, lastNameTextInput, firstNameTextInput, phoneTextInput,
  341. otherActivityTextInput, brandTextInput ];
  342. var textInputLabel : Array = [ mailLabel, passwordLabel, confirmPasswordLabel, answerOneLabel,
  343. answerTwoLabel, hospitalLabel, invoiceAddressLabel, shippingAddressLabel,
  344. cityLabel, zipCodeLabel, phoneCenterLabel, lastNameLabel, firstNameLabel, phoneLabel,
  345. otherActivityLabel, brandLabel ];
  346. var comboBoxList : Array = [ questionOneComboBox, questionTwoComboBox, countryComboBox, activityComboBox ];
  347. var comboBoxLabel : Array = [ questionOneLabel, questionTwoLabel, countryLabel, activityLabel ];
  348. for (var i : int = 0; i < textInputWithSkinList.length; i++)
  349. checkTextInputEntry(textInputWithSkinList[i], textInputLabel[i]);
  350. for (i = 0; i < comboBoxList.length; i++)
  351. checkComboBoxEntry(comboBoxList[i], comboBoxLabel[i]);
  352. if( validatorsError.length != 0 )
  353. {
  354. toastMessage = new ImtToaster();
  355. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'error.allFieldsTitle');
  356. toastMessage.message = ResourceManager.getInstance().getString('labels', 'error.allFields');
  357. toastMessage.timeToLive = 10;
  358. toastMessage.level = ImtToaster.WARNING;
  359. _model.toaster.toast( toastMessage );
  360. }
  361. else if ((licenceAgreeCheckBox.selected == false) || (physicianAgreeCheckBox.selected == false))
  362. {
  363. toastMessage = new ImtToaster();
  364. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'error.allFieldsTitle');
  365. toastMessage.message = ResourceManager.getInstance().getString('labels', 'error.checkAgreeUnchecked');
  366. toastMessage.timeToLive = 10;
  367. toastMessage.level = ImtToaster.WARNING;
  368. _model.toaster.toast( toastMessage );
  369. }
  370. else
  371. {
  372. if( !_conditionsAreRead )
  373. {
  374. toastMessage = new ImtToaster();
  375. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'termsOfUse');
  376. toastMessage.message = ResourceManager.getInstance().getString('labels', 'error.conditionNotRead');
  377. toastMessage.timeToLive = 7;
  378. toastMessage.level = ImtToaster.WARNING;
  379. _model.toaster.toast( toastMessage );
  380. }
  381. else {
  382. /**
  383. * On enleve les caractère Espace, virgule, tiret, point
  384. * et on met la réponse en minuscule.
  385. */
  386. FormatString.formatWithoutSpace( answerOneTextInput.text );
  387. FormatString.formatWithoutSpace( answerTwoTextInput.text );
  388. var newProbeVo : ProbeVo = new ProbeVo();
  389. newProbeVo.frequency = frequencyNumericStepper.value
  390. var newUltraSoundScannerVo : UltraSoundScannerVo = new UltraSoundScannerVo();
  391. newUltraSoundScannerVo.name = nameTextInput.text;
  392. newUltraSoundScannerVo.brand = brandTextInput.text;
  393. newUltraSoundScannerVo.type = typeTextInput.text;
  394. newUltraSoundScannerVo.age = new Date(ageNumericStepper.value);
  395. newUltraSoundScannerVo.probes.push( newProbeVo );
  396. var newHospitalVo : HospitalVo = new HospitalVo();
  397. newHospitalVo.name = hospitalTextInput.text;
  398. newHospitalVo.addressInvoicing = invoiceAddressTextInput.text;
  399. newHospitalVo.addressShipping = shippingAddressTextInput.text;
  400. newHospitalVo.city = cityTextInput.text;
  401. newHospitalVo.zipCode = zipCodeTextInput.text;
  402. newHospitalVo.country = countryComboBox.selectedItem.code;
  403. newHospitalVo.phone = phoneCenterTextInput.text;
  404. newHospitalVo.fax = faxCenterTextInput.text;
  405. var newPersonVo : PersonVo = new PersonVo();
  406. newPersonVo.lastName = lastNameTextInput.text;
  407. newPersonVo.firstName = firstNameTextInput.text;
  408. newPersonVo.phone = phoneTextInput.text;
  409. newPersonVo.fax = faxTextInput.text;
  410. var newUserVo : UserVo = new UserVo();
  411. newUserVo.hospital = newHospitalVo;
  412. newUserVo.help = true;
  413. newUserVo.ultraSoundScanner = newUltraSoundScannerVo;
  414. newUserVo.person = newPersonVo;
  415. newUserVo.login = mailTextInput.text;
  416. newUserVo.password = SHA256.hash( "INTim@meDia2011" + passwordTextInput.text );
  417. newUserVo.questionOne = questionOneComboBox.selectedItem.code;
  418. newUserVo.answerOne = answerOneTextInput.text;
  419. newUserVo.questionTwo = questionTwoComboBox.selectedItem.code;
  420. newUserVo.answerTwo = answerTwoTextInput.text;
  421. newUserVo.buyer = buyer.selected;
  422. newUserVo.conditions = _idTermsAccepted;
  423. if ( activityComboBox.selectedItem.code == 9 )
  424. newPersonVo.activity = otherActivityTextInput.text;
  425. else
  426. newPersonVo.activity = activityComboBox.selectedLabel;
  427. if ( dataBaseAgreeCheckBox.selected )
  428. newUserVo.database = 1;
  429. else
  430. newUserVo.database = 0;
  431. registerButton.enabled = false;
  432. new RegisterEvent( newUserVo, ResourceManager.getInstance().getString('labels', 'language'), this ).dispatch();
  433. }
  434. }
  435. }
  436. public function returnToHome(uid : String) : void
  437. {
  438. registerButton.enabled = true;
  439. clearRegisterForm();
  440. this.parentDocument.selectedIndex = 0;
  441. var userVo : UserVo = new UserVo();
  442. userVo.id = int(uid);
  443. }
  444. private function resetLabels() : void
  445. {
  446. var formItemList : Array = [ mailTextInput, passwordTextInput, confirmPasswordTextInput, answerOneTextInput,
  447. answerTwoTextInput, hospitalTextInput, invoiceAddressTextInput, shippingAddressTextInput,
  448. cityTextInput, zipCodeTextInput, questionOneComboBox, questionTwoComboBox, countryComboBox,
  449. phoneCenterTextInput, lastNameTextInput, firstNameTextInput, phoneTextInput, activityComboBox,
  450. otherActivityTextInput, brandTextInput ];
  451. var formLabelList : Array = [ mailLabel, passwordLabel, confirmPasswordLabel, answerOneLabel,
  452. answerTwoLabel, hospitalLabel, invoiceAddressLabel, shippingAddressLabel,
  453. cityLabel, zipCodeLabel, questionOneLabel, questionTwoLabel, countryLabel,
  454. phoneCenterLabel, lastNameLabel, firstNameLabel, phoneLabel, activityLabel,
  455. otherActivityLabel, brandLabel ];
  456. for (var i : int = 0; i < formItemList.length; i++)
  457. {
  458. formLabelList[i].setStyle("color", "#555557");
  459. formLabelList[i].setStyle("fontWeight", "normal");
  460. formItemList[i].errorString = "";
  461. }
  462. }
  463. public function clearRegisterForm() : void
  464. {
  465. mailValidator.enabled = false;
  466. passwordValidator.enabled = false;
  467. confirmPasswordValidator.enabled = false;
  468. answerOneValidator.enabled = false;
  469. answerTwoValidator.enabled = false;
  470. hospitalValidator.enabled = false;
  471. invoiceAddressValidator.enabled = false;
  472. shippingAddressValidator.enabled = false;
  473. cityValidator.enabled = false;
  474. zipCodeValidator.enabled = false;
  475. questionOneValidator.enabled = false;
  476. questionTwoValidator.enabled = false;
  477. countryValidator.enabled = false;
  478. phoneCenterValidator.enabled = false;
  479. lastNameValidator.enabled = false;
  480. firstNameValidator.enabled = false;
  481. phoneValidator.enabled = false;
  482. activityValidator.enabled = false;
  483. brandValidator.enabled = false;
  484. frequencyValidator.enabled = false;
  485. otherActivityValidator.enabled = false;
  486. licenceAgreeValidator.enabled = false;
  487. physicianAgreeValidator.enabled = false;
  488. mailTextInput.text = "";
  489. passwordTextInput.text = "";
  490. confirmPasswordTextInput.text = "";
  491. questionOneComboBox.selectedIndex = -1;
  492. questionOneComboBox.prompt = ResourceManager.getInstance().getString('labels', 'choose');
  493. questionTwoComboBox.selectedIndex = -1;
  494. questionTwoComboBox.prompt = ResourceManager.getInstance().getString('labels', 'choose');
  495. answerOneTextInput.text = "";
  496. answerTwoTextInput.text = "";
  497. hospitalTextInput.text = "";
  498. invoiceAddressTextInput.text = "";
  499. shippingAddressTextInput.text = "";
  500. cityTextInput.text = "";
  501. zipCodeTextInput.text = "";
  502. countryComboBox.selectedIndex = -1;
  503. phoneCenterTextInput.text = "";
  504. faxCenterTextInput.text = "";
  505. lastNameTextInput.text = "";
  506. firstNameTextInput.text = "";
  507. phoneTextInput.text = "";
  508. faxTextInput.text = "";
  509. activityComboBox.selectedIndex = -1;
  510. activityComboBox.prompt = ResourceManager.getInstance().getString('labels', 'chooseActivity');
  511. brandTextInput.text = "";
  512. typeTextInput.text = "";
  513. frequencyNumericStepper.value = 0;
  514. ageNumericStepper.value = 0;
  515. otherActivityTextInput.text = "";
  516. licenceAgreeCheckBox.selected = false;
  517. dataBaseAgreeCheckBox.selected = false;
  518. physicianAgreeCheckBox.selected = false;
  519. mailValidator.enabled = true;
  520. passwordValidator.enabled = true;
  521. confirmPasswordValidator.enabled = true;
  522. answerOneValidator.enabled = true;
  523. answerTwoValidator.enabled = true;
  524. hospitalValidator.enabled = true;
  525. invoiceAddressValidator.enabled = true;
  526. shippingAddressValidator.enabled = true;
  527. cityValidator.enabled = true;
  528. zipCodeValidator.enabled = true;
  529. questionOneValidator.enabled = true;
  530. questionTwoValidator.enabled = true;
  531. countryValidator.enabled = true;
  532. phoneCenterValidator.enabled = true;
  533. lastNameValidator.enabled = true;
  534. firstNameValidator.enabled = true;
  535. phoneValidator.enabled = true;
  536. activityValidator.enabled = true;
  537. brandValidator.enabled = true;
  538. frequencyValidator.enabled = true;
  539. otherActivityValidator.enabled = true;
  540. licenceAgreeValidator.enabled = true;
  541. physicianAgreeValidator.enabled = true;
  542. resetLabels();
  543. }
  544. private function setFieldError() : void
  545. {
  546. mailValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  547. mailValidator.invalidCharError = ResourceManager.getInstance().getString('labels', 'errorField');
  548. mailValidator.invalidDomainError = ResourceManager.getInstance().getString('labels', 'errorField');
  549. mailValidator.invalidIPDomainError = ResourceManager.getInstance().getString('labels', 'errorField');
  550. mailValidator.invalidPeriodsInDomainError = ResourceManager.getInstance().getString('labels', 'errorField');
  551. mailValidator.missingAtSignError = ResourceManager.getInstance().getString('labels', 'errorField');
  552. mailValidator.missingPeriodInDomainError = ResourceManager.getInstance().getString('labels', 'errorField');
  553. mailValidator.missingUsernameError = ResourceManager.getInstance().getString('labels', 'errorField');
  554. mailValidator.tooManyAtSignsError = ResourceManager.getInstance().getString('labels', 'errorField');
  555. passwordValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  556. confirmPasswordValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  557. answerOneValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  558. answerTwoValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  559. hospitalValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  560. invoiceAddressValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  561. shippingAddressValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  562. cityValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  563. zipCodeValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  564. questionOneValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  565. questionTwoValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  566. countryValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  567. phoneCenterValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  568. lastNameValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  569. firstNameValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  570. phoneValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  571. activityValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  572. brandValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  573. frequencyValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  574. otherActivityValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  575. licenceAgreeValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'checkLicence');
  576. physicianAgreeValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'checkAgreePhysician');
  577. }
  578. private function initListeners() : void
  579. {
  580. setFieldError();
  581. mailValidator.addEventListener(ValidationResultEvent.VALID, mailValidatorHandler);
  582. passwordValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  583. confirmPasswordValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  584. answerOneValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  585. answerTwoValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  586. hospitalValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  587. invoiceAddressValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  588. shippingAddressValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  589. cityValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  590. zipCodeValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  591. questionOneValidator.addEventListener(ValidationResultEvent.VALID, numberValidatorHandler);
  592. questionTwoValidator.addEventListener(ValidationResultEvent.VALID, numberValidatorHandler);
  593. countryValidator.addEventListener(ValidationResultEvent.VALID, numberValidatorHandler);
  594. phoneCenterValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  595. lastNameValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  596. firstNameValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  597. phoneValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  598. activityValidator.addEventListener(ValidationResultEvent.VALID, numberValidatorHandler);
  599. brandValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  600. frequencyValidator.addEventListener(ValidationResultEvent.VALID, numberValidatorHandler);
  601. otherActivityValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  602. licenceAgreeValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  603. physicianAgreeValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  604. }
  605. public function updateErrorStrings() : void
  606. {
  607. setFieldError();
  608. if (mailTextInput.errorString)
  609. mailTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  610. if (passwordTextInput.errorString)
  611. passwordTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  612. if (confirmPasswordTextInput.errorString)
  613. confirmPasswordTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  614. if (answerOneTextInput.errorString)
  615. answerOneTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  616. if (answerTwoTextInput.errorString)
  617. answerTwoTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  618. if (hospitalTextInput.errorString)
  619. hospitalTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  620. if (invoiceAddressTextInput.errorString)
  621. invoiceAddressTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  622. if (shippingAddressTextInput.errorString)
  623. shippingAddressTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  624. if (cityTextInput.errorString)
  625. cityTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  626. if (zipCodeTextInput.errorString)
  627. zipCodeTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  628. if (questionOneComboBox.errorString)
  629. questionOneComboBox.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  630. if (questionTwoComboBox.errorString)
  631. questionTwoComboBox.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  632. if (countryComboBox.errorString)
  633. countryComboBox.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  634. if (phoneCenterTextInput.errorString)
  635. phoneCenterTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  636. if (lastNameTextInput.errorString)
  637. lastNameTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  638. if (firstNameTextInput.errorString)
  639. firstNameTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  640. if (phoneTextInput.errorString)
  641. phoneTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  642. if (activityComboBox.errorString)
  643. activityComboBox.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  644. if (otherActivityTextInput.errorString)
  645. otherActivityTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  646. if (brandTextInput.errorString)
  647. brandTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  648. if (frequencyNumericStepper.errorString)
  649. frequencyNumericStepper.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  650. if (licenceAgreeCheckBox.errorString)
  651. licenceAgreeCheckBox.errorString = ResourceManager.getInstance().getString('labels', 'checkLicence');
  652. if (physicianAgreeCheckBox.errorString)
  653. physicianAgreeCheckBox.errorString = ResourceManager.getInstance().getString('labels', 'checkAgreePhysician');
  654. }
  655. private function mailValidatorHandler(event : ValidationResultEvent) : void
  656. {
  657. if (mailTextInput.errorString)
  658. mailTextInput.errorString = null;
  659. }
  660. private function stringValidatorHandler(event : ValidationResultEvent) : void
  661. {
  662. if (event.currentTarget.source.errorString)
  663. event.currentTarget.source.errorString = null;
  664. }
  665. private function numberValidatorHandler(event : ValidationResultEvent) : void
  666. {
  667. if (event.currentTarget.source.errorString)
  668. event.currentTarget.source.errorString = null;
  669. }