@@ -46,11 +46,11 @@ class GeotabLogin {
4646 }
4747
4848 initializeGeotabApi ( GeotabApi ) {
49- const self = this ;
50- global . api = new GeotabApi ( function ( detailsCallback ) {
51- self . authenticationCallback = detailsCallback ;
52- if ( ! self . elLoginDialog . open ) {
53- self . elLoginDialog . showModal ( ) ;
49+ global . api = new GeotabApi ( ( detailsCallback ) => {
50+ this . authenticationCallback = detailsCallback ;
51+
52+ if ( ! this . elLoginDialog . open ) {
53+ this . elLoginDialog . showModal ( ) ;
5454 }
5555 } , {
5656 rememberMe : true
@@ -74,15 +74,14 @@ class GeotabLogin {
7474 }
7575
7676 initializeDevice ( ) {
77- let self = this ;
7877 // Mock device for drive addin
7978 global . api . call ( 'Get' , {
8079 typeName : 'Device' ,
8180 resultsLimit : 1000 ,
8281 search : {
8382 fromDate : new Date ( )
8483 }
85- } , function ( devices ) {
84+ } , ( devices ) => {
8685 var options = devices . sort ( function ( d1 , d2 ) {
8786 var name1 = d1 . name . toLowerCase ( ) ;
8887 var name2 = d2 . name . toLowerCase ( ) ;
@@ -96,45 +95,44 @@ class GeotabLogin {
9695 } ) . map ( function ( d ) {
9796 return '<option value="' + d . id + '">' + d . name + '</option>' ;
9897 } ) ;
99- self . elDevices . innerHTML = '<option>Select Device</option>' + options . join ( '' ) ;
100- self . elDeviceDialog . showModal ( ) ;
101- } , function ( e ) {
98+ this . elDevices . innerHTML = '<option>Select Device</option>' + options . join ( '' ) ;
99+ this . elDeviceDialog . showModal ( ) ;
100+ } , ( e ) => {
102101 console . error ( `Could not get vehicles: ${ e . message } ` ) ;
103102 } ) ;
104103 }
105104
106105 intializeInterface ( isDriveAddin ) {
107- const self = this ;
108-
109- this . elLoginBtn . addEventListener ( 'click' , function ( event ) {
110- var server = self . elServer . value || 'my.geotab.com' ,
111- database = self . elDatabase . value ,
112- email = self . elEmail . value ,
113- password = self . elPassword . value ;
106+ this . elLoginBtn . addEventListener ( 'click' , ( event ) => {
107+ var server = this . elServer . value || 'my.geotab.com' ,
108+ database = this . elDatabase . value ,
109+ email = this . elEmail . value ,
110+ password = this . elPassword . value ;
114111
115112 event . preventDefault ( ) ;
116-
117113 localStorage . setItem ( '_user' , JSON . stringify ( email ) ) ;
114+
118115 global . api . user = email ;
116+ this . elLoginError . style . display = 'none' ;
119117
120- self . elLoginError . style . display = 'none' ;
118+ this . authenticationCallback ( server , database , email , password , ( err ) => {
119+ this . elLoginDialog . showModal ( ) ;
121120
122- self . authenticationCallback ( server , database , email , password , function ( err ) {
123- self . elLoginDialog . showModal ( ) ;
124121 if ( err ) {
125- self . elLoginError . textContent = err ;
122+ this . elLoginError . textContent = err ;
126123 }
127- self . elLoginError . style . display = 'block' ;
124+
125+ this . elLoginError . style . display = 'block' ;
128126 } ) ;
129127
130128 if ( ! isDriveAddin ) {
131- self . initalizeAddin ( ) ;
129+ this . initalizeAddin ( ) ;
132130 }
133131
134- self . elLoginDialog . close ( ) ;
132+ this . elLoginDialog . close ( ) ;
135133 } ) ;
136134
137- this . elLogoutBtn . addEventListener ( 'click' , function ( event ) {
135+ this . elLogoutBtn . addEventListener ( 'click' , ( event ) => {
138136 event . preventDefault ( ) ;
139137
140138 if ( global . api !== undefined ) {
@@ -144,35 +142,38 @@ class GeotabLogin {
144142 Object . keys ( global . geotab . addin ) . forEach ( function ( name ) {
145143 global . geotab . addin [ name ] . isInitialize = false ;
146144 } ) ;
147- self . device = null ;
148- global . state . device = self . device ;
149- localStorage . setItem ( '_device' , JSON . stringify ( self . device ) ) ;
145+
146+ this . device = null ;
147+ global . state . device = this . device ;
148+ localStorage . setItem ( '_device' , JSON . stringify ( this . device ) ) ;
149+
150150 if ( isDriveAddin ) {
151- self . initializeDevice ( ) ;
151+ this . initializeDevice ( ) ;
152152 }
153+
153154 Object . keys ( global . geotab . addin ) . forEach ( function ( name ) {
154155 global . geotab . addin [ name ] . blur ( global . api , global . state ) ;
155156 } ) ;
156157 } ) ;
157158
158- this . elDevices . addEventListener ( 'change' , function ( event ) {
159+ this . elDevices . addEventListener ( 'change' , ( event ) => {
159160 var id = event . target . value ;
160161
161162 event . preventDefault ( ) ;
162163
163164 if ( id ) {
164- self . device = {
165+ this . device = {
165166 id : id
166167 } ;
167- global . state . device = self . device ;
168- localStorage . setItem ( '_device' , JSON . stringify ( self . device ) ) ;
168+ global . state . device = this . device ;
169+ localStorage . setItem ( '_device' , JSON . stringify ( this . device ) ) ;
169170 }
170171 } ) ;
171172
172- this . elDevicesOkBtn . addEventListener ( 'click' , function ( event ) {
173+ this . elDevicesOkBtn . addEventListener ( 'click' , ( event ) => {
173174 event . preventDefault ( ) ;
174175
175- if ( self . device ) {
176+ if ( this . device ) {
176177 this . initalizeAddin ( ) ;
177178
178179 // in this order becasue zombiejs errors out on close
@@ -186,7 +187,7 @@ class GeotabLogin {
186187 let app = document . querySelector ( '#app' ) ;
187188 let body = document . body ;
188189
189- if ( self . elNightModeToggle . checked ) {
190+ if ( this . elNightModeToggle . checked ) {
190191 app . classList . add ( NightMode ) ;
191192 body . classList . add ( NightMode ) ;
192193 } else {
@@ -258,4 +259,4 @@ class GeotabLogin {
258259 }
259260}
260261
261- module . exports = GeotabLogin ;
262+ module . exports = GeotabLogin ;
0 commit comments