Blame view

app/js/app.js 12.3 KB
feacde5ff   Rishav   setup acuefuel in...
1
  'use strict';
05bfa28a2   Mr. Hot Foods   remove save butto...
2
    angular.module('acufuel', ['nvd3', 'ngCookies', 'ngResource', 'ui.router', 'ngAnimate', 'ui.bootstrap', 'xeditable', 'ui.toggle', 'ngTable', 'ui.select2', 'ckeditor', 'ui.calendar', 'ngDragDrop'])
4bb02bb84   Rishav   new integration w...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  
      .config(['$httpProvider', function($httpProvider) {
        $httpProvider.defaults.withCredentials = true;
        $httpProvider.interceptors.push('myCSRF');
        $httpProvider.interceptors.push('httpRequestInterceptor');
      }])
  
  
      .factory('httpRequestInterceptor', ['$q', '$rootScope', '$location', function($q, $rootScope, $location) {
         return {
             request: function($config) {
               return $config;
             },
             responseError: function(rejection) {
               if (rejection.status === 401) {
                 if($location.path() != "/login"){
                     localStorage.clear();
                     window.location.reload();
                 }  
               }
               return $q.reject(rejection);
             }
           }
       }])
      
      .provider('myCSRF',[function(){
        var headerName = 'X-CSRFToken';
        var cookieName = 'csrftoken';
        var allowedMethods = ['GET'];
  
        this.setHeaderName = function(n) {
          headerName = n;
        }
        this.setCookieName = function(n) {
          cookieName = n;
        }
        this.setAllowedMethods = function(n) {
          allowedMethods = n;
        }
        this.$get = ['$cookies', function($cookies){
          return {
            'request': function(config) {
              if(allowedMethods.indexOf(config.method) === -1) {
                // do something on success
                config.headers[headerName] = $cookies[cookieName];
              }
              return config;
            }
          }
        }];
      }])
