(function() { "use strict"; angular.module('VialOfLife',['Common','ngRoute','ngAnimate','VialOfLifeForms']);angular.module('App',['VialOfLife']).run(['$rootScope','$templateCache',function($rootScope,$templateCache){$rootScope.$on('$routeChangeStart',function(){$templateCache.removeAll();});}]);function VOLRoutes($routeProvider){$routeProvider.when('/',{templateUrl:'app/components/home/homeView.html',controller:'defaultController',controllerAs:'vm'}).when('/home-new-account',{templateUrl:'app/components/home/newAccountView.html',controller:'homeController',controllerAs:'vm'}).when('/lost-password',{templateUrl:'app/components/home/lostPasswordView.html',controller:'lostPasswordController',controllerAs:'vm'}).when('/home-member-login',{templateUrl:'app/components/home/loginView.html',controller:'loginController',controllerAs:'vm'}).when('/home-member-login/:msg',{templateUrl:'app/components/home/loginView.html',controller:'loginController',controllerAs:'vm'}).when('/member-home',{templateUrl:'app/components/member/memberHomeView.html',controller:'memberHomeController',controllerAs:'vm'}).when('/member-home/:action',{templateUrl:'app/components/member/memberHomeView.html',controller:'memberHomeController',controllerAs:'vm'}).when('/member-home/:action/:id',{templateUrl:'app/components/member/memberHomeView.html',controller:'memberHomeController',controllerAs:'vm'}).when('/member-home/:action/:id/:readonly',{templateUrl:'app/components/member/memberHomeView.html',controller:'memberHomeController',controllerAs:'vm'}).when('/member-info',{templateUrl:'app/components/member/memberInfoView.html',controller:'memberInfoController',controllerAs:'vm'}).when('/member-vial',{templateUrl:'app/components/member/memberVialView.html',controller:'memberVialController',controllerAs:'vm'}).when('/guest-vial',{templateUrl:'app/components/vial/vialVialView.html',controller:'vialVialController',controllerAs:'vm'}).when('/order-decals-individual',{templateUrl:'app/components/decals/simpleView.html',controller:function(){window.location.href='/call-to-order';},controllerAs:'vm'}).when('/order-decals-large',{templateUrl:'app/components/decals/largeView.html',controller:'decalsController',controllerAs:'vm'}).otherwise({redirectTo:'/'});} angular.module('VialOfLife').config(VOLRoutes);function decalsController(CommonFactory,statesService,$scope){var vm=this;var factory=CommonFactory;var init=function(){statesService.getStates().then(function(d){vm.states=d;});factory.clearError();};var individual=function(data){if(confirm('Submit this Order?')){var final=angular.extend(defaults,data);factory.load('individual',{data:final}).then(function(r){vm.completed=r.data.success;});}};var organization=function(data){if(vm.compareDecalDonation()&&confirm('Submit this Order?')){var final=angular.extend(defaults,data);factory.load('organization',{data:final}).then(function(r){vm.completed=r.data.success;});}else if(!vm.compareDecalDonation()){alert(vm.account.decals+' decals requires a minimum donation of $'+vm.calcMinDonation()+'.00');}};var defaults={"id":null,"firstname":null,"lastname":null,"organization":null,"title":null,"phone":null,"address":null,"address2":null,"city":null,"state":null,"zip":null,"email":'',"memo":null,"decals":null,"datecreated":null,"donation_amount":null,"donation_cc":null,"donation_exp":null,"donation_routing":null,"donation_account":null,"donation_bank":null,"donation_type":null,"donation_card_type":null,"ext":"0","bill_name":null,"bill_addr":null,card_exp_mm:null,card_exp_yy:null,"bill_city":null,"bill_state":null,"bill_zip":null,"json_tags":null,"ref_form":"small","trans_id":0};factory.target('code/decals.php');vm.error='';vm.loading=false;vm.account={};vm.individual=individual;vm.organization=organization;vm.months=[];vm.years=[];vm.completed=false;vm.calcMinDonation=function(){if(vm.account.decals<=50){return 10;}else if(vm.account.decals<=100){return 20;}else if(vm.account.decals<=200){return 30;}else if(vm.account.decals<=300){return 40;}else if(vm.account.decals<=400){return 50;}else if(vm.account.decals<=500){return 60;}else if(vm.account.decals<=750){return 80;}else if(vm.account.decals<=1000){return 100;}else if(vm.account.decals<=1500){return 140;}else if(vm.account.decals<=2000){return 175;}else if(vm.account.decals){var owed_amount=175;owed_amount=((Math.floor(vm.account.decals/1000)-1)*50)+owed_amount;return owed_amount;}else{return 10;}};vm.compareDecalDonation=function(){if(vm.account.donation_amount&&vm.account.decals){var a=parseFloat(vm.account.donation_amount);var b=parseFloat(vm.calcMinDonation());$scope.accountForm.donation_amount.$setValidity('min',a>=b);$scope.accountForm.$invalid=a>=b;return a>=b;} return false;};$scope.$watch(factory.loading,function(o){vm.loading=o;});$scope.$watch(function(){return factory.error();},function(o,n){vm.error=o;});for(var i=0;i<12;i++){vm.months.push(i+1);} var year=parseInt((new Date).getFullYear());for(var i=0;i<20;i++){vm.years.push(i+year);} document.title='Vial of Life - Order Decals Organization';init();} angular.module('VialOfLife').controller('decalsController',decalsController);function homeController(CommonFactory,statesService,$location,$scope,$window){var vm=this;var factory=CommonFactory;var info={};var init=function(){statesService.getStates().then(function(d){vm.states=d;});if($window.sessionStorage.vol_vial){info=angular.fromJson($window.sessionStorage.vol_vial);if(info.vial_info){var data=info.vial_info;data['phone_home']=data['phone'];data['email1']=data['email'];data['email2']=data['email'];vm.account=angular.extend(vm.account,data);delete vm.account.phone;delete vm.account.email;delete vm.account.initial;} console.log(info,vm.account);} factory.clearError();};var submit=function(account){if(account.email1!==account.email2){alert('Email and Confirm Email must match!');return false;} if(account.password1!==account.password2){alert('Password and Confirm Password must match!');return false;} if(confirm('Create an account with these values?')){var data={account:account};if($window.sessionStorage.vol_vial){data.vial=angular.fromJson($window.sessionStorage.vol_vial);} factory.load('new-account',data).then(function(r){if(r.data.success){delete $window.sessionStorage.vol_vial;vm.account={first_responder_program:1};if(confirm('Account added successfully! Proceed with the login page?')){$location.path('/home-member-login');}}});}};factory.target('code/home.php');vm.accountInfoButtonLabel='Sign Up';vm.accountInfoSubmit=submit;vm.accountInfoPageTitle='Create a New Account';vm.states=[];vm.loading=false;vm.account={first_responder_program:1};vm.error='';vm.cancelHidden=typeof $window.sessionStorage.vol_vial==='undefined';vm.cancel=function(){if(confirm('Cancel are you sure?')){$location.path('/guest-vial');}};$scope.$watch(factory.loading,function(o){vm.loading=o;});$scope.$watch(function(){return factory.error();},function(o){vm.error=o;});init();} angular.module('VialOfLife').controller('homeController',homeController);function loginController(CommonFactory,$scope,$location,SessionService,$routeParams){var vm=this;var factory=CommonFactory;var session=SessionService;var init=function(){session.check().success(function(r){if(r.valid){SessionService.loggedIn(true);$location.path('/member-home');}else{SessionService.loggedIn(false);}});};var login=function(user){session.login(user.name,user.pass).then(function(r){if(!r.data.valid){vm.message=r.data.message;}});};vm.loading=false;vm.user={name:'',pass:''};vm.login=login;vm.message=$routeParams.msg||'';$scope.$watch(factory.loading,function(o){vm.loading=o;});$scope.$watch(function(){return factory.error();},function(o){vm.error=o;vm.message=o;});init();} angular.module('VialOfLife').controller('loginController',loginController);function lostPasswordController(CommonFactory){var vm=this;var factory=CommonFactory;factory.target('code/home.php');vm.reSend=function(){factory.load('lost',{user:vm.user.name}).then(function(){vm.message='Password Sent!';});};vm.user={};vm.message='';} angular.module('VialOfLife').controller('lostPasswordController',lostPasswordController);function menuController($scope,TopMenuService){var vm=this;vm.hidden=true;TopMenuService.hidden(true);$scope.$watch(function(){return TopMenuService.hidden();},function(v){vm.hidden=v;});} angular.module('VialOfLife').controller('menuController',menuController);function passwordResetController(CommonFactory){var vm=this;var factory=CommonFactory;} angular.module('VialOfLife').controller('passwordResetController',passwordResetController);function memberHomeController(MemberFactory,$scope,$location,SessionService,$routeParams,statesService){var vm=this;var factory=MemberFactory;var init=function(){var panelAction=vm.panel;var add={};if(vm.id){add.id=vm.id;} factory.load(panelAction,add).success(function(r){if(r.list){vm.list=r.list;vm.label=r.label;vm.optin=r.optin;}else if(r.vial){vm.vial=r.vial;}else if(r.account){vm.account=r.account;} if(vm.states.length===0){statesService.getStates().then(function(r){vm.states=r;});} switch(vm.panel){case'edit-account':vm.pageTitle='Edit Account Information';break;case'edit-vial':vm.pageTitle='Vial of Life Form';break;case'main':default:vm.pageTitle='Account Management';} document.title='Vial of Life - '+vm.pageTitle;SessionService.loggedIn(true);});};vm.accountInfoButtonLabel='Save';vm.accountInfoSubmit=function(){if(!confirm('Save Form?')){return false;} factory.load('save-account',{info:vm.account}).then(function(r){if(r.data.success){alert('Account Saved');$location.path('/member-home');}});};vm.removeVial=function(item){if(!confirm('Remove Form?')){return false;} factory.load('del-vial',{item:item}).then(function(r){if(r.data.success){alert('Form Removed');vm.list=r.data.list;}});};vm.optin={bool:false,forget:false};vm.optin_enroll=function(){factory.load('optin-001',{optin:vm.optin}).success(function(r){if(r.success){vm.optin=r.optin;}});};vm.optin_forget=function(){factory.load('optin-001-forget',{optin:vm.optin}).success(function(r){if(r.success){vm.optin=r.optin;}});};vm.accountInfoPageTitle='';vm.account={};vm.pageTitle='Member Home';vm.readOnlyVial=$routeParams.readonly==='true';vm.panel=$routeParams.action||'main';vm.id=$routeParams.id||'';vm.error='';vm.cancelHidden=true;vm.list=[];vm.loading=false;vm.states=[];vm.edit=function(){$location.path('/member-home/edit-vial/'+$routeParams.id);};vm.SaveVialForm=function(){if(!confirm('Save Form?')){return false;} factory.load('save-vial',{info:vm.vial}).then(function(r){if(r.data.success){alert('Form Saved');$location.path('/member-home');}});};vm.isEditPanel=function(){return /^edit/.test(vm.panel);};vm.check=function(){factory.load('check');};vm.logout=function(){if(!confirm('Logout?')){return false;} $location.path('/login-out');factory.load('logout').then(function(r){if(r.data.success){$location.path('/home-member-login');}});};$scope.$watch(factory.loading,function(o){vm.loading=o;});$scope.$watch(function(){return factory.error();},function(o){vm.error=o;});init();} function MemberFactory(CommonFactory){return{load:function(action,params,callback){return CommonFactory.target('code/member.php').load(action,params,callback);},loading:CommonFactory.loading,error:CommonFactory.error};} angular.module('VialOfLife').controller('memberHomeController',memberHomeController).factory('MemberFactory',MemberFactory);function vialVialController(CommonFactory,statesService,$window,$location,TopMenuService){var vm=this;var factory=CommonFactory;vm.states=[];vm.vial={};vm.submit=function(){if(confirm('Create a new account?')){$window.sessionStorage.vol_vial=angular.toJson(vm.vial);$location.path('/home-new-account');}};if(vm.states.length===0){statesService.getStates().then(function(s){vm.states=s;});} document.title='Vial of Life - Vial of Life Form';if($window.sessionStorage.vol_vial){vm.vial=angular.fromJson($window.sessionStorage.vol_vial);}} function defaultController(TopMenuService){TopMenuService.hidden(false);var vm=this;vm.hide=function(){TopMenuService.hidden(true);};} angular.module('VialOfLife').controller('vialVialController',vialVialController).controller('defaultController',defaultController);function authorizeInterceptorService($q,$window,$location){var response=function(response){if(response.status===401&&$location.path()!=='/home-member-login'){$location.path('/home-member-login/'+response.data.error);} return response||$q.when(response);};var request=function(config){config.headers=config.headers||{};if($window.sessionStorage.vol_token){config.headers.Authorization='Bearer '+$window.sessionStorage.vol_token;} return config;};var responseError=function(response){if(response.status===401&&$location.path()!=='/home-member-login'){$location.path('/home-member-login/'+response.data.error);} return $q.reject(response);};var service={request:request,response:response,responseError:responseError};return service;} function Sessions(CommonFactory,$window,$location){var factory=CommonFactory;var loggedIn=false;var service={loggedIn:function(bool){if(typeof bool!=='undefined'){loggedIn=bool;} return loggedIn;},check:function(){return factory.target('code/sessions.php').load('check').success(function(r){service.loggedIn(r.valid);}).error(function(){service.loggedIn(false);});},login:function(user,pass){return factory.target('code/sessions.php').load('login',{name:user,pass:pass}).success(function(r){if(r.valid){service.loggedIn(true);$window.sessionStorage.vol_token=r.token;$location.path('/member-home');}}).error(function(){service.loggedIn(false);});}};return service;} function TopMenuService(){var _hidden=false;return{hidden:function(bool){if(typeof bool!=='undefined'){_hidden=bool;} return _hidden;}};} angular.module('VialOfLife').factory('authorizeInterceptorService',authorizeInterceptorService).factory('SessionService',Sessions).factory('TopMenuService',TopMenuService).config(function($httpProvider){$httpProvider.interceptors.push('authorizeInterceptorService');});function CommonFactory($http,$sce){var errorMessage='';var targetUrl='';var baseUrl='';var responseObject={data:[]};var loadingBool=false;var myLoadingFunction=function(){if(typeof arguments[0]==='boolean'){loadingBool=arguments[0];} return loadingBool;};var overwriteLoadingFunction=function(){if(typeof arguments[0]==='function'){factory.loading=arguments[0];}else{factory.loading=myLoadingFunction;}};var factory={hasError:false,target:function(link){targetUrl=baseUrl+link;return factory;},response:function(){if(typeof arguments[0]!=='undefined'&&typeof arguments[0]==='object'){responseObject=angular.extend(responseObject,arguments[0]);} return responseObject;},clearError:function(){errorMessage='';factory.hasError=false;},load:Load,loading:myLoadingFunction,error:function(text){if(typeof text!=='undefined'){errorMessage=$sce.trustAsHtml(arguments[0]);} return errorMessage;}};function Load(view,obj){if(arguments.length===3){overwriteLoadingFunction(arguments[2]);} factory.loading(true);factory.clearError();var data={action:view};var final={};if(typeof obj==='object'){final=angular.extend(data,obj);}else if(typeof obj!=='undefined'){throw new Exception('Invalid parameter detected!');}else{final=data;} return $http.post(targetUrl,final).success(function(response){factory.loading(false);return response;}).error(function(r){factory.loading(false);handleError(r);return r;});} function handleError(response){if(response.error){factory.error(response.error);}else{factory.error(response);} factory.hasError=true;} return factory;} angular.module('Common',[]).service('CommonFactory',CommonFactory).directive('volStickyError',function(){return{restrict:'E',replace:true,scope:{error:'='},template:'
'};}).directive('focusMe',function(){return{link:function(scope,element,attrs){scope.$watch(attrs.focusMe,function(value){if(value===true){element[0].focus();scope[attrs.focusMe]=false;}});}};}).directive('volLoaderInline',function(){return{restrict:'E',replace:true,scope:{bool:'=',label:'@'},template:'
'+'loading {{label||\'Loading\'}} ...  '};}).directive('volLoader',function(){return{restrict:'E',replace:true,scope:{bool:'=',label:'@'},template:'

{{label||\'Loading\'}} ...

'+'loading
'};}).directive('volExport',function(){return{restrict:'E',replace:true,scope:{encoded:'@',targetStr:'@'},template:'
'+''+''+'
'};}).directive('tableResponse',function(){return{restrict:'E',scope:{data:'=',label:'@'},template:'
{{c}}
'};}).directive('tableFields',function(){return{restrict:'E',scope:{data:'=',label:'@',fields:'='},template:'
{{f}}
{{r[f]}}
'};});angular.module('VialOfLifeForms',[]).directive('vialMemberForm',function(){return{restrict:'E',replace:true,scope:{vial:'=',submit:'&',states:'=',readonly:'=',hideSubmit:'=',edit:'&'},templateUrl:'app/components/member/memberVialView.html',controller:function($rootElement,$scope){$scope.force=function(){$rootElement.find('input, select, textarea').checkAndTriggerAutoFillEvent();};$scope.GetHearingText=function(){if(!$scope.vial)return'None';var v=$scope.vial.vial_info;if(!v||!v.hearing)return'None';if(v.hearing.left&&v.hearing.right){return'Both Ears';}else if(v.hearing.left){return'Left Ear';}else if(v.hearing.right){return'Right Ear';}else{return'None';}};$scope.GetDeafText=function(){if(!$scope.vial)return'No';var v=$scope.vial.vial_info;if(!v||!v.deaf)return'No';if(v.deaf.left&&v.deaf.right){return'Both Ears';}else if(v.deaf.left){return'Left Ear';}else if(v.deaf.right){return'Right Ear';}else{return'No';}};$scope.GetBlindText=function(){if(!$scope.vial)return'No';var v=$scope.vial.vial_info;if(!v||!v.blind)return'No';if(v.blind.left&&v.blind.right){return'Both Eyes';}else if(v.blind.left){return'Left Eye';}else if(v.blind.right){return'Right Eye';}else{return'No';}};$scope.GetArtificialEyeText=function(){if(!$scope.vial)return'No';var v=$scope.vial.vial_info;if(!v||!v.artificial_eye)return'No';if(v.artificial_eye.left&&v.artificial_eye.right){return'Both Eyes';}else if(v.artificial_eye.left){return'Left Eye';}else if(v.artificial_eye.right){return'Right Eye';}else{return'No';}};}};}).directive('vialMemberAccountForm',function(){return{restrict:'E',replace:true,scope:{vm:'=',states:'=',editMode:'=',useOld:'='},templateUrl:'app/components/home/newAccountView.html',controller:function($rootElement,$scope){$scope.force=function(){$rootElement.find('input, select, textarea').checkAndTriggerAutoFillEvent();};}};});function statesService($http,$q){var states=[];var promise=function(){var def=$q.defer();def.resolve(states);return def.promise;};var getStates=function(){if(states.length===0){return $http.get('code/states.php').then(function(r){if(r.data.success){states=r.data.states;} return promise();});}else{return promise();}};return{getStates:getStates};} angular.module('VialOfLife').factory('statesService',statesService);})();