consumerportal
Version:
mydna Custimised for you
93 lines (85 loc) • 3.66 kB
text/typescript
/// <reference path="../../includes.ts" />
module helpContactUsCtrl{
import UserService = services.UserService;
import IUserContact = services.IUserContact;
import IUser = services.IUser;
interface IHelpContactUsController{
sendContactDetails(): void;
}
interface IHelpContactUsScope extends angular.IScope{
myForm: angular.IFormController;
$sce: angular.ISCEService;
}
class HelpContactUsController implements IHelpContactUsController {
frm: any;
showErrors : boolean = false;
sentSuccesfully: boolean = false;
static $inject =[
'apiSrvc',
'errorHandlerSrvc',
'$scope',
'mydnaApis',
'scrollerSrvc',
'$location',
'UtilitySrvc',
'userService',
'user'
];
constructor(private apiSrvc: apiSrvc.IApiService,
private errorHandlerSrvc: errorHandlerSrvc.IErrorHandlerService,
private $scope: IHelpContactUsScope,
private mydnaApis: ImyDNAApis,
private scrollerSrvc:scrollerSrvc.IScrollerService,
private $location: angular.ILocationService,
private UtilitySrvc:UtilitySrvc.IUtilityService,
private userService: UserService,
private user: IUser
) {
let vm = this;
vm.frm = {
UserName : user.Username,
FirstName : this.UtilitySrvc.toTitleCase(user.FirstName),
LastName : this.UtilitySrvc.toTitleCase(user.LastName),
Email : (user.Email || '').toLowerCase(),
Subject : '',
Message : ''
};
this.userService.contact().then((contact: IUserContact) => {
vm.frm.PhoneNumber = UtilitySrvc.reFormatPhoneNumberFromCountryCode(contact.Mobile);
});
}
sendContactDetails(){
this.scrollerSrvc.TopScroll();
this.showErrors = false;
this.sentSuccesfully = false;
if (this.$scope.myForm.$valid) {
let phone = this.frm.PhoneNumber;
this.formatFormData();
this.$scope.$emit("disable-on-save-on");
this.apiSrvc.post_request_urlEncode(this.mydnaApis.ContactUs,this.frm).then(data=> {
this.sentSuccesfully = true;
this.frm.Subject = "";
this.frm.Message = "";
this.frm.PhoneNumber = phone;
this.$scope.$emit("disable-on-save-off");
},err => {
this.frm.PhoneNumber = phone;
this.errorHandlerSrvc.errorHandler(err, 'debug', '');
this.$scope.$emit("disable-on-save-off");
});
} else {
this.showErrors = true;
}
this.$scope.myForm.$setPristine();
}
formatFormData(){
this.frm.FirstName = this.UtilitySrvc.toTitleCase(this.frm.FirstName);
this.frm.LastName = this.UtilitySrvc.toTitleCase(this.frm.LastName);
this.frm.PhoneNumber = this.UtilitySrvc.formatPhoneNumberToCountryCode(this.frm.PhoneNumber);
this.frm.Email = this.frm.Email!==null?this.frm.Email.toLowerCase():"";
}
}
angular
.module('app')
.controller('helpContactUsCtrl', HelpContactUsController);
}