angular.module('kalgudiApp.profile').controller('personalInfoController', ["$scope","profileService","$state","$rootScope",'$filter', function($scope,profileService,$state,$rootScope,$filter){ var familyIndex = ""; $scope.currentPersonalInfo={}; $scope.educationdetails={}; $scope.educationEditFlag=false; $scope.universityWarn=$scope.profileLiterals.searchByKey('ENTER_UNIV_WARN'); $scope.endyearWarn=$scope.profileLiterals.searchByKey('END_YEAR_WARN'); $scope.onlyNumberWarn=$scope.profileLiterals.searchByKey('ONLY_NUMBER_WARN'); $scope.searchRequest = { "query" : "", "type" : "", "limit" : 20, "offset" : 0 } /*personal details*/ $scope.editPersonalInfo = function() { $scope.currentPersonalInfoErrorFlag= { interests: false, emailId : false, address1 : false, address2 : false, alternateMobileNo : false, landLineNumber : false } $scope.currentPersonalInfo = { dateOfBirth: $rootScope.loggedInUserBusinessProfile.dateOfBirth, firstName: $rootScope.loggedInUserBusinessProfile.firstName, maritalStatus : $rootScope.loggedInUserBusinessProfile.maritalStatus, gender : $rootScope.loggedInUserBusinessProfile.gender, interests : $rootScope.loggedInUserBusinessProfile.interests, country:$rootScope.loggedInUserBusinessProfile.country, address1:$rootScope.loggedInUserBusinessProfile.address1, address2 : $rootScope.loggedInUserBusinessProfile.address2, //landLineCode : $rootScope.loggedInUserBusinessProfile.landLineNumber, landLineNumber : $rootScope.loggedInUserBusinessProfile.landLineNumber, //mobileNo : $rootScope.loggedInUserBusinessProfile.mobileNo, alternateMobileNo : $rootScope.loggedInUserBusinessProfile.alternateMobileNo, emailId : $rootScope.loggedInUserBusinessProfile.emailId, altemailId : $rootScope.loggedInUserBusinessProfile.altemailId, location_personal : $rootScope.loggedInUserCurrentBussinessInfo.locationTo.placeName + ', ' + $rootScope.loggedInUserCurrentBussinessInfo.locationTo.locationShort, location : $rootScope.loggedInUserCurrentBussinessInfo.locationTo, businessTypeName : $rootScope.loggedInUserCurrentBussinessInfo.businessTypeName, uniqueIdentificationNo : $rootScope.loggedInUserBusinessProfile.uniqueIdentificationNo, aboutMe : $rootScope.loggedInUserBusinessProfile.aboutMe } } $scope.editPersonalInfo(); $scope.restEducationalDetails =function(){ $scope.educationdetails.institutionName = "" $scope.educationdetails.startYear ="" $scope.educationdetails.endYear ="" $scope.educationdetails.degree ="" $scope.educationdetails.fieldOfStudy ="" $scope.educationdetails.educationDetailId="" $scope.educationEditFlag=false; } $scope.validateCurrentPersonalInfo = function() { var personalInfoFlag = true; if($scope.currentPersonalInfo.interests) { if(_.size($scope.currentPersonalInfo.interests) > $scope.characterLimit_2) { $scope.currentPersonalInfoErrorFlag.interests = true; $scope.currentPersonalInfo.interests = ""; $scope.currentPersonalInfoPlaceholder.interests = $scope.profileLiterals.searchByKey('KL_PR_0178'); personalInfoFlag = false; } else { $scope.currentPersonalInfoErrorFlag.interests = false; personalInfoFlag = true; } } if($scope.currentPersonalInfo.emailId) { if($scope.emailRegex.test($scope.currentPersonalInfo.emailId) == false) { $scope.currentPersonalInfoErrorFlag.emailId = true; $scope.currentPersonalInfo.emailId = ""; $scope.currentPersonalInfoPlaceholder.emailId = $scope.profileLiterals.searchByKey('KL_PR_0402'); personalInfoFlag = false; } else { $scope.currentPersonalInfoErrorFlag.emailId = false; //personalInfoFlag = true; } } if($scope.currentPersonalInfo.address1) { if(_.size($scope.currentPersonalInfo.address1) > $scope.characterLimit_2) { $scope.currentPersonalInfoErrorFlag.address1 = true; $scope.currentPersonalInfo.address1 = ""; $scope.currentPersonalInfoPlaceholder.address1 = $scope.profileLiterals.searchByKey('KL_PR_0181'); personalInfoFlag = false; } else { $scope.currentPersonalInfoErrorFlag.emailId = false; //personalInfoFlag = true; } } if($scope.currentPersonalInfo.address2) { if(_.size($scope.currentPersonalInfo.address2) > $scope.characterLimit_2){ $scope.currentPersonalInfo.address2 = ""; $scope.currentPersonalInfoErrorFlag.address2 = true; $scope.currentPersonalInfoPlaceholder.address2 = $scope.profileLiterals.searchByKey('KL_PR_0181'); personalInfoFlag = false; } else { $scope.currentPersonalInfoErrorFlag.address2 = false; //personalInfoFlag = true; } } if($scope.currentPersonalInfo.alternateMobileNo) { if(_.size($scope.currentPersonalInfo.alternateMobileNo) != 10) { $scope.currentPersonalInfo.alternateMobileNo = ""; $scope.currentPersonalInfoErrorFlag.alternateMobileNo = true; $scope.currentPersonalInfoPlaceholder.alternateMobileNo = $scope.profileLiterals.searchByKey('KL_PR_0179'); personalInfoFlag = false; } else { //personalInfoFlag = true; $scope.currentPersonalInfoErrorFlag.alternateMobileNo = false; } } if($scope.currentPersonalInfo.landLineNumber) { if(_.size($scope.currentPersonalInfo.landLineNumber) <5) { $scope.currentPersonalInfo.landLineNumber = ""; $scope.currentPersonalInfoErrorFlag.landLineNumber = true; $scope.currentPersonalInfoPlaceholder.landLineNumber =$scope.profileLiterals.searchByKey('KL_PR_0494'); personalInfoFlag = false; } else { //personalInfoFlag = true; $scope.currentPersonalInfoErrorFlag.landLineNumber = false; } } return personalInfoFlag; } $scope.validmail=function() { if($scope.currentPersonalInfo.emailId !=""){ $scope. currentPersonalInfoErrorFlag.emailId=false; } } $scope.validlandlinenumber=function() { if($scope.currentPersonalInfo.landLineNumber !=""){ $scope.currentPersonalInfoErrorFlag.landLineNumber=false; } } /*$scope.profileServiceCall =function(){ profileService.getUserProfile($rootScope.loggedInUserBusinessProfile.profileKey).then(function(result) { $rootScope.loggedInUserBusinessProfile = result; $rootScope.loggedInUserCurrentBussinessInfo = _.find($rootScope.loggedInUserBusinessProfile.lstOfUserBusinessDetailsInfo,function(rw){ return rw.businessUUID == $rootScope.globalConfig.currentBussinessId }); //$rootScope.$broadcast('loggedInUserProfieLoaded',"true"); }); }*/ $rootScope.$on("updatePersonalInformationAEE",function(event,state){ console.log('broadcasting to updatePersonalInformationAEE'); if(state == 'emailId'){ $scope.currentPersonalInfo.emailId = $rootScope.loggedInUserBusinessProfile.alternateEmailId; $scope.updatePersonalInformation(); }else if (state == 'mobile') { $scope.currentPersonalInfo.alternateMobileNo = $rootScope.loggedInUserBusinessProfile.altmobileNo; $scope.updatePersonalInformation(); } }); $scope.updatePersonalInformation = function() { //if($scope.validateCurrentPersonalInfo()) { profileService.updatePersonalInfo($scope.currentPersonalInfo,$rootScope.loggedInUserBusinessProfile.profileKey).then(function(response) { if(response.code == 201) { $scope.profileServiceCallRefresh(); $scope.restEducationalDetails(); } else { //$rootScope.commonTopErrorAlert($scope.profileLiterals.searchByKey('KL_PR_0165')); } }); //} } /*end personaldetails modal*/ /*personal details end*/ /*educational Details*/ $scope.editEducationDetails = function(education) { $scope.educationdetails.institutionName = education.institutionName; $scope.educationdetails.startYear =education.startYear; $scope.educationdetails.endYear =education.endYear; $scope.educationdetails.degree =education.degree; $scope.educationdetails.fieldOfStudy =education.fieldOfStudy; $scope.educationdetails.educationDetailId=education.educationDetailId; $scope.educationEditFlag=true; } $scope.universityList = []; $scope.searchTextFlag = false; $scope.preKey = ""; $scope.getUniversities = function(keyword){ $scope.universityList = []; $scope.temp = ""; if(keyword.length >2 && $scope.preKey.length <= keyword.length){ $scope.preKey = keyword; $scope.searchTextFlag = true; $scope.searchRequest.query = keyword; $scope.searchRequest.type = "UNIVERSITY"; profileService.searchEntityWithKey($scope.searchRequest).then(function(result) { $scope.temp = "["+result.data+"]"; $scope.universityList = JSON.parse($scope.temp); }); }else{ $scope.preKey = keyword; } } $scope.selectedUni = function(name){ $scope.searchTextFlag = false; $scope.educationdetails.institutionName = name; } $scope.endYearFlag = false; $scope.institutionNameFlag = false; $scope.startYearNotCharFlag = false; $scope.endYearNotCharFlag = false; $scope.startYearOnlyNumber = function (startYear) { if(startYear != ""){ if(/^[0-9]*$/.test(startYear)){ $scope.startYearNotCharFlag = false; }else{ $scope.startYearNotCharFlag = true; } }else { $scope.startYearNotCharFlag = false; } } $scope.endYearOnlyNumber = function (endYear) { if(endYear != ""){ if(/^[0-9]*$/.test(endYear)){ $scope.endYearNotCharFlag = false; }else{ $scope.endYearNotCharFlag = true; } }else { $scope.endYearNotCharFlag = false; } } $scope.validatingEducation = function(educationdetails) { if(educationdetails.institutionName != "") { $scope.institutionNameFlag = false; if((educationdetails.startYear != "") && (educationdetails.endYear != "")){ if(!$scope.startYearNotCharFlag && !$scope.endYearNotCharFlag ) { if ($scope.educationdetails.endYear > $scope.educationdetails.startYear) { $scope.createEducationDetails(); $scope.expandeducation(); } else { $scope.endYearFlag = true; } } }else if ((educationdetails.startYear != "") && (educationdetails.endYear == "")){ if(!$scope.startYearNotCharFlag){ $scope.createEducationDetails(); $scope.expandeducation(); } }else if ((educationdetails.startYear == "") && (educationdetails.endYear != "")){ if(!$scope.endYearNotCharFlag){ $scope.createEducationDetails(); $scope.expandeducation(); } }else { $scope.createEducationDetails(); $scope.expandeducation(); } } else { $scope.institutionNameFlag = true; } } $scope.allFlagFalse =function(){ $scope.endYearFlag = false; $scope.institutionNameFlag = false; $scope.startYearNotCharFlag = false; $scope.endYearNotCharFlag = false; } $scope.createEducationDetails= function() { //if($scope.validateEducation()) { profileService.createEducation($scope.educationdetails,$rootScope.loggedInUserBusinessProfile.profileKey).then(function(result) { if(result.code == 201) { $scope.profileServiceCallRefresh(); $scope.restEducationalDetails(); } else { //$rootScope.spinerisActive = false; ////$rootScope.commonTopErrorAlert($scope.profileLiterals.searchByKey('KL_PR_0321')); //$scope.resetEducationDetails(); } }); //} } $scope.updateEducationDetails = function() { //if($scope.validateEducation()) { //$scope.educationdetails.currentEducation.educationDetailId = $rootScope.loggedInUserBusinessProfile.lstOfUserEducationDetails[$scope.educationdetails.currentEducation.educationIndex].educationDetailId; profileService.updateEducation($scope.educationdetails,$rootScope.loggedInUserBusinessProfile.profileKey).then(function(result) { if(result.code == 201) { $scope.profileServiceCallRefresh(); $scope.restEducationalDetails(); } else { //$rootScope.spinerisActive = false; //$rootScope.commonTopErrorAlert($scope.profileLiterals.searchByKey('KL_PR_0321')); //$scope.resetEducationDetails(); } }); //} } }]);