(function () { "use strict"; var app = angular.module("fgcMain", ["common.services", "ui.router", "ngMessages", "ngFileUpload", "ngSanitize", "summernote", "ngCookies"]); //Factories - START app.factory('authInterceptor', function ($rootScope, $q, $window, $cookies, $cookieStore) { return { request: function (config) { config.headers = config.headers || {}; if ($window.sessionStorage.token) { config.headers.Authorization = $window.sessionStorage.token; config.headers["Auth-Token"] = $window.sessionStorage.token; } else { var mToken = $cookieStore.get('token'); if (mToken) { config.headers.Authorization = mToken; config.headers["Auth-Token"] = mToken; } } return config; }, response: function (response) { if (response.status === 401) { // handle the case where the user is not authenticated } return response || $q.when(response); } }; }); app.factory('CommonCode', function ($sce, $rootScope, $state) { var root = {}; root.renderHtml = function (htmlCode) { return $sce.trustAsHtml(htmlCode); }; root.displaySentMessage = false; root.isLoggin = false; root.nextStateAfterLogin = ''; root.authToken = ''; root.prepForBroadcast = function (msg) { this.isLoggin = msg; this.broadcastItem(); }; root.supportAjaxUploadProgressEvents = function () { var xhr = new XMLHttpRequest(); return !!(xhr && ('upload' in xhr) && ('onprogress' in xhr.upload)); }; root.broadcastItem = function () { $rootScope.$broadcast('member-authentication', {isLoggin : this.isLoggin}); }; root.broadcastLoggedout = function () { $rootScope.$broadcast('member-loggedout', { isLoggin: this.isLoggin }); }; root.IsForbiddenRequest = function (error) { if (error.status === 403) { this.nextStateAfterLogin = $state.$current; $state.go('loginPage'); return true; } return false; }; root.RedirectNextStateAfterLogin = function (forceState) { if (forceState) { $state.go(forceState); return; } if (this.nextStateAfterLogin) { var tempNextStateAfterLogin = this.nextStateAfterLogin; this.nextStateAfterLogin = ''; $state.go(tempNextStateAfterLogin); return; } else { $state.go('messagesPage'); return; } }; root.Redirect = function (page, params) { $state.go(page, params); }; root.RedirectForceState = function (data) { if ((data) && (!data.success)) { if (data.forcePasswordRenew) { $state.go('changePasswordPage'); return true; } } }; root.HandleErrorOnAction = function (status) { var retVal = ''; if (status === 403) { retVal = sessionExpiredErrorText; } else { retVal = connectionGeneralErrorText; } return retVal; }; root.SetAuthToken = function (authToken) { this.authToken = authToken; }; root.GetAuthToken = function () { return this.authToken; }; root.SetDisplaySentMessage = function (value) { this.displaySentMessage = value; }; root.GetDisplaySentMessage = function () { return this.displaySentMessage; }; root.LogoutAction = function () { this.broadcastLoggedout(); var retVal = 'Index.aspx?action=logout&authToken=' + this.authToken; window.location = retVal; }; return root; }); //Factories - END app.config(["$stateProvider", "$urlRouterProvider", "$locationProvider", function ($stateProvider, $urlRouterProvider, $locationProvider) { $stateProvider.state("loginWithEmailPage", { name: "loginWithEmail", url: "/login/:email", templateUrl: "MemberLoginPage.html", controller: "LoginCtrl", params: { email: null } }) .state("loginPage", { name: "login", url: "/login", templateUrl: "MemberLoginPage.html", controller: "LoginCtrl" }) .state("errorPage", { url: "/error", templateUrl: "MemberErrorPage.html", controller: "ErrorCtrl" }) .state("filesAreaPage", { url: "/filesArea", templateUrl: "MemberFilesAreaPage.html", controller: "FilesCtrl" }) .state("uploadFilesAreaPage", { url: "/uploadFiles", templateUrl: "MemberUploadFilesPage.html", controller: "UploadFilesCtrl" }) .state("changePasswordPage", { url: "/changePassword", templateUrl: "MemberChangePasswordPage.html", controller: "ChangePasswordCtrl" }) .state("resetPasswordPage", { url: "/resetPassword", templateUrl: "MemberResetPasswordPage.html", controller: "ResetPasswordCtrl" }) .state("signUpPage", { url: "/signUp", templateUrl: "MemberSignUpPage.html", controller: "SignUpCtrl" }) .state("personalInfoPage", { url: "/personalInfo", templateUrl: "MemberEditPersonalInfoPage.html", controller: "EditPersonalInfoCtrl" }) .state("messagesPage", { url: "/messages", templateUrl: "MemberMessagesPage.html", controller: "MessagesCtrl" }) .state("conversationPage", { url: "/conversation?enquiryId&oet&oeid&mid", templateUrl: "MemberConversationPage.html", controller: "ConversationCtrl" }) .state("notificationsPage", { url: "/notifications", templateUrl: "MemberNotificationsPage.html", controller: "NotificationsCtrl" }) .state("medicalInformationPage", { url: "/medicalInformation", templateUrl: "MemberMedicalInformationPage.html", controller: "MedicalInformationCtrl" }) .state("paymentsPage", { url: "/payments", templateUrl: "MemberPaymentsPage.html", controller: "PaymentsCtrl" }) .state("makePaymentPage", { url: "/makePayment/:leadId/:priceQuoteId", templateUrl: "MakePaymentPage" + paymentProvider +".html", controller: "MakePaymentCtrl", params: { 'leadId': null, 'priceQuoteId': null } }) .state("paymentConfirmationPage", { url: "/paymentConfirmation/:paymentId", templateUrl: "MemberPaymentConfirmationPage.html", controller: "PaymentConfirmationCtrl", params: { 'paymentId': null } }), //.state("logoutPage", { // url: "login/logout", // templateUrl: "MemberLoginPage.html", // controller: "LoginCtrl", // data: { 'action': 'logout' }, //}) // $locationProvider.html5Mode(true); $urlRouterProvider.otherwise("/login"); }] ); app.config(function ($httpProvider) { $httpProvider.interceptors.push('authInterceptor'); }); app.controller("MainCtrl", ["$scope", "$state", "$location", "$window", MainCtrl]); function MainCtrl($scope, $state, $location, $window) { $.uniform.defaults.fileDefaultHtml = uniform_fileDefaultHtml; $.uniform.defaults.fileButtonHtml = uniform_fileButtonHtml; $.uniform.defaults.resetDefaultHtml = uniform_resetDefaultHtml; $.uniform.defaults.submitDefaultHtml = uniform_submitDefaultHtml; if (isProduction === true) { $scope.$on('$viewContentLoaded', function (event) { $window.ga('send', 'pageview', { page: $location.url() }); }); } $scope.Init = function (state) { $state.go(state); } } //Directives - START app.directive('toolTip', ['$rootScope', function ($rootScope) { var controller = ['$scope', function ($scope) { $scope.hoverTooltipIn = function () { this.showToottip = true; }; $scope.hoverTooltipOut = function () { this.showToottip = false; }; }]; return { restrict: 'EA', //E = element, A = attribute, C = class, M = comment templateUrl: 'Tooltip.html', scope: { datasource: '=' }, link: function ($scope, element, attrs) { }, controller: controller } }]); app.directive('memberMessage', ['$rootScope' , '$timeout', '$window', 'CommonCode', function ($rootScope, $timeout, $window, CommonCode) { return { restrict: 'EA', //E = element, A = attribute, C = class, M = comment templateUrl: 'MemberMessage.html', scope: { message: '=', islast: '=', pricequote: '=', pricequotesmodel: '=', authtokenstr: '=', allowmemberpayment: '=', ordernowtext: '=', acceptpricequote: '&', declinepricequote: '&', makepayment: '&' }, link: function ($scope, element, attrs) { } , controller: function ($scope) { } } }]); app.directive('textBoxControl', ['$rootScope', '$timeout', '$window', 'CommonCode', function ($rootScope, $timeout, $window, CommonCode) { return { restrict: 'EA', //E = element, A = attribute, C = class, M = comment templateUrl: 'TextBoxControl.html', scope: { controldata: '=', servererrors: '=', formcontrol: '=', buttonclicked: '=', namec: '@', controlid: '@' }, require: '^form', link: function ($scope, element, attrs, formCtrl) { } , controller: function ($scope) { }, transclude: true } }]); app.directive('switchControl', ['$rootScope', '$timeout', '$window', 'CommonCode', function ($rootScope, $timeout, $window, CommonCode) { return { restrict: 'EA', //E = element, A = attribute, C = class, M = comment templateUrl: 'SwitchControl.html', scope: { controldata: '=', servererrors: '=', formcontrol: '=', buttonclicked: '=', namec: '@', controlid: '@' }, require: '^form', link: function (scope, element, attrs, formCtrl) { }, controller: function ($scope) { }, transclude: true } }]); app.directive('listControl', ['$rootScope', '$timeout', '$window', 'CommonCode', function ($rootScope, $timeout, $window, CommonCode) { return { restrict: 'EA', //E = element, A = attribute, C = class, M = comment templateUrl: 'ListControl.html', scope: { controldata: '=', servererrors: '=', formcontrol: '=', buttonclicked: '=', namec: '@', controlid: '@' }, require: '^form', link: function ($scope, element, attrs, formCtrl) { }, controller: function ($scope) { }, transclude: true } }]); var INTEGER_REGEXP = /^\-?\d+$/; app.directive('integer', function () { return { require: 'ngModel', link: function (scope, elm, attrs, ctrl) { ctrl.$validators.integer = function (modelValue, viewValue) { if (attrs.integer !== 'true') { return true; } if (ctrl.$isEmpty(modelValue)) { // consider empty models to be valid return true; } if (INTEGER_REGEXP.test(viewValue)) { // it is valid return true; } // it is invalid return false; }; } }; }); //The value from the server is string but the angluar expect number(float or int) app.directive('numberConverter', function () { return { priority: 1, restrict: 'A', require: 'ngModel', link: function (scope, element, attr, ngModel) { function toModel(value) { return "" + value; // convert to string } function toView(value) { return parseFloat(value); // convert to number } ngModel.$formatters.push(toView); ngModel.$parsers.push(toModel); } }; }); app.directive('addFilesBox', ['$rootScope', '$timeout', function ($rootScope, $timeout) { return { restrict: 'EA', //E = element, A = attribute, C = class, M = comment templateUrl: 'AddFilesBox.html', scope: { boxConfig: '=', fileInputConfig: '=', ngModel: '=' }, link: function ($scope, element, attrs) { //watch when fileInputConfig is updating from the server $scope.$watch('fileInputConfig', function (fileInputConfig) { if (fileInputConfig) {//first time the directive is init before the model data populate from the server $timeout(function () { // You might need this timeout to be sure its run after DOM render. $('.open-box-file').slideUp(); $('.box-add-file').slideDown(); $('select').msDropdown(); $timeout(function () { $('.close.fileinput-remove').click(function () { $('.open-box-file').slideDown(); $('.box-add-file').slideUp(); }) }, 10, false); $('.open-box-file').click(function () { $(this).slideUp(); $('.box-add-file').slideDown(); $('select').msDropdown(); //only after the control is displayed i can add function to it closing X icon //$('.close.fileinput-remove').click(function () { // $('.open-box-file').slideDown(); // $('.box-add-file').slideUp(); //}) }); $(".uploadFilesControl").fileinput({ language: fileInputConfig.LanguageCode, uploadUrl: fileInputConfig.UploadUrl, allowedFileExtensions: fileInputConfig.AllowedFileExtensions, dropZoneEnabled: false, overwriteInitial: false, showUpload: false, showRemove: false, maxFileSize: fileInputConfig.MaxFileSize, maxFilesNum: fileInputConfig.MaxFileCount, uploadExtraData: function () { return { categorieId: $(".uploadFilesCategoriesList").val() }; }, slugCallback: function (filename) { return filename.replace('(', '_').replace(']', '_'); } }); }, 10, false); } }); } //DOM manipulation } }]); //Directives - END //Filters - START app.filter('htmlToPlaintext', function () { return function (text) { return text ? String(text).replace(/<[^>]+>/gm, '') : ''; }; } ); app.filter('trustAsHTML', ['$sce', function ($sce) { return function (text) { return $sce.trustAsHtml(text); }; }]); //Filters - END }()); (function () { "use strict"; angular.module("common.services", ["ngResource"]); }()); (function () { "use strict"; angular.module("common.services").factory("errorResource", ["$resource", errorResource]); function errorResource($resource) { return $resource("/Members/errors/:id"); } }()); (function () { "use strict"; angular.module("fgcMain").controller("ErrorCtrl", ["errorResource", "$scope", ErrorCtrl]); function ErrorCtrl(errorResource, $scope) { var vm = this;//view model errorResource.get({ id: 404}).$promise.then(function (data) { $scope.MemberErrorModel = data.toJSON(); vm.afterLoadPage(); }, function (error) { }); vm.afterLoadPage = function (error) { }; } }()); (function () { "use strict"; angular.module("common.services").factory("footerResource", ["$resource", footerResource]); function footerResource($resource) { return $resource("/Members/footer"); } }()); (function () { "use strict"; angular.module("fgcMain").controller("FooterCtrl", ["footerResource", "$scope", "$rootScope", "$timeout", FooterCtrl]); function FooterCtrl(footerResource, $scope, $rootScope, $timeout) { var vm = this;//view model vm.LoadFooter = function () { footerResource.get().$promise.then(function (data) { $scope.MemberFooterModel = data.toJSON(); vm.afterLoadPage(); }, function (error) { }); }; vm.LoadFooter(); vm.afterLoadPage = function (error) { }; $rootScope.$on('member-loggedout', function (event, args) { $timeout(function () { vm.LoadFooter(); }, 0); }); $rootScope.$on('member-authentication', function (event, args) { $timeout(function () { vm.LoadFooter(); }, 0); }); } }()); (function () { "use strict"; angular.module("common.services").factory("headerResource", ["$resource", headerResource]); function headerResource($resource) { return $resource("/Members/header"); } }()); (function () { "use strict"; angular.module("fgcMain").controller("HeaderCtrl", ["headerResource", "$scope", "$state", "$rootScope", "CommonCode", "$timeout", HeaderCtrl]); function HeaderCtrl(headerResource, $scope, $state, $rootScope, CommonCode, $timeout) { var vm = this;//view model vm.LoadHeader = function () { headerResource.get().$promise.then(function (data) { $rootScope.MemberHeaderModel = data.toJSON(); vm.afterLoadPage(); }, function (error) { }); }; vm.LoadHeader(); $scope.isActive = function (itemName) { if (itemName == $state.$current) { return true; } return false; }; vm.LogoutAction = function () { CommonCode.LogoutAction(); vm.LoadHeader(); }; $scope.reloadRoute = function () { $state.reload(); }; $rootScope.$on('member-authentication', function (event, args) { $timeout(function () { $rootScope.MemberHeaderModel.DisplayLogin = !args.isLoggin; $rootScope.MemberHeaderModel.DisplaySignUp = !args.isLoggin; $rootScope.$apply(); }, 0); }); vm.afterLoadPage = function (error) { $('.ico-mnmb').click(function () { if ($('.nav-menu-mb ul').css('display') == 'none') { $(this).addClass('active'); $('.nav-menu-mb ul').slideDown(); } else { $(this).removeClass('active'); $('.nav-menu-mb ul').slideUp(); } }); $('.nav-menu-mb').click(function () { if ($('.nav-menu-mb ul').css('display') !== 'none') { $(this).removeClass('active'); $('.nav-menu-mb ul').slideUp(); } }); $('.size1').on('click', function () { $('#content').css('font-size', "12px"); }); $('.size2').on('click', function () { $('#content').css('font-size', "14px"); }); $('.size3').on('click', function () { $('#content').css('font-size', "16px"); }); $('.nav-menu li a').each(function () { $(this).css({ 'padding-left': 0, 'padding-right': 0, 'width': $(this).outerWidth() }); }); $('.menu-user > li.setting').click(function(event) { event.stopPropagation(); var $this = $(this); if ($this.hasClass('active')) { $this.removeClass('active'); } else { $this.addClass('active'); } }); $('html, body').click(function() { $('.menu-user > li.setting').removeClass('active'); }); }; } }()); (function () { "use strict"; angular.module("common.services").factory("loginResource", ["$resource", loginResource]); function loginResource($resource) { return $resource("/Members/login/:email"); } }()); (function () { "use strict"; angular.module("fgcMain").controller("LoginCtrl", ["loginResource", "$scope", "$rootScope", "$http", "$window", "$cookieStore", "CommonCode", "$stateParams", LoginCtrl]); function LoginCtrl(loginResource, $scope, $rootScope, $http, $window, $cookieStore, CommonCode, $stateParams, MainCtrl) { var vm = this;//view model $scope.buttonClicked = false; loginResource.get({ email: $stateParams.email }).$promise.then(function (data) { $scope.MemberLoginModel = data.toJSON(); vm.afterLoadPage(); }, function (error) { $scope.ConnectionGeneralErrorText = connectionGeneralErrorText; }); vm.afterLoadPage = function (error) { }; $scope.login = function () { $scope.buttonClicked = true; $scope.ConnectionGeneralErrorText = ''; $scope.MemberLoginModel.ServerErrors = ''; if ($scope.memberLoginForm.$valid) { $http.post('/Members/Account/login', $scope.MemberLoginModel.LoginAttemptModel). success(function (data, status, headers, config) { $scope.memberLoginForm.$setPristine(); if (data.success == true) { CommonCode.prepForBroadcast(true); $window.sessionStorage.token = data.tokenId; //commenData.autoToken = $window.sessionStorage.token; $scope.autoToken = data.tokenId; $cookieStore.put('token', data.tokenId); CommonCode.SetAuthToken(data.tokenId); $rootScope.MemberHeaderModel.MemberDisplayName = data.memberDisplayName; //redirect to page var forceState = data.forcePasswordRenew ? 'changePasswordPage' : ''; CommonCode.RedirectNextStateAfterLogin(forceState); } else { CommonCode.prepForBroadcast(false); $scope.MemberLoginModel.ServerErrors = data.messages; } }). error(function (data, status, headers, config) { $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); }); } }; } }()); (function () { "use strict"; angular.module("common.services").factory("filesResource", ["$resource", filesResource]); function filesResource($resource) { return $resource("/Members/files/"); } }()); (function () { "use strict"; var app = angular.module("fgcMain").directive('onLastRepeat', function () { return function (scope, element, attrs) { if (scope.$last) setTimeout(function () { scope.$emit('onRepeatLast', element, attrs); }, 1); }; }).controller("FilesCtrl", ["filesResource", "$scope", "$window", "CommonCode", FilesCtrl]); function FilesCtrl(filesResource, $scope, $window, CommonCode) { var vm = this;//view model filesResource.get().$promise.then(function (data) { if (CommonCode.RedirectForceState(data)) { return; } $scope.MemberFilesAreaModel = data.toJSON(); vm.afterLoadPage(); }, function (error, status) { if (!CommonCode.IsForbiddenRequest(error)) { $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); } }); $scope.autoToken = $window.sessionStorage.token; //this came to solve the problem that i need to run the jquery only after $scope.$on('onRepeatLast', function (scope, element, attrs) { var className = attrs.onLastRepeat; if (className == 'files-table') { if ($('.list-files').length > 0) { $('.list-files').footable({ breakpoints: { phone: 690, tablet: 1024 } }); } } else { $('.' + className + ' select').msDropdown(); } }); vm.afterLoadPage = function (error) { }; } }()); (function () { "use strict"; var app = angular.module("fgcMain").directive('onLastRepeat', function () { return function (scope, element, attrs) { if (scope.$last) setTimeout(function () { scope.$emit('onRepeatLast', element, attrs); }, 1); }; }).controller("UploadFilesCtrl", ["uploadFilesResource", "$scope", "CommonCode", UploadFilesCtrl]); function UploadFilesCtrl(uploadFilesResource, $scope, CommonCode) { var vm = this;//view model uploadFilesResource.get().$promise.then(function (data) { if (CommonCode.RedirectForceState(data)) { return; } $scope.MemberUploadFilesModel = data.toJSON(); vm.afterLoadPage($scope.MemberUploadFilesModel.UploadFilesControlConfig); }, function (error, status) { if (!CommonCode.IsForbiddenRequest(error)) { //handle on error $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); } }); //this came to solve the problem that i need to run the jquery only after the angular databinding - otherwise some controls will not init them self properly. $scope.$on('onRepeatLast', function (scope, element, attrs) { $('.' + attrs.onLastRepeat + ' select').msDropdown(); }); vm.afterLoadPage = function (config) { $scope.supportAjaxUploadProgressEvents = CommonCode.supportAjaxUploadProgressEvents(); $(".uploadFilesControl").fileinput({ language: config.LanguageCode, uploadUrl: config.UploadUrl, allowedFileExtensions: config.AllowedFileExtensions, overwriteInitial: false, maxFileSize: config.MaxFileSize, maxFilesNum: config.MaxFileCount, uploadExtraData: function () { return { categorieId: $(".uploadFilesCategoriesList").val() }; }, slugCallback: function (filename) { return filename.replace('(', '_').replace(']', '_'); } }); }; } }()); (function () { "use strict"; angular.module("common.services").factory("uploadFilesResource", ["$resource", uploadFilesResource]); function uploadFilesResource($resource) { return $resource("/Members/uploadFiles/"); } }()); (function () { "use strict"; angular.module("fgcMain").controller("ChangePasswordCtrl", ["changePasswordResource", "$scope", "$timeout", "$http", "CommonCode", ChangePasswordCtrl]); function ChangePasswordCtrl(changePasswordResource, $scope, $timeout, $http, CommonCode) { var vm = this; $scope.buttonClicked = false; changePasswordResource.get().$promise.then(function (data) { $scope.MemberChangePasswordModel = data.toJSON(); vm.afterLoadPage(); }, function (error) { if (!CommonCode.IsForbiddenRequest(error)) { $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); } }); vm.afterLoadPage = function (error) { }; $scope.changePassword = function () { $scope.buttonClicked = true; $scope.MemberChangePasswordModel.SuccessMessage = ''; $scope.ConnectionGeneralErrorText = ''; $scope.MemberChangePasswordModel.ServerErrors = ''; if ($scope.memberChangePasswordForm.$valid) { $('.view-content').addClass('waiting'); $scope.isProcessing = true; $http.post('/Members/Account/changePassword', $scope.MemberChangePasswordAttemptModel). success(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.memberChangePasswordForm.$setPristine(); if (data.success == true) { $scope.MemberChangePasswordModel.SuccessMessage = data.messages; //$scope.MemberChangePasswordModel.FullRedirectMessageText = $scope.MemberChangePasswordModel.RedirectMessageText + ' ' + $scope.counter + ' ' + $scope.MemberChangePasswordModel.RedirectSecondsText; CommonCode.RedirectNextStateAfterLogin(); //var timeFunc = $timeout($scope.onTimeout, 1000); } else { $scope.MemberChangePasswordModel.ServerErrors = data.messages; } }). error(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); }); } }; } }()); (function () { "use strict"; angular.module("common.services").factory("changePasswordResource", ["$resource", changePasswordResource]); function changePasswordResource($resource) { return $resource("/Members/changePassword"); } }()); (function () { "use strict"; angular.module("fgcMain").directive('onLastRepeat', function () { return function (scope, element, attrs) { if (scope.$last) setTimeout(function () { scope.$emit('onRepeatLast', element, attrs); }, 1); }; }).controller("SignUpCtrl", ["signUpResource", "$scope", "$http", "$window", "$state", "$timeout", "$compile", "Upload", "CommonCode", SignUpCtrl]); function SignUpCtrl(signUpResource, $scope, $http, $window, $state, $timeout, $compile, Upload, CommonCode) { var vm = this;//view model $scope.buttonClicked = false; signUpResource.get().$promise.then(function (data) { $scope.MemberSignUpModel = data.toJSON(); vm.afterLoadPage(); }, function (error) { $scope.ConnectionGeneralErrorText = connectionGeneralErrorText; }); vm.afterLoadPage = function (error) { if ($('.check-login').length > 0) { $('.check-login input').uniform(); } if ($('.gder').length > 0) { $('.gder input').uniform(); } if ($('.ip-file').length > 0) { $('.ip-file input').uniform(); } vm.DateTimePickerInit($scope.MemberSignUpModel.DateTimePickerSettings); }; vm.DateTimePickerInit = function (dobSettings) { jQuery('.dateOfBirth').datetimepicker({ defaultTime: false, yearStart: dobSettings.YearStart, yearEnd: dobSettings.YearEnd, minDate: dobSettings.MinDate, maxDate: dobSettings.MaxDate, timepicker: false, datepicker: true, format: 'm/d/Y', clickInput: true, dateFormat: 'm/d/Y', lang: dobSettings.LanguageCode, }); }; $scope.$on('onRepeatLast', function (scope, element, attrs) { var className = attrs.onLastRepeat; $('.' + className + ' select').msDropdown(); }); $scope.onFileClick = function (file) { $('.filename').html(''); }; $scope.counter = 25; $scope.onTimeout = function () { $scope.counter--; if ($scope.counter <= 0) { $state.go('loginPage'); } else { $scope.MemberSignUpModel.FullRedirectMessageText = $scope.MemberSignUpModel.RedirectMessageText + ' ' + $scope.counter + ' ' + $scope.MemberSignUpModel.RedirectSecondsText; var timeFunc = $timeout($scope.onTimeout, 1000); } } $scope.signUp = function (file) { $scope.buttonClicked = true; $scope.MemberSignUpModel.SuccessMessage = ''; $scope.ConnectionGeneralErrorText = ''; $scope.MemberSignUpModel.ServerErrors = ''; if ($scope.memberSignUpForm.$valid) { $('.view-content').addClass('waiting'); $scope.isProcessing = true; var fileToTransfer = file != undefined ? file : null; var fileUploadAnswer = Upload.upload({ url: '/Members/Account/signup/', method: 'POST', data: $scope.MemberSignUpAttemptModel, file: fileToTransfer }).progress(function (evt) { // get upload percentage //console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total)); }).success(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.memberSignUpForm.$setPristine(); if (data.success == true) { $scope.MemberSignUpModel.SuccessMessage = data.messages; $scope.MemberSignUpModel.FullRedirectMessageText = $scope.MemberSignUpModel.RedirectMessageText + ' ' + $scope.counter + ' ' + $scope.MemberSignUpModel.RedirectSecondsText; var timeFunc = $timeout($scope.onTimeout, 1000); } else { $scope.MemberSignUpModel.ServerErrors = data.messages; } }).error(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); }); if (file != undefined) { file.upload = fileUploadAnswer; } } }; } }()); (function () { "use strict"; angular.module("common.services").factory("signUpResource", ["$resource", signUpResource]); function signUpResource($resource) { return $resource("/Members/signUp"); } }()); (function () { "use strict"; angular.module("fgcMain").directive('onLastRepeat', function () { return function (scope, element, attrs) { if (scope.$last) setTimeout(function () { scope.$emit('onRepeatLast', element, attrs); }, 1); }; }). controller("EditPersonalInfoCtrl", ["personalInfoResource", "$scope", "$rootScope", "$http", "$window", "$timeout", "$compile", "$state", "CommonCode", "Upload", EditPersonalInfoCtrl]); function EditPersonalInfoCtrl(personalInfoResource, $scope, $rootScope, $http, $window, $timeout, $compile, $state, CommonCode, Upload) { var vm = this;//view model $scope.buttonClicked = false; personalInfoResource.get().$promise.then(function (data) { if (CommonCode.RedirectForceState(data)) { return; } $scope.MemberEditPersonalInfoModel = data.toJSON(); vm.afterLoadPage(); }, function (error) { if (!CommonCode.IsForbiddenRequest(error)) { $scope.ConnectionGeneralErrorText = connectionGeneralErrorText; } }); vm.afterLoadPage = function (error) { if ($('.check-login').length > 0) { $('.check-login input').uniform(); } if ($('.ip-file').length > 0) { $('.ip-file input').uniform({ fileDefaultHtml: $scope.MemberEditPersonalInfoModel.SelectFileWatermark, fileButtonHtml: $scope.MemberEditPersonalInfoModel.SelectFileButtonText }); } vm.DateTimePickerInit($scope.MemberEditPersonalInfoModel.DateTimePickerSettings); setTimeout(function () { if ($('.gder').length > 0) { $('.gder input').uniform(); } if ($('.check-login').length > 0) { $('.check-login input').uniform(); } }, 300); }; vm.DateTimePickerInit = function (dobSettings) { jQuery('.dateOfBirth').datetimepicker({ defaultTime: false, yearStart: dobSettings.YearStart, yearEnd: dobSettings.YearEnd, minDate: dobSettings.MinDate, maxDate: dobSettings.MaxDate, timepicker: false, datepicker: true, format: 'm/d/Y', clickInput: true, dateFormat: 'm/d/Y', lang: dobSettings.LanguageCode, scrollInput: false, }); }; $scope.$on('onRepeatLast', function (scope, element, attrs) { var className = attrs.onLastRepeat; $('.' + className + ' select').msDropdown(); }); $scope.onFileClick = function (file) { $('.filename').html(''); }; $scope.editPersonalInfo = function (file) { $scope.buttonClicked = true; $scope.MemberEditPersonalInfoModel.SuccessMessage = ''; $scope.ConnectionGeneralErrorText = ''; $scope.MemberEditPersonalInfoModel.ServerErrors = ''; if ($scope.memberEditPersonalInfoForm.$valid) { $('.view-content').addClass('waiting'); $scope.isProcessing = true; var fileToTransfer = file != undefined ? file : null; var fileUploadAnswer = Upload.upload({ url: '/Members/Account/editPersonalInfo/', method: 'POST', data: $scope.MemberEditPersonalInfoModel.MemberEditPersonalInfoAttemptModel, file: fileToTransfer }).progress(function (evt) { // get upload percentage }).success(function (data, status, headers, config) { $scope.memberEditPersonalInfoForm.$setPristine(); $('.view-content').removeClass('waiting'); $scope.isProcessing = false; if (data.success == true) { //$scope.MemberEditPersonalInfoModel.MemberEditPersonalInfoAttemptModel.Password = ''; $timeout(function () { $scope.MemberEditPersonalInfoModel.SuccessMessage = data.messages; if (data.newMainPhotoUrl.length > 0) { $scope.MemberEditPersonalInfoModel.MemberEditPersonalInfoAttemptModel.MainPhotoUrl = data.newMainPhotoUrl + '&tt=' + new Date().getTime(); } $scope.$apply(); }, 0); //$scope.MemberEditPersonalInfoModel.MemberEditPersonalInfoAttemptModel.MainPhotoUrl = $scope.MemberEditPersonalInfoModel.MemberEditPersonalInfoAttemptModel.MainPhotoUrl + '&tt=' + new Date().getTime(); } else { $scope.MemberEditPersonalInfoModel.ServerErrors = data.messages; } }).error(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); }); if (file != undefined) { file.upload = fileUploadAnswer; } } }; } }()); (function () { "use strict"; angular.module("common.services").factory("personalInfoResource", ["$resource", personalInfoResource]); function personalInfoResource($resource) { return $resource("/Members/editPersonalInfo"); } }()); (function () { "use strict"; angular.module("fgcMain").controller("ResetPasswordCtrl", ["resetPasswordResource", "$scope", "$http", ResetPasswordCtrl]); function ResetPasswordCtrl(resetPasswordResource, $scope, $http) { var vm = this;//view model $scope.buttonClicked = false; resetPasswordResource.get().$promise.then(function (data) { $scope.MemberResetPasswordModel = data.toJSON(); vm.afterLoadPage(); }, function (error) { //handle on error $scope.ConnectionGeneralErrorText = connectionGeneralErrorText; }); vm.afterLoadPage = function (error) { }; $scope.resetPassword = function () { $scope.buttonClicked = true; $scope.MemberResetPasswordModel.SuccessMessage = ''; $scope.ConnectionGeneralErrorText = ''; $scope.MemberResetPasswordModel.ServerErrors = ''; if ($scope.memberResetPasswordForm.$valid) { $('.view-content').addClass('waiting'); $scope.isProcessing = true; $http.post('/Members/Account/resetPassword', $scope.MemberResetPasswordAttemptModel). success(function (data, status, headers, config) { $scope.memberResetPasswordForm.$setPristine(); $('.view-content').removeClass('waiting'); $scope.isProcessing = false; if (data.success == true) { $scope.MemberResetPasswordModel.SuccessMessage = data.messages; } else { $scope.MemberResetPasswordModel.ServerErrors = data.messages; } }). error(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.ConnectionGeneralErrorText = connectionGeneralErrorText; }); } }; } }()); (function () { "use strict"; angular.module("common.services").factory("resetPasswordResource", ["$resource", resetPasswordResource]); function resetPasswordResource($resource) { return $resource("/Members/resetPassword"); } }()); (function () { "use strict"; angular.module("fgcMain").controller("MessagesCtrl", ["messagesResource", "$scope", "$http", "$window", "CommonCode", MessagesCtrl]); function MessagesCtrl(messagesResource, $scope, $http, $window, CommonCode) { var vm = this; messagesResource.get().$promise.then(function (data) { if (CommonCode.RedirectForceState(data)) { return; } $scope.MemberMessagesModel = data.toJSON(); vm.afterLoadPage(); }, function (error, status) { if (!CommonCode.IsForbiddenRequest(error)) { $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); } }); $scope.autoToken = $window.sessionStorage.token; $scope.renderHtml = CommonCode.renderHtml; vm.afterLoadPage = function (error) { }; } }()); (function () { "use strict"; angular.module("common.services").factory("messagesResource", ["$resource", messagesResource]); function messagesResource($resource) { return $resource("/Members/messages"); } }()); (function () { "use strict"; angular.module("fgcMain").controller("ConversationCtrl", ["conversationResource", "$scope", "$rootScope", "$http", "$state", "$stateParams", "$timeout", "$window", "CommonCode", "Upload", ConversationCtrl]); function ConversationCtrl(conversationResource, $scope, $rootScope, $http, $state, $stateParams, $timeout, $window, CommonCode, Upload) { var vm = this; $scope.buttonClicked = false; $scope.priceQuoteClicked = false; $scope.summernoteOptions = { disableDragAndDrop: true, placeholder: summernotePlaceholder, height: 140, focus: true, airMode: false, toolbar: [ ['edit', ['undo', 'redo']], ['headline', ['style']], ['style', ['bold', 'italic', 'underline', 'clear']], ['fontface', []], ['textsize', ['fontsize']], ['fontclr', ['color']], ['alignment', ['ul', 'ol', 'paragraph']], ['height', ['height']], ['table', []], ['insert', []], ['view', []], ['help', []] ] }; conversationResource.get($stateParams).$promise.then(function (data) { if (CommonCode.RedirectForceState(data)) { return; } $scope.MemberConversationModel = data.toJSON(); if (($scope.MemberConversationModel.Messages == null) && ($scope.MemberConversationModel.Lead == null)) { $state.go('messagesPage'); } vm.afterLoadPage($scope.MemberConversationModel); }, function (error, status) { if (!CommonCode.IsForbiddenRequest(error)) { $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); } }); $scope.autoToken = $window.sessionStorage.token; //this came to solve the problem that i need to run the jquery only after the angular databinding - otherwise some controls will not init them self properly. $scope.$on('onRepeatLast', function (scope, element, attrs) { //$('.' + attrs.onLastRepeat + ' select').msDropdown(); }); $scope.renderHtml = CommonCode.renderHtml; $scope.GetAuthToken = CommonCode.GetAuthToken; $scope.supportAjaxUploadProgressEvents = true; vm.afterLoadPage = function (model) { if (CommonCode.GetDisplaySentMessage() == true) { CommonCode.SetDisplaySentMessage(false); $scope.DisplaySentMessage($scope.MemberConversationModel.SentMessageSuccessfully); } //Lead more info $('.more-intro').click(function () { $(this).hide(); $('.detail-intro').slideDown(); }); $('.hide-detail').click(function() { $('.detail-intro').slideUp(); $('.more-intro').show(); }); //expand\collapse messages $('.ms-expand').click(function() { ms_show_all(); }); $('.ms-collapse').click(function() { ms_hide(); }); $('.hide-expand').click(function() { ms_show(); }); $timeout(function () { $scope.supportAjaxUploadProgressEvents = CommonCode.supportAjaxUploadProgressEvents(); $scope.fileInputConfig = model.UploadFilesControlConfig; $scope.boxConfig = { Files_DragAndDrop: model.Files_DragAndDrop, Files_Category_Title: model.Files_Category_Title, CategoryDropDownItems: model.CategoryDropDownItems }; }, 0); }; $scope.AllMessagesExpand = function (messages, toExpand) { if (messages) { for (var i = 0; i < messages.length - 1; i++) { var currentItem = messages[i]; currentItem.IsExpand = toExpand; } } } $scope.MemberUpdatePriceQuoteAttemptModel = { LeadId: '', PriceQuoteId: '', Action: '' } $scope.PriceQuoteResponde = function (message, action) { $scope.ConnectionGeneralErrorText = ''; $scope.MemberConversationModel.ServerErrors = ''; $scope.MemberUpdatePriceQuoteAttemptModel.LeadId = message.EnquiryId; $scope.MemberUpdatePriceQuoteAttemptModel.PriceQuoteId = message.PriceQuote.Id; $scope.MemberUpdatePriceQuoteAttemptModel.Action = action; if (($scope.memberMessagesForm.$valid) && ($scope.priceQuoteClicked == false)) { //neet to check valition $('.view-content').addClass('waiting'); $scope.priceQuoteClicked = true; $http.post('/Members/PriceQuotes/MemberPriceQuoteRespond', $scope.MemberUpdatePriceQuoteAttemptModel). success(function (data, status, headers, config) { $scope.memberMessagesForm.$setPristine(); $scope.priceQuoteClicked = false; if (data.success == true) { //update price quote display for the message //go over all the messages with Price Quotes, file the current by id //update the dispaly: remove buttons and display only notification if (data.updatePriceQuoteResponse) { if (data.updatePriceQuoteResponse.ActionStatus == true) { $timeout(function () { for (var i = 0; i < $scope.MemberConversationModel.Messages.length; i++) { if ($scope.MemberConversationModel.Messages[i].MessageId == message.MessageId) { $scope.MemberConversationModel.Messages[i].PriceQuote.Status = data.updatePriceQuoteResponse.NewStatus; $scope.MemberConversationModel.Messages[i].PriceQuote.StatusText = data.updatePriceQuoteResponse.NewTextToDisplay; break; //Stop this loop, we found it! } } }, 0); } else { $timeout(function () { message.PriceQuote.ErrorText = data.updatePriceQuoteResponse.ErrorText; $scope.$apply(); }, 0); } } } else { $timeout(function () { message.PriceQuote.ErrorText = data.updatePriceQuoteResponse.ErrorText; $scope.memberMessagesForm.ServerErrors = data.messages; $scope.$apply(); }, 0); } $('.view-content').removeClass('waiting'); }). error(function (data, status, headers, config) { $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); $scope.priceQuoteClicked = false; $('.view-content').removeClass('waiting'); }); } }; $scope.makePayment = function (message) { var priceQuoteId = null; var leadId = null; if (message !== undefined) { if (message.PriceQuote !== undefined) { priceQuoteId = message.PriceQuote.Id; } leadId = message.EnquiryId; } CommonCode.Redirect('makePaymentPage', { 'leadId': leadId, 'priceQuoteId': priceQuoteId }); }; $scope.AcceptPriceQuote = function (message) { $scope.PriceQuoteResponde(message, 1); }; $scope.DeclinePriceQuote = function (message) { $scope.PriceQuoteResponde(message, 0); }; $scope.sendNewMessage = function (files, fileCategory) { if ($scope.memberConversationForm.$valid) { $('.view-content').addClass('waiting'); $scope.buttonClicked = true; $scope.isProcessing = true; $scope.ConnectionGeneralErrorText = ''; $scope.MemberConversationModel.ServerErrors = ''; $scope.MemberConversationModel.MemberNewMessageAttemptModel.AuthenticationCode = $scope.MemberConversationModel.AuthenticationCode; $scope.MemberConversationModel.MemberNewMessageAttemptModel.FileCategory = fileCategory; var fileToTransfer = files != undefined ? files : null; var fileUploadAnswer = Upload.upload({ url: '/Members/Conversation/sendNewMessage/', method: 'POST', data: $scope.MemberConversationModel.MemberNewMessageAttemptModel, file: files }).progress(function (evt) { // get upload percentage //console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total)); }).success(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.memberConversationForm.$setPristine(); if (data.success == true) { CommonCode.SetDisplaySentMessage(true); $state.reload(); } else { $scope.MemberConversationModel.ServerErrors = data.messages; } }).error(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); }); if (files != undefined) { files.upload = fileUploadAnswer; } } }; $scope.DisplaySentMessage = function DisplaySentMessage(messageText) { setTimeout(function () { $.notify({ // options animate: { enter: 'animated bounceIn', exit: 'animated bounceOut' }, message: messageText, icon: '' }, { // settings type: 'minimalist newMessageNotification', placement: { from: "top", align: "center" }, template: '', delay: 10000, }); }, 2000); } function ms_show_all() { $('.show-expand').show(); $('.ms-collapse').show(); $('.hide-expand').hide(); $('.ms-expand').hide(); } function ms_show() { $('.show-expand').show(); $('.ms-collapse').show(); $('.hide-expand').hide(); $('.ms-expand').hide(); } function ms_hide() { $('.show-expand').hide(); $('.ms-collapse').hide(); $('.hide-expand').show(); $('.ms-expand').show(); } } }()); (function () { "use strict"; angular.module("common.services").factory("conversationResource", ["$resource", "$stateParams", conversationResource]); function conversationResource($resource, $stateParams) { return $resource("/Members/conversation"); } }()); (function () { "use strict"; angular.module("fgcMain").directive('onLastRepeat', function () { return function (scope, element, attrs) { if (scope.$last) setTimeout(function () { scope.$emit('onRepeatLast', element, attrs); }, 1); }; }).controller("NotificationsCtrl", ["notificationsResource", "$scope", "$http", "CommonCode", NotificationsCtrl]); function NotificationsCtrl(notificationsResource, $scope, $http, CommonCode) { var vm = this;//view model notificationsResource.get().$promise.then(function (data) { $scope.MemberNotificationsModel = data.toJSON(); vm.afterLoadPage(); }, function (error, status) { if (!CommonCode.IsForbiddenRequest(error)) { //handle on error $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); } }); vm.afterLoadPage = function (error) { setTimeout(function () { if ($('.check-login').length > 0) { $('.check-login input').uniform(); } }, 300); }; $scope.$on('onRepeatLast', function (scope, element, attrs) { var className = attrs.onLastRepeat; $('.' + className + ' select').msDropdown(); }); $scope.notifications = function () { $scope.MemberNotificationsModel.SuccessMessage = ''; $scope.ConnectionGeneralErrorText = ''; $scope.MemberNotificationsModel.ServerErrors = ''; if ($scope.memberNotificationsForm.$valid) { $('.view-content').addClass('waiting'); $scope.isProcessing = true; $http.post('/Members/Account/notificationsSettings', $scope.MemberNotificationsModel.MemberNotificationsAttemptModel). success(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.memberNotificationsForm.$setPristine(); if (data.success == true) { $scope.MemberNotificationsModel.SuccessMessage = data.messages; } else { $scope.MemberNotificationsModel.ServerErrors = data.messages; } }). error(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); }); } }; } }()); (function () { "use strict"; angular.module("common.services").factory("notificationsResource", ["$resource", notificationsResource]); function notificationsResource($resource) { return $resource("/Members/notifications"); } }()); (function () { "use strict"; angular.module("fgcMain").directive('onLastRepeat', function () { return function (scope, element, attrs) { if (scope.$last) setTimeout(function () { scope.$emit('onRepeatLast', element, attrs); }, 1); }; }). controller("MedicalInformationCtrl", ["medicalInformationResource", "$scope", "$rootScope", "$http", "$window", "$timeout", "$compile", "$state", "CommonCode", "Upload", MedicalInformationCtrl]); function MedicalInformationCtrl(medicalInformationResource, $scope, $rootScope, $http, $window, $timeout, $compile, $state, CommonCode, Upload) { var vm = this;//view model $scope.buttonClicked = false; medicalInformationResource.get().$promise.then(function (data) { if (CommonCode.RedirectForceState(data)) { return; } $scope.MemberMedicalInformationModel = data.toJSON(); vm.afterLoadPage(); }, function (error) { if (!CommonCode.IsForbiddenRequest(error)) { $scope.ConnectionGeneralErrorText = connectionGeneralErrorText; } }); vm.afterLoadPage = function (error) { if ($('.check-login').length > 0) { $('.check-login input').uniform(); } if ($('.ip-file').length > 0) { $('.ip-file input').uniform(); } setTimeout(function () { if ($('.gder').length > 0) { $('.gder input').uniform(); } if ($('.check-login').length > 0) { $('.check-login input').uniform(); } //for the measurment system //$(".setting-switch").bootstrapSwitch(); $(".external-insurance-status .setting-switch").bootstrapSwitch({ onSwitchChange: function (event, state) { $scope.$apply(function() { $scope.MemberMedicalInformationModel.ExternalInsuranceStatusSwitchModel.IndeterminateState = false; $scope.MemberMedicalInformationModel.ExternalInsuranceStatusSwitchModel.Checked = state; }); } }); $(".smoking-status .setting-switch").bootstrapSwitch({ onSwitchChange: function (event, state) { $scope.$apply(function () { $scope.MemberMedicalInformationModel.SmokingStatusSwitchModel.IndeterminateState = false; $scope.MemberMedicalInformationModel.SmokingStatusSwitchModel.Checked = state; }); } }); $(".measurement-system .setting-switch").bootstrapSwitch({ onSwitchChange: function (event, state) { $scope.$apply(function () { $scope.MemberMedicalInformationModel.MeasurementSystemSwitchModel.IndeterminateState = false; $scope.MemberMedicalInformationModel.MeasurementSystemSwitchModel.Checked = state; }); } }); }, 300); }; $scope.$on('onRepeatLast', function (scope, element, attrs) { var className = attrs.onLastRepeat; $('.' + className + ' select').msDropdown(); }); $scope.saveMedicalInformation = function (file) { $scope.buttonClicked = true; $scope.MemberMedicalInformationModel.SuccessMessage = ''; $scope.ConnectionGeneralErrorText = ''; $scope.MemberMedicalInformationModel.ServerErrors = ''; $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.HeightCm = $scope.MemberMedicalInformationModel.HeightCmTextBoxModel.Value; $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.HeightFeet = $scope.MemberMedicalInformationModel.HeightFeetTextBoxModel.Value; $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.HeightInches = $scope.MemberMedicalInformationModel.HeightInchesTextBoxModel.Value; $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.WeightKg = $scope.MemberMedicalInformationModel.WeightKgTextBoxModel.Value; $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.WeightLbs = $scope.MemberMedicalInformationModel.WeightLbsTextBoxModel.Value; $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.WeightOz = $scope.MemberMedicalInformationModel.WeightOzTextBoxModel.Value; $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.ExternalInsuranceCompanyName = $scope.MemberMedicalInformationModel.ExternalInsuranceCompanyNameTextBoxModel.Value; if ($scope.MemberMedicalInformationModel.SmokingStatusSwitchModel.IndeterminateState == true) { $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.SmokingStatus = -1; } else { $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.SmokingStatus = $scope.MemberMedicalInformationModel.SmokingStatusSwitchModel.Checked == true ? 1 : 0; } if ($scope.MemberMedicalInformationModel.ExternalInsuranceStatusSwitchModel.IndeterminateState == true) { $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.ExternalInsuranceStatus = -1; } else { $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.ExternalInsuranceStatus = $scope.MemberMedicalInformationModel.ExternalInsuranceStatusSwitchModel.Checked == true ? 1 : 0; } if ($scope.MemberMedicalInformationModel.MeasurementSystemSwitchModel.IndeterminateState == true) { $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.MeasurementSystem = -1; } else { $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.MeasurementSystem = $scope.MemberMedicalInformationModel.MeasurementSystemSwitchModel.Checked == true ? 1 : 0; } $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel.BloodType = $scope.MemberMedicalInformationModel.BloodTypeListModel.Value; if ($scope.memberMedicalInformationForm.$valid) { $('.view-content').addClass('waiting'); $scope.isProcessing = true; $http.post('/Members/Account/updateMedicalInformation', $scope.MemberMedicalInformationModel.MemberMedicalInformationAttemptModel). success(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.memberMedicalInformationForm.$setPristine(); if (data.success == true) { $scope.MemberMedicalInformationModel.SuccessMessage = data.messages; } else { $scope.ConnectionGeneralErrorText = data.message; } }). error(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); }); } }; } }()); (function () { "use strict"; angular.module("common.services").factory("medicalInformationResource", ["$resource", medicalInformationResource]); function medicalInformationResource($resource) { return $resource("/Members/medicalInformation"); } }()); (function () { "use strict"; var app = angular.module("fgcMain").directive('onLastRepeat', function () { return function (scope, element, attrs) { if (scope.$last) setTimeout(function () { scope.$emit('onRepeatLast', element, attrs); }, 1); }; }).controller("PaymentsCtrl", ["paymentsResource", "$scope", "$http", "$window", "$timeout", "CommonCode", PaymentsCtrl]); function PaymentsCtrl(paymentsResource, $scope, $http, $window, $timeout, CommonCode) { var vm = this; $scope.isProcessing = false; paymentsResource.get().$promise.then(function (data) { if (CommonCode.RedirectForceState(data)) { return; } $scope.MemberPaymentsModel = data.toJSON(); vm.afterLoadPage(); }, function (error, status) { if (!CommonCode.IsForbiddenRequest(error)) { $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); } }); $scope.autoToken = $window.sessionStorage.token; //this came to solve the problem that i need to run the jquery only after $scope.$on('onRepeatLast', function (scope, element, attrs) { var className = attrs.onLastRepeat; if (className === 'payments-table') { if ($('.list-payment').length > 0) { $('.list-payment').footable({ breakpoints: { phone: 690, tablet: 1024 } }); } } else { $('.' + className + ' select').msDropdown(); } }); vm.afterLoadPage = function (error) { }; $scope.MemberRequestRefundAttemptModel = { PaymentId: '', RefundReasonText: '' }; $scope.memberRequestRefund = function (payment) { $scope.buttonClicked = true; $scope.MemberPaymentsModel.SuccessMessage = ''; $scope.ConnectionGeneralErrorText = ''; $scope.MemberPaymentsModel.ServerErrors = ''; if ($scope.memberPaymentsForm.$valid && $scope.isProcessing === false) { $('.view-content').addClass('waiting'); $scope.isProcessing = true; $scope.MemberRequestRefundAttemptModel.PaymentId = payment.PaymentId; $http.post('/Members/Payments/memberRequestRefund', $scope.MemberRequestRefundAttemptModel).success( function (data, status, headers, config) { $scope.memberPaymentsForm.$setPristine(); $('.view-content').removeClass('waiting'); $scope.isProcessing = false; if (data.success === true) { $timeout(function () { payment.RefundStatus = data.memberRequestRefundResponse.NewRefundRequestStatus; payment.RefundStatusText = data.memberRequestRefundResponse.NewRefundRequestStatusText; payment.AllowRefund = false; $scope.MemberPaymentsModel.SuccessMessage = data.memberRequestRefundResponse.SuccessMessage; $scope.$apply(); }, 0); } else { $timeout(function () { $scope.MemberPaymentsModel.ServerErrors = data.messages; $scope.$apply(); }, 0); } }).error(function (data, status, headers, config) { $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); }); } }; } }()); (function () { "use strict"; angular.module("common.services").factory("paymentsResource", ["$resource", paymentsResource]); function paymentsResource($resource) { return $resource("/Members/payments"); } }()); (function () { "use strict"; angular.module("fgcMain").controller("MakePaymentCtrl", ["makePaymentResource", "$scope", "$http", "$timeout", "$window", "$document", "$stateParams", "CommonCode", MakePaymentCtrl]); function MakePaymentCtrl(makePaymentResource, $scope, $http, $timeout, $window, $document, $stateParams, CommonCode) { var vm = this; $scope.stripToken = null; $scope.isProcessing = false; $scope.isLoading = true; var priceQuoteId = null; var leadId = null; if ($stateParams !== undefined) { leadId = $stateParams.leadId; priceQuoteId = $stateParams.priceQuoteId; } makePaymentResource.get({ leadId: leadId, priceQuoteId: priceQuoteId }).$promise.then(function (data) { if (CommonCode.RedirectForceState(data)) { return; } $scope.MemberMakePaymentModel = data.toJSON(); vm.afterLoadPage(); }, function (error) { if (!CommonCode.IsForbiddenRequest(error)) { $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); } }); $scope.autoToken = $window.sessionStorage.token; $scope.renderHtml = CommonCode.renderHtml; vm.afterLoadPage = function (error) { $document.on( "click", function (event) { //on any click - clear the error messages $timeout(function () { $scope.ConnectionGeneralErrorText = ''; $scope.MemberMakePaymentModel.ServerErrors = ''; $scope.MemberMakePaymentModel.ErrorText = ''; }, 0); } ); if ($scope.MemberMakePaymentModel.AllowMemberPayment) { $scope.handler = StripeCheckout.configure({ key: $scope.MemberMakePaymentModel.ProviderPublicKey, image: '/images/logo.jpg', locale: 'auto', allowRememberMe: false, currency: $scope.MemberMakePaymentModel.Currency, token: function (token) { var paymentEmail = token.email; $scope.stripToken = token.id; $scope.makePayment(token.id, paymentEmail); }, closed: function () { //console.log("Stripe Checkout closed"); } }); $scope.isLoading = false; } else { //Error for user } }; $scope.openPayingForm = function () { if ($scope.isProcessing === false) { $scope.handler.open({ email: $scope.MemberMakePaymentModel.Email, name: $scope.MemberMakePaymentModel.PaymentName, description: $scope.MemberMakePaymentModel.PaymentDescription, amount: $scope.MemberMakePaymentModel.Amount * 100.0 }); // Close Checkout on page navigation: $window.addEventListener('popstate', function () { $scope.handler.close(); }); } }; $scope.makePayment = function (stripToken, paymentEmail) { $scope.buttonClicked = true; $scope.ConnectionGeneralErrorText = ''; $scope.MemberMakePaymentModel.ServerErrors = ''; $scope.MemberMakePaymentModel.ErrorText = ''; if ($scope.memberMakePaymentForm.$valid && $scope.isProcessing === false) { var panelToRefresh = $('.refresh-container'); panelToRefresh.show(); $('.view-content').addClass('waiting'); $scope.isProcessing = true; $scope.MemberMakePaymentModel.PaymentAttemptModel.PaymentMethodNonce = stripToken; $scope.MemberMakePaymentModel.PaymentAttemptModel.PaymentEmail = paymentEmail; $http.post('/Members/Payments/memberMakePayment', $scope.MemberMakePaymentModel.PaymentAttemptModel) .success(function (data, status, headers, config) { var panelToRefresh = $('.refresh-container'); panelToRefresh.fadeOut(800); if (data.success === true) { $scope.isProcessing = false; $('.view-content').removeClass('waiting'); CommonCode.Redirect('paymentConfirmationPage', { 'paymentId': data.paymentId }); } else { $scope.isProcessing = false; $('.view-content').removeClass('waiting'); $scope.MemberMakePaymentModel.ServerErrors = data.messages; } }).error(function (data, status, headers, config) { var panelToRefresh = $('.refresh-container'); panelToRefresh.fadeOut(800); $('.view-content').removeClass('waiting'); $scope.isProcessing = false; $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); }); } }; } }()); (function () { "use strict"; angular.module("common.services").factory("makePaymentResource", ["$resource", makePaymentResource]); function makePaymentResource($resource) { return $resource("/Members/makePayment/:leadId/:priceQuoteId"); } }()); (function () { "use strict"; angular.module("fgcMain").controller("PaymentConfirmationCtrl", ["paymentConfirmationResource", "$scope", "$http", "$window", "$stateParams", "CommonCode", PaymentConfirmationCtrl]); function PaymentConfirmationCtrl(paymentConfirmationResource, $scope, $http, $window, $stateParams, CommonCode) { var vm = this; var paymentId = null; if ($stateParams !== undefined) { paymentId = $stateParams.paymentId; } paymentConfirmationResource.get({ paymentId: paymentId}).$promise.then(function (data) { if (CommonCode.RedirectForceState(data)) { return; } $scope.MemberPaymentConfirmationModel = data.toJSON(); vm.afterLoadPage(); }, function (error, status) { if (!CommonCode.IsForbiddenRequest(error)) { $scope.ConnectionGeneralErrorText = CommonCode.HandleErrorOnAction(status); } }); $scope.autoToken = $window.sessionStorage.token; $scope.renderHtml = CommonCode.renderHtml; vm.afterLoadPage = function (error) { }; } }()); (function () { "use strict"; angular.module("common.services").factory("paymentConfirmationResource", ["$resource", paymentConfirmationResource]); function paymentConfirmationResource($resource) { return $resource("/Members/paymentConfirmation/:paymentId"); } }());