@@ -39,20 +39,22 @@ function ControllerApp(
3939 actions : { }
4040 } ;
4141 function setActiveAccount ( accountName ) {
42- $scope . $watch ( 'dataApp.data.orgs' , function ( n ) {
43- if ( n ) {
44- dataApp . data . instances = null ;
45- var accounts = [ thisUser ] . concat ( n . models ) ;
46- dataApp . data . activeAccount = accounts . find ( function ( org ) {
47- return ( keypather . get ( org , 'oauthName().toLowerCase()' ) === accountName . toLowerCase ( ) ) ;
48- } ) ;
49- if ( ! dataApp . data . activeAccount ) {
50- dataApp . data . activeAccount = thisUser ;
42+ if ( accountName ) {
43+ $scope . $watch ( 'dataApp.data.orgs' , function ( n ) {
44+ if ( n ) {
45+ dataApp . data . instances = null ;
46+ var accounts = [ thisUser ] . concat ( n . models ) ;
47+ dataApp . data . activeAccount = accounts . find ( function ( org ) {
48+ return ( keypather . get ( org , 'oauthName().toLowerCase()' ) === accountName . toLowerCase ( ) ) ;
49+ } ) ;
50+ if ( ! dataApp . data . activeAccount ) {
51+ dataApp . data . activeAccount = thisUser ;
52+ }
53+ $rootScope . $broadcast ( 'INSTANCE_LIST_FETCH' , dataApp . data . activeAccount . oauthName ( ) ) ;
54+ $rootScope . safeApply ( ) ;
5155 }
52- $rootScope . $broadcast ( 'INSTANCE_LIST_FETCH' , dataApp . data . activeAccount . oauthName ( ) ) ;
53- $rootScope . safeApply ( ) ;
54- }
55- } ) ;
56+ } ) ;
57+ }
5658 }
5759 // shows spinner overlay
5860 dataApp . data . loading = false ;
@@ -66,7 +68,6 @@ function ControllerApp(
6668
6769 var thisUser ;
6870
69-
7071 $scope . $watch ( function ( ) {
7172 return errs . errors . length ;
7273 } , function ( n ) {
@@ -85,37 +86,40 @@ function ControllerApp(
8586 $scope . $broadcast ( 'app-document-click' ) ;
8687 } ;
8788
88-
8989 fetchUser ( function ( err , results ) {
90- thisUser = results ;
91- dataApp . data . user = results ;
92- } ) ;
93- fetchOrgs ( function ( err , results ) {
94- dataApp . data . orgs = results ;
95- $rootScope . safeApply ( ) ;
96- if ( err ) {
97- return errs . handler ( err ) ;
98- }
99- if ( $window . heap ) {
100- $window . heap . identify ( {
101- name : thisUser . oauthName ( ) ,
102- email : thisUser . attrs . email ,
103- orgs : $window . JSON . stringify ( results )
90+ if ( ! err ) {
91+ thisUser = results ;
92+ dataApp . data . user = results ;
93+ fetchOrgs ( function ( err , results ) {
94+ if ( err ) {
95+ return errs . handler ( err ) ;
96+ }
97+ dataApp . data . orgs = results ;
98+ if ( $window . heap ) {
99+ $window . heap . identify ( {
100+ name : thisUser . oauthName ( ) ,
101+ email : thisUser . attrs . email ,
102+ orgs : $window . JSON . stringify ( results )
103+ } ) ;
104+ }
105+ if ( $window . initIntercom ) {
106+ $window . initIntercom ( {
107+ name : thisUser . oauthName ( ) ,
108+ email : thisUser . attrs . email ,
109+ // Convert ISO8601 to Unix timestamp
110+ created_at : + ( new Date ( thisUser . attrs . created ) ) ,
111+ app_id : 'wqzm3rju'
112+ } ) ;
113+ }
114+ if ( $window . olark ) {
115+ $window . olark ( 'api.visitor.updateEmailAddress' , { emailAddress : thisUser . attrs . email } ) ;
116+ $window . olark ( 'api.visitor.updateFullName' , { fullName : thisUser . oauthName ( ) } ) ;
117+ $window . olark ( 'api.box.show' ) ;
118+ }
119+ $rootScope . safeApply ( ) ;
104120 } ) ;
105- }
106- if ( $window . initIntercom ) {
107- $window . initIntercom ( {
108- name : thisUser . oauthName ( ) ,
109- email : thisUser . attrs . email ,
110- // Convert ISO8601 to Unix timestamp
111- created_at : + ( new Date ( thisUser . attrs . created ) ) ,
112- app_id : 'wqzm3rju'
113- } ) ;
114- }
115- if ( $window . olark ) {
116- $window . olark ( 'api.visitor.updateEmailAddress' , { emailAddress : thisUser . attrs . email } ) ;
117- $window . olark ( 'api.visitor.updateFullName' , { fullName : thisUser . oauthName ( ) } ) ;
118- $window . olark ( 'api.box.show' ) ;
121+ } else {
122+ return errs . handler ( err ) ;
119123 }
120124 } ) ;
121125}
0 commit comments