UNPKG

consumerportal

Version:

mydna Custimised for you

218 lines (173 loc) 6.86 kB
/// <reference path="../../includes.ts" /> module acctMgmtRegisterCtrl{ interface IAcctMgmtRegisterController{ saveDetails(); getDetails(); } interface IAcctMgmtRegisterScope extends angular.IScope{ myForm: angular.IFormController, snd: any; } class AcctMgmtRegisterController implements IAcctMgmtRegisterController{ static $inject = [ '$rootScope', '$scope', 'scrollerSrvc', 'apiSrvc', 'appMemorySrvc', 'locationSrvc', 'errorHandlerSrvc', 'mydnaApis', 'UtilitySrvc', '$filter' ]; frm: any; tabIndexValue: any; showErrors: any; Countries:any; selectedCountry:any; constructor ( private $rootScope: angular.IRootScopeService, private $scope: IAcctMgmtRegisterScope, private scrollerSrvc: scrollerSrvc.IScrollerService, private apiSrvc: apiSrvc.IApiService, private appMemorySrvc: appMemorySrvc.IAppMemoryService, private locationSrvc: locationSrvc.ILocationService, private errorHandlerSrvc: errorHandlerSrvc.IErrorHandlerService, private mydnaApis: ImyDNAApis, private UtilitySrvc: UtilitySrvc.IUtilityService, private $filter: angular.IFilterService ){ var vm = this; vm.frm = {}; vm.frm.dob = ""; vm.showErrors = false; vm.Countries = []; vm.selectedCountry = { "Id": "", "Name": "", "IsDefault": true } vm.getCountries(); $rootScope.$on("resetTabIndexValue", (event, message) => { vm.tabIndexValue = "0"; }); $rootScope.$on("setTabIndexValue", (event, message) => { vm.tabIndexValue = "-1"; }); if(vm.appMemorySrvc.getGenericFlag() == false){ vm.locationSrvc.goto('acctmgmt/findpatient',''); } else{ vm.getDetails(); } } getDetails(){ this.$scope.$emit("disable-on-save-on"); this.apiSrvc.registration_requests( this.mydnaApis.RegistrationDetails , "", true, "GET", "JSON").then(data => { this.frm = data.data; if (data.data.Country===undefined){ this.frm.Country = "Australia" }else{ //this.setCountryFromData(); } this.formatFormDataforPopulating(); this.$scope.$emit("disable-on-save-off"); }, err => { this.errorHandlerSrvc.errorHandler(err, 'debug', ''); this.$scope.$emit("disable-on-save-off"); }); } saveDetails(){ this.showErrors = this.showErrors == true ? false : ""; this.scrollerSrvc.TopScroll(); if(this.$scope.myForm.$valid){ this.$scope.$emit("disable-on-save-on"); var mobile = this.frm.Mobile; this.formatFormData(); if (this.frm.Country ==undefined){ this.frm.Country = "Australia" ; } this.apiSrvc.registration_requests( this.mydnaApis.RegistrationDetails , this.frm, true, "POST", "JSON").then(data => { this.appMemorySrvc.setRegistrationUserinfo(this.frm); this.$scope.$emit("disable-on-save-off"); this.locationSrvc.goto('acctmgmt/signindetails', ''); }, err => { this.frm.Mobile = mobile; this.errorHandlerSrvc.errorHandler(err, 'debug', ''); this.$scope.$emit("disable-on-save-off"); }); } else{ this.showErrors = true; } } getCountries(){ var data = [ {"Id": "AUS","Name": "Australia","IsDefault": true} ,{"Id": "NZL","Name": "New Zealand","IsDefault": false} ,{"Id": "UK","Name": "United Kingdom","IsDefault": false} ,{"Id": "CAN","Name": "Canada","IsDefault": false} ]; this.Countries = data; var thisElementPos = data.map(function(x) { return x.IsDefault; }).indexOf(true); this.selectedCountry = (thisElementPos == null || thisElementPos == undefined || thisElementPos == -1) ? data[0] : data[thisElementPos]; this.setCountry(); /////Uncomment the below code once the country field is implemented. // this.$scope.$emit("disable-on-save-on"); // this.ApiSrvc.get_request_params(this.mydnaApis.Countries, '').then(data => { // this.$scope.$emit("disable-on-save-off"); // this.Countries = data; // var thisElementPos = data.map(function(x) { return x.IsDefault; }).indexOf(true); // this.frm.countryID = (thisElementPos == null || thisElementPos == undefined || thisElementPos == -1) // ? this.frm.countryID = this.Countries[0].Id // : this.frm.countryID = this.Countries[thisElementPos].Id; // this.selectedCountry = (thisElementPos == null || thisElementPos == undefined || thisElementPos == -1) // ? data[0] // : data[thisElementPos]; // }, err => { // var data = [ {"Id": "AUS","Name": "Australia","IsDefault": true}, // {"Id": "NEZ","Name": "New Zealand","IsDefault": false} // ]; // this.Countries = data; // var thisElementPos = data.map(function(x) { return x.IsDefault; }).indexOf(true); // // this.frm.countryID = (thisElementPos == null || thisElementPos == undefined || thisElementPos == -1) // // ? this.frm.countryID = this.Countries[0].Id // // : this.frm.countryID = this.Countries[thisElementPos].Id; // this.selectedCountry = (thisElementPos == null || thisElementPos == undefined || thisElementPos == -1) // ? data[0] // : data[thisElementPos]; // // this.errorHandlerSrvc.errorHandler(err, 'debug', ''); // this.$scope.$emit("disable-on-save-off"); // }); } setCountry(){ this.frm.Country = this.selectedCountry.Name; } setCountryFromData(){ var thisElementPos = this.Countries.map(function(x) { return x.Name; }).indexOf(this.frm.Country); this.selectedCountry = (thisElementPos == null || thisElementPos == undefined || thisElementPos == -1) ? this.Countries[0] : this.Countries[thisElementPos]; this.frm.Country = this.selectedCountry.Name; } formatFormData(){ this.frm.Address =this.UtilitySrvc.toTitleCase(this.frm.Address); this.frm.Suburb = this.UtilitySrvc.toTitleCase(this.frm.Suburb); this.frm.Mobile = this.UtilitySrvc.formatPhoneNumberToCountryCode(this.frm.Mobile); this.frm.Email = this.frm.Email!==null?this.frm.Email.toLowerCase():""; } formatFormDataforPopulating(){ this.frm.Address =this.UtilitySrvc.toTitleCase(this.frm.Address); this.frm.Suburb = this.UtilitySrvc.toTitleCase(this.frm.Suburb); this.frm.Mobile = this.UtilitySrvc.reFormatPhoneNumberFromCountryCode(this.frm.Mobile); this.frm.Email = this.frm.Email!==null?this.frm.Email.toLowerCase():""; } } angular.module('app').controller('acctMgmtRegisterCtrl', AcctMgmtRegisterController); }