client-ui
Version:
Testing implementation of nodeJs Backend, angular frontend, and hopefully in a way that this can be deployed to s3/cloudfront
493 lines (472 loc) • 27 kB
JavaScript
angular.module(moduleName)
.run(['$rootScope', '$state', 'AuthStateFactory', 'stateChangeManager', 'loan', 'client', '$location', function ($rootScope, $state, AuthStateFactory, stateChangeManager, loan, client, $location) {
AuthStateFactory.check();
var hadRouteChange = false;
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
$rootScope.hideSpinner = false;
hadRouteChange = true;
stateChangeManager.doTasks();
if (toState.loginRequirement === 'notAllowed') {
if (AuthStateFactory.isLoggedIn) {
event.preventDefault();
$state.go('loanDashboard.myDashboard');
}
} else if (toState.loginRequirement === 'notRequired') {
// just allow anything
} else {
if (!AuthStateFactory.isLoggedIn) {
event.preventDefault();
$state.go('login');
}
}
var loanObj = loan.getCurrentLoan();
if (loanObj) {
if (loanObj.statusCode >= 500 && toState.incompleteLoanApplication === 'required') {
event.preventDefault();
$state.go('loanDashboard.myDashboard');
}
var payMethod = loanObj.payMethod || {};
if ((!payMethod || (payMethod && payMethod.name === 'check' && !payMethod.confirmed) ) && toState.name !== "loanDashboard.myDashboard") {
if (toState.confirmedPayMethod === 'required') {
event.preventDefault();
$state.go('loanDashboard.myDashboard', {messages: 'CALL_TO_PROCEED'});
}
}
}
var clientObj = client.getClientStore();
if (clientObj) {
if (clientObj.requestIdDoc && toState.confirmedId === 'required') {
event.preventDefault();
$state.go('loanApplication.verify.identity');
}
}
});
$rootScope.$on('$stateChangeSuccess', function(){
config.scrollToTop();
$rootScope.hideSpinner = true;
if (config.isProduction()) {
ga('send', 'pageview', $location.path());
}
});
$rootScope.globalConfig = globalConfig;
$rootScope.config = config;
function hookAngularBoomerang() {
if (window.BOOMR && BOOMR.version) {
if (BOOMR.plugins && BOOMR.plugins.Angular) {
BOOMR.plugins.Angular.hook($rootScope, hadRouteChange);
}
return true;
}
}
if (!hookAngularBoomerang()) {
if (document.addEventListener) {
document.addEventListener("onBoomerangLoaded", hookAngularBoomerang);
}
else if (document.attachEvent) {
document.attachEvent("onpropertychange", function (e) {
e = e || window.event;
if (e && e.propertyName === "onBoomerangLoaded") {
hookAngularBoomerang();
}
});
}
}
}])
.config(['$sceDelegateProvider', function ($sceDelegateProvider) {
// whitelist our remote content urls (s3)
$sceDelegateProvider.resourceUrlWhitelist([
'self',
config.staticContentDomainRoot + '/**',
config.s3DomainRoot + config.staticContentDomainRoot + '/**',
'http://decisionlogic*.' + config.envName + '.' + config.domainRoot + '/**',
'https://widget.decisionlogic.com/**'
]);
}])
.config(['$provide', '$httpProvider', function ($provide, $httpProvider) {
// toggle withCredentials flag based on request url
// (needs to be false for static/s3 content)
$provide.factory('StaticContentInterceptor', function () {
return {
request: function (opts) {
if (opts.url && opts.url.indexOf(config.staticContentDomainRoot) > 0) {
opts.withCredentials = false;
} else {
opts.withCredentials = true;
}
return opts;
}
};
});
$httpProvider.interceptors.push('StaticContentInterceptor');
}])
.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('root', {
abstract: true,
template: '<div ui-view=""></div>',
resolve: {
currentLoan: ['loan', 'client', function (loan, client) {
//if page was refreshed query client and loan from database
if (window.localStorage.getItem("loanRefreshed") === 'true'
&& loan.getCurrentLoan() && client.getClientStore()) {
window.localStorage.removeItem("loanRefreshed");
return loan.refreshCurrentLoanFromDB();
} else {
//else query from local storage
window.localStorage.removeItem("loanRefreshed");
return loan.getCurrentLoan();
}
}],
clientData: ['loan', 'client', function (loan, client) {
//if page was refreshed query client and loan from database
if (window.localStorage.getItem("clientRefreshed") === 'true'
&& loan.getCurrentLoan() && client.getClientStore()) {
window.localStorage.removeItem("clientRefreshed");
return client.getClient();
} else {
//else query from local storage
window.localStorage.removeItem("clientRefreshed");
return client.getClientStore();
}
}]
}
})
.state('homepage',{
url: 'homepage.html',
templateUrl: 'homepage.html'
})
.state('loanApplication.account-creation', {
url: '/account-creation?loanAmount&loanPurpose&promoCode&r&e&c&p',
templateUrl: 'account-creation/account-creation-view.html',
controller: 'accountCreationController as accountCreationController',
loginRequirement: 'notRequired',
incompleteLoanApplication: 'required',
resolve: {
requiredDisclosures: ['loan', function (loan) {
return loan.getRequiredDisclosures('account-creation');
}]
}
})
.state('loanApplication', {
parent: 'root',
templateUrl: 'loan-application/loan-application-view.html',
controller: 'loanApplicationController as loanApplicationController',
incompleteLoanApplication: 'required'
})
.state('loanDashboard', {
templateUrl: 'loan-dashboard/loan-dashboard.html',
controller: 'loanDashboardNavController as loanDashboardNavController'
})
.state('loanDashboard.myDashboard', {
url: '/my-dashboard?messages',
templateUrl: 'my-dashboard/my-dashboard.html',
controller: 'myDashboardController as myDashboardController'
})
.state('loanDashboard.myProfile', {
url: '/my-profile/:reason',
templateUrl: 'my-profile/my-profile.html',
controller: 'myProfileController as myProfileController'
})
.state('loanDashboard.makePayment', {
url: '/make-payment',
templateUrl: 'make-payment/make-payment.html',
controller: 'makePaymentController as makePaymentController'
})
.state('loanApplication.loanOptions', {
url: '/loan-options/:selectedOfferUnavailable',
templateUrl: 'loan-options/loan-options.html',
incompleteLoanApplication: 'required',
controller: 'loanOptionsController as loanOptionsController'
})
.state('loanApplication.verify', {
url: '/verify',
template: '<ui-view/>',
incompleteLoanApplication: 'required',
abstract: true
})
.state('loanApplication.verify.emailAddress', {
url: '/email-address',
templateUrl: 'verify/email/email-address.html',
incompleteLoanApplication: 'required',
controller: 'emailController as emailController'
})
.state('loanApplication.verify.knowledgeAssessment', {
url: '/knowledge-assessment',
templateUrl: 'verify/knowledge-assessment/knowledge-assessment.html',
incompleteLoanApplication: 'required',
controller: 'knowledgeAssessmentController as knowledgeAssessmentController',
loginRequirement: 'notRequired'
})
.state('loanApplication.verify.income', {
url: '/income',
template: '<ui-view />',
incompleteLoanApplication: 'required',
abstract: true
})
.state('loanApplication.verify.income.automatic', {
url: '/automatic',
templateUrl: 'verify/income/automatic.html',
incompleteLoanApplication: 'required',
controller: 'incomeSummaryController as incomeSummaryController'
})
.state('loanApplication.verify.income.choose', {
url: '/choose',
templateUrl: 'verify/income/choose.html',
incompleteLoanApplication: 'required',
controller: 'incomeSummaryController as incomeSummaryController'
})
.state('loanApplication.verify.income.decisionLogic', {
url: '/decision-logic',
templateUrl: 'verify/income/decision-logic.html',
incompleteLoanApplication: 'required',
controller: 'incomeSummaryController as incomeSummaryController'
})
.state('loanApplication.verify.income.manual', {
url: '/manual',
templateUrl: 'verify/income/manual.html',
incompleteLoanApplication: 'required',
controller: 'incomeSummaryController as incomeSummaryController'
})
.state('loanApplication.verify.doc.pending', {
url: '/pending',
templateUrl: 'verify/doc-pending/doc-verify-pending.html',
incompleteLoanApplication: 'required',
controller: 'docPendingController as docPendingController'
})
.state('loanApplication.verify.bank', {
url: '/bank',
templateUrl: 'verify/bank/bank.html',
incompleteLoanApplication: 'required',
controller: 'verifyBankController as verifyBankController',
resolve: {
requiredDisclosures: ['loan', function (loan) {
return loan.getRequiredDisclosures('bank-verification');
}]
}
})
.state('loanApplication.verify.debit', {
url: '/debit',
templateUrl: 'verify/debit/debit.html',
incompleteLoanApplication: 'required',
confirmedPayMethod: 'required',
controller: 'debitController as debitController'
})
.state('loanApplication.verify.identity', {
url: '/identity',
templateUrl: 'verify/identity/identity-document.html',
controller: 'identityDocumentController as identityDocumentController',
incompleteLoanApplication: 'required'
})
.state('loanApplication.verify.complete', {
url: '/complete',
incompleteLoanApplication: 'required',
templateUrl: 'verify/verify-complete.html'
})
.state('loanApplication.loanOverview',{
url: '/loan-overview',
templateUrl: 'loan-overview/loan-overview.html',
controller: 'loanOverviewController as loanOverviewController',
incompleteLoanApplication: 'required'
})
.state('loanApplication.loanAgreement', {
url: '/loan-agreement',
templateUrl: 'loan-agreement/loan-agreement.html',
controller: 'loanAgreementController as loanAgreementController',
incompleteLoanApplication: 'required',
confirmedPayMethod: 'required',
confirmedId: 'required',
resolve: {
requiredDisclosures: ['loan', function (loan) {
return loan.getRequiredDisclosures('loan-acceptance');
}]
}
})
.state('loanApplication.approved', {
url: '/loan-approved',
templateUrl: 'loan-approved/loan-approved.html',
controller: 'loanApprovedController as loanApprovedController',
})
.state('sorry', {
parent: 'root',
url: '/sorry',
templateUrl: 'sorry/sorry.html',
controller: 'sorryController as sorryController',
loginRequirement: "notRequired",
params: {
reasons: null
}
})
.state('login', {
url: '/login?forceLogout&reason&gonext&goTo',
templateUrl: 'login/login-view.html',
controller: 'loginController as loginController',
loginRequirement: 'notRequired'
})
.state('password-reset', {
url: '/password-reset?u&k',
templateUrl: 'password-reset/password-reset.html',
controller: 'passwordResetController as passwordResetController',
loginRequirement: 'notRequired'
})
.state('our-process', {
url: '/our-process',
templateUrl: 'static/our-process.html',
loginRequirement: 'notRequired'
})
.state('sign-out', {
url: '/sign-out',
templateUrl: 'static/sign-out.html',
loginRequirement: 'notRequired'
})
.state('family-of-companies', {
url: '/family-of-companies',
templateUrl: 'foc/family-of-companies.html',
loginRequirement: 'notRequired',
controller: 'focController as focController'
})
.state('learn-more', {
url: '/learn-more',
templateUrl: 'static/learn-more.html',
loginRequirement: 'notRequired'
})
.state('personal-loan-uses', {
url: '/personal-loan-uses',
templateUrl: 'static/personal-loan-uses/personal-loan-uses.html',
loginRequirement: 'notRequired'
})
.state('personal-loan-uses.debt-consolidation', {
url: '/debt-consolidation',
templateUrl: 'static/personal-loan-uses/debt-consolidation.html',
loginRequirement: 'notRequired'
})
.state('personal-loan-uses.home-improvement', {
url: '/home-improvement',
templateUrl: 'static/personal-loan-uses/home-improvement.html',
loginRequirement: 'notRequired'
})
.state('personal-loan-uses.medical-expense', {
url: '/medical-expense',
templateUrl: 'static/personal-loan-uses/medical-expense.html',
loginRequirement: 'notRequired'
})
.state('personal-loan-uses.small-business', {
url: '/small-business',
templateUrl: 'static/personal-loan-uses/small-business.html',
loginRequirement: 'notRequired'
})
.state('personal-loan-uses.auto', {
url: '/auto',
templateUrl: 'static/personal-loan-uses/auto.html',
loginRequirement: 'notRequired'
})
.state('personal-loan-uses.other', {
url: '/other',
templateUrl: 'static/personal-loan-uses/other.html',
loginRequirement: 'notRequired'
})
.state('about-us', {
url: '/about-us',
templateUrl: 'static/about-us.html',
loginRequirement: 'notRequired',
controller: 'aboutUsController as aboutUsController'
})
.state('team-member-refer', {
url: '/team-member-refer',
templateUrl: 'team-member-refer/team-member-refer.html',
loginRequirement: 'notRequired',
controller: 'teamMemberReferController as teamMemberReferController',
})
.state('loan-calculator', {
url: '/loan-calculator',
templateUrl: 'loan-calculator/loan-calculator.html',
loginRequirement: 'notRequired',
controller: 'loanCalculatorController as loanCalculatorController'
})
.state('terms-of-service', {
url: '/terms-of-service',
templateUrl: 'static/terms-of-service.html',
loginRequirement: 'notRequired'
})
.state('privacy-policy', {
url: '/privacy-policy',
templateUrl: 'static/privacy-policy.html',
loginRequirement: 'notRequired'
})
.state('faq', {
url: '/faq',
templateUrl: 'static/faq.html',
loginRequirement: 'notRequired',
controller: 'faqController as faqController'
})
.state('fees', {
url: '/fees',
templateUrl: 'static/fees.html',
loginRequirement: 'notRequired'
})
.state('404', {
url: '*path',
templateUrl: 'static/404.html',
loginRequirement: 'notRequired'
})
}])
.config(['xtFormConfigProvider', function (xtFormConfigProvider) {
xtFormConfigProvider.setDefaultValidationStrategy('focusedAndDirtyOrSubmitted');
xtFormConfigProvider.addValidationStrategy('accountCreationStrategy', function (form, ngModel) {
if (ngModel.$name === 'password') {
return xtFormConfigProvider.$validationStrategies.focusedAndDirtyOrSubmitted(form, ngModel);
}
return form.$invalid && form.$submitted && ngModel.$focused;
});
}])
.config(['$provide', function ($provide) {
$provide.decorator('$state', ['$delegate', function ($delegate) {
var originalTransitionTo = $delegate.transitionTo;
$delegate.transitionTo = function (to, toParams, options) {
return originalTransitionTo(to, toParams, angular.extend({
reload: true
}, options));
};
return $delegate;
}]);
$provide.decorator('carouselDirective', ['$delegate', function ($delegate) {
var directive = $delegate[0];
directive.templateUrl = "templates/carousel.tpl.html";
return $delegate;
}]);
$provide.decorator('daypickerDirective', ['$delegate', function ($delegate) {
var directive = $delegate[0];
directive.templateUrl = "templates/datepicker/day.tpl.html";
return $delegate;
}]);
}])
.config(["IdleProvider", function (IdleProvider) {
IdleProvider.idle(20 * 60);
IdleProvider.timeout(false);
}])
.run(["Idle", "Keepalive", "$rootScope", "$state", "AuthStateFactory", function (Idle, Keepalive, $rootScope, $state, auth) {
Idle.watch();
Keepalive.stop();
$rootScope.$on("IdleStart", function () {
if (auth.check()) {
auth.logout()
.then(function () {
$state.go("login");
}, function (error) {
$state.go("login");
});
}
});
}])
.config(["$httpProvider", function ($httpProvider) {
$httpProvider.interceptors.push("sessionInterceptor");
$httpProvider.interceptors.push("invalidClientInterceptor");
$httpProvider.interceptors.push("invalidSelectedOfferInterceptor");
$httpProvider.interceptors.push("invalidLoanInterceptor");
}]);
//handle page refresh
window.onbeforeunload = function () {
if (window.localStorage.getItem("client") && window.localStorage.getItem("currentLoan")) {
window.localStorage.setItem("clientRefreshed", true);
window.localStorage.setItem("loanRefreshed", true);
}
};