import com.imt.intimamedia.events.user.ExportDataEvent; import com.imt.intimamedia.events.user.SearchCitiesEvent; import com.imt.intimamedia.events.user.SearchZipCodesEvent; import com.imt.intimamedia.events.user.TermsAgreedEvent; import com.imt.intimamedia.events.user.UpdateUserEvent; import com.imt.intimamedia.helpers.ComboBoxHelper; import com.imt.intimamedia.helpers.WindowShadeButton; import com.imt.intimamedia.model.ApplicationModelLocator; import com.imt.intimamedia.views.common.ImtToaster; import com.imt.intimamedia.views.general.register.ApplicationTermsPopUp; import com.imt.intimamedia.vo.HospitalVo; import com.imt.intimamedia.vo.PersonVo; import com.imt.intimamedia.vo.ProbeVo; import com.imt.intimamedia.vo.UltraSoundScannerVo; import com.imt.intimamedia.vo.UserVo; import flash.events.Event; import flash.events.MouseEvent; import flash.net.URLLoader; import flash.net.URLRequest; import flash.net.URLStream; import mx.collections.ArrayCollection; import mx.containers.FormItem; import mx.controls.Alert; import mx.controls.ComboBox; import mx.controls.Menu; import mx.events.ListEvent; import mx.events.MenuEvent; import mx.events.ValidationResultEvent; import mx.managers.PopUpManager; import mx.resources.ResourceManager; import mx.utils.ObjectUtil; import mx.validators.Validator; import org.alivepdf.display.Display; [Bindable] private var _model : ApplicationModelLocator = ApplicationModelLocator.getInstance(); [Bindable] private var _maxYear : int = new Date().fullYear; [Bindable] private var _otherActivityActive : Boolean = false; private var _updateAddressManually : Boolean = false; private var _conditionsAreRead : Boolean = false; [Bindable] private var _partOneValid : Boolean = false; [Bindable] private var _partTwoValid : Boolean = false; [Bindable] private var _partThreeValid : Boolean = false; private function showView() : void { countryComboBox.selectedIndex = ComboBoxHelper.findIndex(_model.connectedUser.hospital.country, _model.countries ); } private function actionOnZonesFromErrors( event : Event, zone : String ) : void { switch( zone ) { case "ZoneOne": organization.opened = false; user.opened = false; scanner.opened = false; vatContainer.opened = false; mathContainer.opened = false; break; case "ZoneTwo": organization.opened = !organization.opened; user.opened = !user.opened; scanner.opened = !scanner.opened; if( organization.opened ) { vatContainer.opened = false; mathContainer.opened = false; } break; } } private function actionOnZones( event : Event, zone : String ) : void { if( event.target is WindowShadeButton ) { switch( zone ) { case "ZoneOne": organization.opened = false; user.opened = false; scanner.opened = false; vatContainer.opened = false; mathContainer.opened = false; break; case "ZoneTwo": organization.opened = !organization.opened; user.opened = !user.opened; scanner.opened = !scanner.opened; if( organization.opened ) { vatContainer.opened = false; mathContainer.opened = false; } break; case "ZoneThree": vatContainer.opened = !vatContainer.opened; mathContainer.opened = !mathContainer.opened; if( vatContainer.opened ) { organization.opened = false; user.opened = false; scanner.opened = false; } break; } } } private function displayShippingAddress( selected : Boolean ) : void { _updateAddressManually = selected; shippingAddressTextInput.text = ""; shippingAddressLabel.visible = selected; shippingAddressLabel.includeInLayout = selected; copyAddress( invoiceAddressTextInput.text ); } private function copyAddress( address : String ) : void { if( !_updateAddressManually ) shippingAddressTextInput.text = address; } private function searchCityWithZipCode() : void { if( countryComboBox.selectedIndex != -1 ) { _model.cities = new ArrayCollection(); new SearchCitiesEvent( zipCodeTextInput.text, countryComboBox.selectedItem.code ).dispatch(); var menuZipCode : Menu = Menu.createMenu( null, _model.cities, false ); menuZipCode.addEventListener( MenuEvent.ITEM_CLICK, citySelected ); menuZipCode.width = cityTextInput.width; menuZipCode.show( 258, 307 ); } else { var toastMessage : ImtToaster = new ImtToaster(); toastMessage.titleMessage = ResourceManager.getInstance().getString( 'labels', 'register.searchImpossibleTitle' ); toastMessage.message = ResourceManager.getInstance().getString( 'labels', 'register.searchImpossibleZip' ); toastMessage.level = ImtToaster.WARNING; ApplicationModelLocator.getInstance().toaster.toast( toastMessage ); } } private function searchZipCodeWithCity() : void { if( countryComboBox.selectedIndex != -1 ) { _model.zipCodes = new ArrayCollection(); new SearchZipCodesEvent( cityTextInput.text, countryComboBox.selectedItem.code ).dispatch(); var menuZipCode : Menu = Menu.createMenu( null, _model.zipCodes, false ); menuZipCode.addEventListener( MenuEvent.ITEM_CLICK, zipCodeSelected ); menuZipCode.width = cityTextInput.width; menuZipCode.show( 258, 279 ); } else { var toastMessage : ImtToaster = new ImtToaster(); toastMessage.titleMessage = ResourceManager.getInstance().getString( 'labels', 'register.searchImpossibleTitle' ); toastMessage.message = ResourceManager.getInstance().getString( 'labels', 'register.searchImpossibleCity' ); toastMessage.level = ImtToaster.WARNING; ApplicationModelLocator.getInstance().toaster.toast( toastMessage ); } } private function zipCodeSelected( event : MenuEvent ) : void { zipCodeTextInput.text = event.item.toString(); } private function citySelected( event : MenuEvent ) : void { cityTextInput.text = event.item.toString(); } private function changeQuestion( event : ListEvent, comboBox : ComboBox ) : void { var newSelection : Object = ( event.currentTarget as ComboBox ).selectedItem; var otherListSelection : Object = comboBox.selectedItem; var index : int = 0; comboBox.dataProvider = ObjectUtil.copy( _model.questions ) as ArrayCollection; for( index = 0; index < comboBox.dataProvider.length; index++ ) { if( comboBox.dataProvider[ index ].code == newSelection.code ) { ( comboBox.dataProvider as ArrayCollection ).removeItemAt( index ); break; } } for( index = 0; index < comboBox.dataProvider.length; index++ ) { if( otherListSelection != null && comboBox.dataProvider[ index ].code == otherListSelection.code ) { comboBox.selectedIndex = index; break; } } } private function onChangeActivity( event : ListEvent ) : void { if( event.currentTarget.selectedItem.code == "S09" ) _otherActivityActive = true; else _otherActivityActive = false; } private function checkTextInputEntry (textInputWithSkin : *, formItem : FormItem) : void { if (textInputWithSkin.errorString) { formItem.setStyle("color", "#7c0b13"); formItem.setStyle("fontWeight", "bold"); } else { formItem.setStyle("color", "#555557"); formItem.setStyle("fontWeight", "normal"); } } private function checkComboBoxEntry (comboBox : ComboBox, formItem : FormItem) : void { if (!comboBox.selectedItem) { formItem.setStyle("color", "#7c0b13"); formItem.setStyle("fontWeight", "bold"); } else { formItem.setStyle("color", "#555557"); formItem.setStyle("fontWeight", "normal"); } } private function update( event : MouseEvent ) : void { var toastMessage : ImtToaster = new ImtToaster(); var validatorsPartOne : Array = []; var validatorsPartTwo : Array = [ countryValidator, phoneCenterValidator, lastNameValidator, firstNameValidator, phoneValidator, activityValidator, cityValidator, zipCodeValidator, invoiceAddressValidator, shippingAddressValidator, hospitalValidator, frequencyValidator, brandValidator ]; var validatorsPartThree : Array = [ ]; var validators : Array = [ countryValidator, phoneCenterValidator, lastNameValidator, firstNameValidator, phoneValidator, activityValidator,cityValidator, zipCodeValidator, invoiceAddressValidator, shippingAddressValidator, hospitalValidator, frequencyValidator, brandValidator ]; if( _otherActivityActive ) { validatorsPartTwo.push( otherActivityValidator ); validators.push( otherActivityValidator ); } var validatorsError : Array = Validator.validateAll( validators ); var validatorsPartOneError : Array = Validator.validateAll( validatorsPartOne ); var validatorsPartTwoError : Array = Validator.validateAll( validatorsPartTwo ); var validatorsPartThreeError : Array = Validator.validateAll( validatorsPartThree ); _partOneValid = true; _partTwoValid = true; _partThreeValid = true; if( validatorsPartTwoError.length != 0 ) partTwo.enabled = true; else partTwo.enabled = false; if( validatorsPartThreeError.length != 0 ) partThree.enabled = true; else partThree.enabled = false; var textInputWithSkinList : Array = [ hospitalTextInput, invoiceAddressTextInput, shippingAddressTextInput, cityTextInput, zipCodeTextInput, phoneCenterTextInput, lastNameTextInput, firstNameTextInput, phoneTextInput, otherActivityTextInput, brandTextInput ]; var textInputLabel : Array = [ hospitalLabel, invoiceAddressLabel, shippingAddressLabel, cityLabel, zipCodeLabel, phoneCenterLabel, lastNameLabel, firstNameLabel, phoneLabel, otherActivityLabel, brandLabel ]; var comboBoxList : Array = [ countryComboBox, activityComboBox ]; var comboBoxLabel : Array = [ countryLabel, activityLabel ]; for (var i : int = 0; i < textInputWithSkinList.length; i++) checkTextInputEntry(textInputWithSkinList[i], textInputLabel[i]); for (i = 0; i < comboBoxList.length; i++) checkComboBoxEntry(comboBoxList[i], comboBoxLabel[i]); if( validatorsError.length != 0 ) { toastMessage = new ImtToaster(); toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'error.allFieldsTitle'); toastMessage.timeToLive = 7; toastMessage.message = ResourceManager.getInstance().getString('labels', 'error.allFields'); toastMessage.level = ImtToaster.WARNING; _model.toaster.toast( toastMessage ); } else { var newProbeVo : ProbeVo = new ProbeVo(); newProbeVo.id = ApplicationModelLocator.getInstance().connectedUser.probe.id; newProbeVo.frequency = frequencyNumericStepper.value var newUltraSoundScannerVo : UltraSoundScannerVo = new UltraSoundScannerVo(); newUltraSoundScannerVo.id = ApplicationModelLocator.getInstance().connectedUser.ultraSoundScanner.id; newUltraSoundScannerVo.name = nameTextInput.text; newUltraSoundScannerVo.brand = brandTextInput.text; newUltraSoundScannerVo.type = typeTextInput.text; newUltraSoundScannerVo.age = new Date(ageNumericStepper.value); newUltraSoundScannerVo.probes.push( newProbeVo ); var newHospitalVo : HospitalVo = new HospitalVo(); newHospitalVo.id = ApplicationModelLocator.getInstance().connectedUser.hospital.id; newHospitalVo.name = hospitalTextInput.text; newHospitalVo.addressInvoicing = invoiceAddressTextInput.text; newHospitalVo.addressShipping = shippingAddressTextInput.text; newHospitalVo.city = cityTextInput.text; newHospitalVo.zipCode = zipCodeTextInput.text; newHospitalVo.country = countryComboBox.selectedItem.code; newHospitalVo.phone = phoneCenterTextInput.text; newHospitalVo.fax = faxCenterTextInput.text; // update for ethnic group (avalaible for all countries but France) _model.connectedUser.hospital.country = newHospitalVo.country; var newPersonVo : PersonVo = new PersonVo(); newPersonVo.id = ApplicationModelLocator.getInstance().connectedUser.person.id; newPersonVo.lastName = lastNameTextInput.text; newPersonVo.firstName = firstNameTextInput.text; newPersonVo.phone = phoneTextInput.text; newPersonVo.fax = faxTextInput.text; newPersonVo.activity = (otherActivityTextInput.text ? otherActivityTextInput.text : activityComboBox.selectedLabel); var userVo : UserVo = new UserVo(); userVo.hospital = newHospitalVo; userVo.ultraSoundScanner = newUltraSoundScannerVo; userVo.person = newPersonVo; userVo.buyer = buyer.selected; userVo.id = _model.connectedUser.id; if ( activityComboBox.selectedItem.code == 9 ) newPersonVo.activity = otherActivityTextInput.text; else newPersonVo.activity = activityComboBox.selectedLabel; new UpdateUserEvent( userVo, "PHYSICIAN", this ).dispatch(); registerButton.enabled = false; } } private function resetLabels() : void { var formItemList : Array = [ hospitalTextInput, invoiceAddressTextInput, shippingAddressTextInput, cityTextInput, zipCodeTextInput, countryComboBox, phoneCenterTextInput, lastNameTextInput, firstNameTextInput, phoneTextInput, activityComboBox, otherActivityTextInput, brandTextInput ]; var formLabelList : Array = [ hospitalLabel, invoiceAddressLabel, shippingAddressLabel, cityLabel, zipCodeLabel, countryLabel, phoneCenterLabel, lastNameLabel, firstNameLabel, phoneLabel, activityLabel, otherActivityLabel, brandLabel ]; for (var i : int = 0; i < formItemList.length; i++) { formLabelList[i].setStyle("color", "#555557"); formLabelList[i].setStyle("fontWeight", "normal"); formItemList[i].errorString = ""; } } public function reset() : void { hospitalValidator.enabled = false; invoiceAddressValidator.enabled = false; shippingAddressValidator.enabled = false; cityValidator.enabled = false; zipCodeValidator.enabled = false; countryValidator.enabled = false; phoneCenterValidator.enabled = false; lastNameValidator.enabled = false; firstNameValidator.enabled = false; phoneValidator.enabled = false; activityValidator.enabled = false; brandValidator.enabled = false; frequencyValidator.enabled = false; otherActivityValidator.enabled = false; hospitalTextInput.text = ""; invoiceAddressTextInput.text = ""; shippingAddressTextInput.text = ""; cityTextInput.text = ""; zipCodeTextInput.text = ""; countryComboBox.selectedIndex = -1; phoneCenterTextInput.text = ""; faxCenterTextInput.text = ""; lastNameTextInput.text = ""; firstNameTextInput.text = ""; phoneTextInput.text = ""; faxTextInput.text = ""; activityComboBox.selectedIndex = -1; activityComboBox.prompt = ResourceManager.getInstance().getString('labels', 'chooseActivity'); brandTextInput.text = ""; typeTextInput.text = ""; frequencyNumericStepper.value = 0; ageNumericStepper.value = 0; otherActivityTextInput.text = ""; hospitalValidator.enabled = true; invoiceAddressValidator.enabled = true; shippingAddressValidator.enabled = true; cityValidator.enabled = true; zipCodeValidator.enabled = true; countryValidator.enabled = true; phoneCenterValidator.enabled = true; lastNameValidator.enabled = true; firstNameValidator.enabled = true; phoneValidator.enabled = true; activityValidator.enabled = true; brandValidator.enabled = true; frequencyValidator.enabled = true; otherActivityValidator.enabled = true; resetLabels(); } public function returnToHome() : void { this.parentDocument.selectedIndex = 0; } public function exportData() : void { var userVo : UserVo = new UserVo(); userVo.id = _model.connectedUser.id; new ExportDataEvent( userVo, this ).dispatch(); } public function onDisplayConditions() : void { new TermsAgreedEvent(_model.connectedUser, this).dispatch(); } public function displayConditions( idterms : int, urlterms : String ) : void { var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, displayConditionsCompleteHandler); loader.load(new URLRequest(urlterms)); } private function displayConditionsCompleteHandler(event:Event) : void { var loader:URLLoader = URLLoader(event.target); var _applicationTermsPopUp : ApplicationTermsPopUp = new ApplicationTermsPopUp(); _applicationTermsPopUp.setTermsAndConditions(loader.data); PopUpManager.addPopUp( _applicationTermsPopUp, this, true ); PopUpManager.centerPopUp( _applicationTermsPopUp ); } private function setFieldError() : void { hospitalValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); invoiceAddressValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); shippingAddressValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); cityValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); zipCodeValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); countryValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); phoneCenterValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); lastNameValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); firstNameValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); phoneValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); activityValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); brandValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); frequencyValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); otherActivityValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required'); } private function initListeners() : void { setFieldError(); hospitalValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler); invoiceAddressValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler); shippingAddressValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler); cityValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler); zipCodeValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler); countryValidator.addEventListener(ValidationResultEvent.VALID, numberValidatorHandler); phoneCenterValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler); lastNameValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler); firstNameValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler); phoneValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler); activityValidator.addEventListener(ValidationResultEvent.VALID, numberValidatorHandler); brandValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler); frequencyValidator.addEventListener(ValidationResultEvent.VALID, numberValidatorHandler); otherActivityValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler); } public function updateErrorStrings() : void { setFieldError(); if (hospitalTextInput.errorString) hospitalTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (invoiceAddressTextInput.errorString) invoiceAddressTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (shippingAddressTextInput.errorString) shippingAddressTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (cityTextInput.errorString) cityTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (zipCodeTextInput.errorString) zipCodeTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (countryComboBox.errorString) countryComboBox.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (phoneCenterTextInput.errorString) phoneCenterTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (lastNameTextInput.errorString) lastNameTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (firstNameTextInput.errorString) firstNameTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (phoneTextInput.errorString) phoneTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (activityComboBox.errorString) activityComboBox.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (otherActivityTextInput.errorString) otherActivityTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (brandTextInput.errorString) brandTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); if (frequencyNumericStepper.errorString) frequencyNumericStepper.errorString = ResourceManager.getInstance().getString('labels', 'errorField'); } private function stringValidatorHandler(event : ValidationResultEvent) : void { if (event.target.errorString) event.target.errorString = null; } private function numberValidatorHandler(event : ValidationResultEvent) : void { if (event.target.errorString) event.target.errorString = null; }