feacde5ff   Rishav   setup acuefuel in...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  
    .config(
        ['$locationProvider', '$stateProvider', '$urlRouterProvider',
          function($locationProvider, $stateProvider, $urlRouterProvider) {
            $locationProvider.hashPrefix('!');
            // routes
            $urlRouterProvider
                .otherwise('/login');
  
            $stateProvider
  
              .state("app", {
                url: "",
                templateUrl: "partials/main/main.html",
                controller: "MainController",
                abstract: true
              })
  
              .state("login", {
                url: "/login",
                templateUrl: "partials/login/login.html",
                controller: "LoginController"
              })
              
              .state("app.customers", {
                url: "/customers",
                templateUrl: "partials/customers/customers.html",
dd378d69f   Mr. Hot Foods   changes in flight...
81
82
83
84
                controller: "customersController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
85
              })
3a9f4472b   Rishav   Implement contact...
86
87
88
89
  
              .state("app.accountSetting", {
                url: "/accountSetting",
                templateUrl: "partials/accountSetting/accountSetting.html",
dd378d69f   Mr. Hot Foods   changes in flight...
90
91
92
93
                controller: "AccountSettingController",
                data: {
                    authorizedRoles: ["FBO"],
                }
3a9f4472b   Rishav   Implement contact...
94
              })
4bb02bb84   Rishav   new integration w...
95
96
97
              .state("app.ContactView", {
                url: "/ContactView",
                templateUrl: "partials/ContactView/ContactView.html",
dd378d69f   Mr. Hot Foods   changes in flight...
98
99
100
101
                controller: "ContactViewController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
102
103
104
105
              })
              .state("app.FuelVendors", {
                url: "/FuelVendors",
                templateUrl: "partials/FuelVendors/FuelVendors.html",
dd378d69f   Mr. Hot Foods   changes in flight...
106
107
108
109
                controller: "FuelVendorsController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
110
              })
feacde5ff   Rishav   setup acuefuel in...
111
112
113
114
  
              .state("app.analytics", {
                url: "/analytics",
                templateUrl: "partials/analytics/analytics.html",
dd378d69f   Mr. Hot Foods   changes in flight...
115
116
117
118
                controller: "analyticsController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
119
120
121
122
123
              })
  
              .state("app.account", {
                url: "/account",
                templateUrl: "partials/account/account.html",
dd378d69f   Mr. Hot Foods   changes in flight...
124
125
126
127
                controller: "accountController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
128
129
              })
              
3a9f4472b   Rishav   Implement contact...
130
              .state("app.dashboard", {
feacde5ff   Rishav   setup acuefuel in...
131
132
                url: "/dashboard",
                templateUrl: "partials/dashboard/dashboard.html",
dd378d69f   Mr. Hot Foods   changes in flight...
133
134
135
136
                controller: "dashboardController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
137
              })
feacde5ff   Rishav   setup acuefuel in...
138
139
140
              .state("app.elements", {
                url: "/elements",
                templateUrl: "partials/elements/elements.html",
dd378d69f   Mr. Hot Foods   changes in flight...
141
142
143
144
                controller: "elementsController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
145
              })
feacde5ff   Rishav   setup acuefuel in...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
              .state("app.error", {
                url: "/error",
                templateUrl: "partials/error/error.html",
                controller: "errorController"
              })
  
              .state("app.faq", {
                url: "/faq",
                templateUrl: "partials/faq/faq.html",
                controller: "faqController"
              })
  
              .state("app.forms", {
                url: "/forms",
                templateUrl: "partials/forms/forms.html",
dd378d69f   Mr. Hot Foods   changes in flight...
161
162
163
164
                controller: "formsController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
165
166
167
168
169
              })
  
              .state("app.fuelManager", {
                url: "/fuelManager",
                templateUrl: "partials/fuelManager/fuelManager.html",
dd378d69f   Mr. Hot Foods   changes in flight...
170
171
172
173
                controller: "fuelManagerController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
174
              })
feacde5ff   Rishav   setup acuefuel in...
175
176
177
              .state("app.pricing", {
                url: "/pricing",
                templateUrl: "partials/pricing/pricing.html",
dd378d69f   Mr. Hot Foods   changes in flight...
178
179
180
181
                controller: "pricingController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
182
183
184
185
186
              })
  
              .state("app.reports", {
                url: "/reports",
                templateUrl: "partials/reports/reports.html",
dd378d69f   Mr. Hot Foods   changes in flight...
187
188
189
190
                controller: "reportsController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
191
192
193
194
195
              })
  
              .state("app.scheduler", {
                url: "/scheduler",
                templateUrl: "partials/scheduler/scheduler.html",
dd378d69f   Mr. Hot Foods   changes in flight...
196
197
198
199
                controller: "schedulerController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
200
201
202
203
204
205
206
207
208
209
              })
              .state("app.signup", {
                url: "/signup",
                templateUrl: "partials/signup/signup.html",
                controller: "signupController"
              })
  
              .state("app.updateFuelManager", {
                url: "/updateFuelManager",
                templateUrl: "partials/updateFuelManager/updateFuelManager.html",
4bb02bb84   Rishav   new integration w...
210
                controller: "updateFuelManagerController",
dd378d69f   Mr. Hot Foods   changes in flight...
211
212
213
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
214
              })
cd330b5ee   Rishav   fuel vendor and v...
215
              .state("app.viewCompany", {
55e075d7e   Rishav   add contact, add ...
216
                url: "/viewCompany/:id",
feacde5ff   Rishav   setup acuefuel in...
217
                templateUrl: "partials/viewCompany/viewCompany.html",
dd378d69f   Mr. Hot Foods   changes in flight...
218
219
220
221
                controller: "viewCompanyController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
222
              }) 
ea15674c8   Rishav   minor changes for...
223
224
225
              .state("app.viewFuelVendor", {
                url: "/viewFuelVendor/:id",
                templateUrl: "partials/viewFuelVendor/viewFuelVendor.html",
dd378d69f   Mr. Hot Foods   changes in flight...
226
227
228
229
                controller: "ViewFuelVendorController",
                data: {
                    authorizedRoles: ["FBO"],
                }
cd330b5ee   Rishav   fuel vendor and v...
230
              }) 
88dad9efc   Rishav   remove unused fil...
231
              .state("app.fuelOrders", {
4bb02bb84   Rishav   new integration w...
232
233
                url: "/fuelOrders",
                templateUrl: "partials/fuelOrders/fuelOrders.html",
dd378d69f   Mr. Hot Foods   changes in flight...
234
235
236
237
                controller: "fuelOrdersController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
238
239
240
241
242
              })
  
               .state("app.DispatchFuel", {
                url: "/DispatchFuel",
                templateUrl: "partials/DispatchFuel/DispatchFuel.html",
dd378d69f   Mr. Hot Foods   changes in flight...
243
244
245
246
                controller: "DispatchFuelController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
247
              })
3a9f4472b   Rishav   Implement contact...
248
              .state("app.searchDispatchFuel", {
4bb02bb84   Rishav   new integration w...
249
250
                url: "/searchDispatchFuel",
                templateUrl: "partials/searchDispatchFuel/searchDispatchFuel.html",
dd378d69f   Mr. Hot Foods   changes in flight...
251
252
253
254
                controller: "searchDispatchFuelController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
255
              })
3a9f4472b   Rishav   Implement contact...
256
              .state("app.Accept", {
4bb02bb84   Rishav   new integration w...
257
258
                url: "/Accept",
                templateUrl: "partials/Accept/Accept.html",
dd378d69f   Mr. Hot Foods   changes in flight...
259
260
261
262
                controller: "AcceptController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
263
              })
3a9f4472b   Rishav   Implement contact...
264
265
  
              .state("app.delselected", {
4bb02bb84   Rishav   new integration w...
266
267
                url: "/delselected",
                templateUrl: "partials/delselected/delselected.html",
dd378d69f   Mr. Hot Foods   changes in flight...
268
269
270
271
                controller: "delselectedController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
272
273
274
275
276
              })
              
              .state("app.pricingcontact", {
                url: "/pricingcontact",
                templateUrl: "partials/pricingcontact/pricingcontact.html",
dd378d69f   Mr. Hot Foods   changes in flight...
277
278
279
280
                controller: "pricingcontactController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
281
              })
3a9f4472b   Rishav   Implement contact...
282
              .state("app.viewContact", {
3cab9e8a3   Rishav   implement view co...
283
284
                url: "/viewContact/:id",
                templateUrl: "partials/viewcontact/viewcontact.html",
dd378d69f   Mr. Hot Foods   changes in flight...
285
286
287
288
                controller: "viewcontactController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
289
              })
d1fe89776   Rishav Singla   view fuel vendor ...
290
291
292
293
  
              .state("app.viewVendorContact", {
                url: "/viewVendorContact/:id",
                templateUrl: "partials/viewVendorContact/viewVendorContact.html",
dd378d69f   Mr. Hot Foods   changes in flight...
294
295
296
297
                controller: "viewVendorContactController",
                data: {
                    authorizedRoles: ["FBO"],
                }
d1fe89776   Rishav Singla   view fuel vendor ...
298
299
              })
              
8f7dbe97c   Swarn Singh   fuel order comple...
300
301
302
              .state("app.enterFuelOrder", {
                url: "/enterFuelOrder",
                templateUrl: "partials/enterFuelOrder/enterFuelOrder.html",
dd378d69f   Mr. Hot Foods   changes in flight...
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
                controller: "enterFuelOrderController",
                data: {
                    authorizedRoles: ["FBO"],
                }
              })
  
              .state("app.flightDepDashboard", {
                url: "/flightDepDashboard",
                templateUrl: "partials/flightDepDashboard/flightDepDashboard.html",
                controller: "flightDepDashboardController"
              })
  
              .state("app.flightDepOrders", {
                url: "/flightDepOrders",
                templateUrl: "partials/flightDepOrders/flightDepOrders.html",
                controller: "flightDepOrdersController"
8f7dbe97c   Swarn Singh   fuel order comple...
319
              })
feacde5ff   Rishav   setup acuefuel in...
320
          }
4bb02bb84   Rishav   new integration w...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
    ])
  
    .run(['$rootScope', '$state', 'LoginService', 'AUTH_EVENTS', function($rootScope, $state, LoginService, AUTH_EVENTS) {
        $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) {
            $rootScope.currentUser = JSON.parse(window.localStorage.getItem('currentUser'));
  
            LoginService.isAuthorized = function (authorizedRoles) {
                if (!angular.isArray(authorizedRoles)) {
                    authorizedRoles = [authorizedRoles];
                }
                var userdata = JSON.parse(window.localStorage.getItem('currentUser'));
                return (userdata? (authorizedRoles.indexOf(userdata.type) !== -1): false);
            }
            
            if ('data' in next && 'authorizedRoles' in next.data) {
              var authorizedRoles = next.data.authorizedRoles;
              if (!LoginService.isAuthorized(authorizedRoles)) {
                event.preventDefault();
                if($state.current.name.length == 0) {
                  $state.go('login')
                } else {
                  $state.go($state.current, {}, {reload: true});
                  $rootScope.$broadcast(AUTH_EVENTS.notAuthorized); 
                }
              }
            }
  
            if (LoginService.isAuthenticated()) {
              if (next.name == 'login') {
                event.preventDefault();
                $state.go('app.dashboard');
              }
dd378d69f   Mr. Hot Foods   changes in flight...
353
            }else{
c277275bb   Mr. Hot Foods   login changes
354
355
356
357
358
              // if (next.name == 'login') {
              //   event.preventDefault();
              //   $state.go('app.flightDepDashboard');
              // }
                
dd378d69f   Mr. Hot Foods   changes in flight...
359
              
4bb02bb84   Rishav   new integration w...
360
361
362
            }
        });
    }])
feacde5ff   Rishav   setup acuefuel in...
363

325c8ff31   Swarn Singh   date issue fixed
364
365
366
367
368
369
370
371
372
373
374
    
      .directive("datepicker",function(){
        return {
          restrict:"A",
          link:function(scope,el,attr){
            el.datepicker();
          }
        };
      })
   
    
feacde5ff   Rishav   setup acuefuel in...
375

32ea0c476   Swarn Singh   working on fuel m...
376

feacde5ff   Rishav   setup acuefuel in...
377