| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606 |
- 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;
- }
|