UNPKG

consumerportal

Version:

mydna Custimised for you

153 lines (129 loc) 4.47 kB
/// <reference path="../../includes.ts" /> module acctMgmtContactDetailsCtrl { interface IAcctMgmtContactDetailsController { saveContactDetails(): any; getContactDetails(): any; } interface IAcctMgmtContactDetailsScope extends angular.IScope { myForm : angular.IFormController } class AcctMgmtContactDetailsController implements IAcctMgmtContactDetailsController { static $inject = [ '$scope', 'apiSrvc', 'mydnaApis', 'errorHandlerSrvc', 'scrollerSrvc', '$location', 'appMemorySrvc', 'UtilitySrvc' ]; showErrors: any; frm: any; UserInfo: any; AuthenToken: any; savedSuccessfully: any; nextLocationPath :any ; locationChanged :boolean; ContactDetails:any; constructor( private $scope : IAcctMgmtContactDetailsScope, private apiSrvc: apiSrvc.IApiService, private mydnaApis: ImyDNAApis, private errorHandlerSrvc: errorHandlerSrvc.IErrorHandlerService, private scrollerSrvc: scrollerSrvc.IScrollerService, private $location: angular.ILocationService, private appMemorySrvc: appMemorySrvc.IAppMemoryService, private UtilitySrvc:UtilitySrvc.IUtilityService ){ var vm = this; vm.ContactDetails = this.appMemorySrvc.getContactDetails(); if (vm.ContactDetails!=="" && vm.ContactDetails!==null && vm.ContactDetails!==undefined){ vm.frm = { Address: vm.ContactDetails.Address, Suburb: vm.ContactDetails.Suburb, State: vm.ContactDetails.State, PostCode: vm.ContactDetails.PostCode, Mobile: vm.ContactDetails.Mobile, Email: vm.ContactDetails.Email, }; }else{ vm.frm = { Address: "", Suburb: "", State: "", PostCode: "", Mobile: "", Email: "", }; vm.getContactDetails(); } vm.showErrors = false; vm.savedSuccessfully = false; vm.nextLocationPath = ""; vm.locationChanged = false; this.formatFormDataforPopulating(); } getContactDetails(){ this.$scope.$emit("disable-on-save-on"); this.apiSrvc.get_request_params( this.mydnaApis.ContactDetails , "").then(data => { this.frm = data; this.frm.Mobile = this.UtilitySrvc.reFormatPhoneNumberFromCountryCode(this.frm.Mobile); this.appMemorySrvc.setContactDetails(data); this.$scope.$emit("disable-on-save-off"); }, err => { this.errorHandlerSrvc.errorHandler(err, 'debug', ''); this.$scope.$emit("disable-on-save-off"); }); } saveContactDetails(){ this.scrollerSrvc.TopScroll(); this.showErrors = this.showErrors == true ? false : ""; if (this.$scope.myForm.$valid) { var mobile = this.frm.Mobile; this.formatFormData(); this.$scope.$emit("disable-on-save-on"); this.apiSrvc.post_request( this.mydnaApis.ContactDetails , this.frm).then(data => { this.appMemorySrvc.setContactDetails(this.frm); this.formatFormDataforPopulating(); this.$scope.$emit("disable-on-save-off"); this.savedSuccessfully = true; }, err => { this.frm.Mobile=mobile; this.$scope.$emit("disable-on-save-off"); this.errorHandlerSrvc.errorHandler(err, 'debug', ''); }); } else { this.showErrors = true; } this.$scope.myForm.$setPristine(); } 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():""; } convertDate(){ if (this.frm.dob!=""){ if(this.frm.dob.toString().includes("/")){ var dateParts = this.frm.dob.split("/"); var dateObject = Date.UTC(dateParts[2], dateParts[1] - 1, dateParts[0]); this.frm.dob = dateObject; } } } } angular.module('app').controller('acctMgmtContactDetailsCtrl', AcctMgmtContactDetailsController); }