Blame view

app/js/app.js 16.9 KB
feacde5ff   Rishav   setup acuefuel in...
1
  'use strict';
97f8c67f9   Rishav Singla   ui select impplem...
2
    angular.module('acufuel', ['nvd3', 'ngCookies', 'ngResource', 'ngSanitize', 'ui.router', 'ngAnimate', 'ui.bootstrap', 'xeditable', 'ui.toggle', 'ngTable', 'ui.select2', 'ckeditor', 'ui.calendar', 'ngDragDrop', 'ui.select'])
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
  
      .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);
             }
           }
       }])
acc03531d   Anchit Jindal   fixes
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
       
       .directive('fileModel', ['$parse', function ($parse) {
          return {
             restrict: 'A',
             link: function(scope, element, attrs) {
                var model = $parse(attrs.fileModel);
                var modelSetter = model.assign;
                
                element.bind('change', function(){
                   scope.$apply(function(){
                      modelSetter(scope, element[0].files[0]);
                   });
                });
             }
          };
       }])
4bb02bb84   Rishav   new integration w...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
      
      .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...
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  
    .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...
97
98
99
100
                controller: "customersController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
101
              })
3a9f4472b   Rishav   Implement contact...
102
103
104
105
  
              .state("app.accountSetting", {
                url: "/accountSetting",
                templateUrl: "partials/accountSetting/accountSetting.html",
dd378d69f   Mr. Hot Foods   changes in flight...
106
107
108
109
                controller: "AccountSettingController",
                data: {
                    authorizedRoles: ["FBO"],
                }
3a9f4472b   Rishav   Implement contact...
110
              })
4bb02bb84   Rishav   new integration w...
111
112
113
              .state("app.ContactView", {
                url: "/ContactView",
                templateUrl: "partials/ContactView/ContactView.html",
dd378d69f   Mr. Hot Foods   changes in flight...
114
115
116
117
                controller: "ContactViewController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
118
119
120
121
              })
              .state("app.FuelVendors", {
                url: "/FuelVendors",
                templateUrl: "partials/FuelVendors/FuelVendors.html",
dd378d69f   Mr. Hot Foods   changes in flight...
122
123
124
125
                controller: "FuelVendorsController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
126
              })
feacde5ff   Rishav   setup acuefuel in...
127
128
129
130
  
              .state("app.analytics", {
                url: "/analytics",
                templateUrl: "partials/analytics/analytics.html",
dd378d69f   Mr. Hot Foods   changes in flight...
131
132
133
134
                controller: "analyticsController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
135
136
137
              })
  
              .state("app.account", {
3604ba8cb   Kuldeep Arora   updates
138
139
140
                url: "/vendors",
                templateUrl: "partials/FuelVendors/FuelVendors.html",
                controller: "FuelVendorsController",
dd378d69f   Mr. Hot Foods   changes in flight...
141
142
143
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
144
145
              })
              
3a9f4472b   Rishav   Implement contact...
146
              .state("app.dashboard", {
feacde5ff   Rishav   setup acuefuel in...
147
148
                url: "/dashboard",
                templateUrl: "partials/dashboard/dashboard.html",
dd378d69f   Mr. Hot Foods   changes in flight...
149
150
                controller: "dashboardController",
                data: {
671643c9f   Kuldeep Arora   additional user
151
                    authorizedRoles: ["FBO","ADDITIONAL"],
dd378d69f   Mr. Hot Foods   changes in flight...
152
                }
feacde5ff   Rishav   setup acuefuel in...
153
              })
feacde5ff   Rishav   setup acuefuel in...
154
155
156
              .state("app.elements", {
                url: "/elements",
                templateUrl: "partials/elements/elements.html",
dd378d69f   Mr. Hot Foods   changes in flight...
157
158
159
160
                controller: "elementsController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
161
              })
feacde5ff   Rishav   setup acuefuel in...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
              .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...
177
178
179
180
                controller: "formsController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
181
182
183
184
185
              })
  
              .state("app.fuelManager", {
                url: "/fuelManager",
                templateUrl: "partials/fuelManager/fuelManager.html",
dd378d69f   Mr. Hot Foods   changes in flight...
186
187
188
189
                controller: "fuelManagerController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
190
              })
feacde5ff   Rishav   setup acuefuel in...
191
192
193
              .state("app.pricing", {
                url: "/pricing",
                templateUrl: "partials/pricing/pricing.html",
dd378d69f   Mr. Hot Foods   changes in flight...
194
195
196
197
                controller: "pricingController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
198
199
200
201
202
              })
  
              .state("app.reports", {
                url: "/reports",
                templateUrl: "partials/reports/reports.html",
dd378d69f   Mr. Hot Foods   changes in flight...
203
204
205
206
                controller: "reportsController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
207
208
209
210
211
              })
  
              .state("app.scheduler", {
                url: "/scheduler",
                templateUrl: "partials/scheduler/scheduler.html",
dd378d69f   Mr. Hot Foods   changes in flight...
212
213
214
215
                controller: "schedulerController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
216
              })
e196b9b74   Anchit Jindal   new changes added
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
              
              .state("app.flightTracking", {
                url: "/flightTracking",
                templateUrl: "partials/flightTracking/flightTracking.html",
                controller: "flightTrackingController",
                data: {
                    authorizedRoles: ["FBO"],
                }
              })
              
              .state("app.taxes", {
                url: "/taxes",
                templateUrl: "partials/taxes/taxes.html",
                controller: "taxesController",
                data: {
                    authorizedRoles: ["FBO"],
                }
              })
              
feacde5ff   Rishav   setup acuefuel in...
236
237
238
239
240
241
242
243
244
              .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...
245
                controller: "updateFuelManagerController",
dd378d69f   Mr. Hot Foods   changes in flight...
246
247
248
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
249
              })
cd330b5ee   Rishav   fuel vendor and v...
250
              .state("app.viewCompany", {
55e075d7e   Rishav   add contact, add ...
251
                url: "/viewCompany/:id",
feacde5ff   Rishav   setup acuefuel in...
252
                templateUrl: "partials/viewCompany/viewCompany.html",
dd378d69f   Mr. Hot Foods   changes in flight...
253
254
255
256
                controller: "viewCompanyController",
                data: {
                    authorizedRoles: ["FBO"],
                }
feacde5ff   Rishav   setup acuefuel in...
257
              }) 
ea15674c8   Rishav   minor changes for...
258
259
260
              .state("app.viewFuelVendor", {
                url: "/viewFuelVendor/:id",
                templateUrl: "partials/viewFuelVendor/viewFuelVendor.html",
dd378d69f   Mr. Hot Foods   changes in flight...
261
262
263
264
                controller: "ViewFuelVendorController",
                data: {
                    authorizedRoles: ["FBO"],
                }
cd330b5ee   Rishav   fuel vendor and v...
265
              }) 
88dad9efc   Rishav   remove unused fil...
266
              .state("app.fuelOrders", {
4bb02bb84   Rishav   new integration w...
267
268
                url: "/fuelOrders",
                templateUrl: "partials/fuelOrders/fuelOrders.html",
dd378d69f   Mr. Hot Foods   changes in flight...
269
270
271
272
                controller: "fuelOrdersController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
273
274
275
276
277
              })
  
               .state("app.DispatchFuel", {
                url: "/DispatchFuel",
                templateUrl: "partials/DispatchFuel/DispatchFuel.html",
dd378d69f   Mr. Hot Foods   changes in flight...
278
279
280
281
                controller: "DispatchFuelController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
282
              })
3a9f4472b   Rishav   Implement contact...
283
              .state("app.searchDispatchFuel", {
4bb02bb84   Rishav   new integration w...
284
285
                url: "/searchDispatchFuel",
                templateUrl: "partials/searchDispatchFuel/searchDispatchFuel.html",
dd378d69f   Mr. Hot Foods   changes in flight...
286
287
288
289
                controller: "searchDispatchFuelController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
290
              })
3a9f4472b   Rishav   Implement contact...
291
              .state("app.Accept", {
4bb02bb84   Rishav   new integration w...
292
293
                url: "/Accept",
                templateUrl: "partials/Accept/Accept.html",
dd378d69f   Mr. Hot Foods   changes in flight...
294
295
296
297
                controller: "AcceptController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
298
              })
3a9f4472b   Rishav   Implement contact...
299
300
  
              .state("app.delselected", {
4bb02bb84   Rishav   new integration w...
301
302
                url: "/delselected",
                templateUrl: "partials/delselected/delselected.html",
dd378d69f   Mr. Hot Foods   changes in flight...
303
304
305
306
                controller: "delselectedController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
307
308
309
310
311
              })
              
              .state("app.pricingcontact", {
                url: "/pricingcontact",
                templateUrl: "partials/pricingcontact/pricingcontact.html",
dd378d69f   Mr. Hot Foods   changes in flight...
312
313
314
315
                controller: "pricingcontactController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
316
              })
3a9f4472b   Rishav   Implement contact...
317
              .state("app.viewContact", {
3cab9e8a3   Rishav   implement view co...
318
319
                url: "/viewContact/:id",
                templateUrl: "partials/viewcontact/viewcontact.html",
dd378d69f   Mr. Hot Foods   changes in flight...
320
321
322
323
                controller: "viewcontactController",
                data: {
                    authorizedRoles: ["FBO"],
                }
4bb02bb84   Rishav   new integration w...
324
              })
d1fe89776   Rishav Singla   view fuel vendor ...
325
326
327
328
  
              .state("app.viewVendorContact", {
                url: "/viewVendorContact/:id",
                templateUrl: "partials/viewVendorContact/viewVendorContact.html",
dd378d69f   Mr. Hot Foods   changes in flight...
329
330
331
332
                controller: "viewVendorContactController",
                data: {
                    authorizedRoles: ["FBO"],
                }
d1fe89776   Rishav Singla   view fuel vendor ...
333
334
              })
              
8f7dbe97c   Swarn Singh   fuel order comple...
335
336
337
              .state("app.enterFuelOrder", {
                url: "/enterFuelOrder",
                templateUrl: "partials/enterFuelOrder/enterFuelOrder.html",
dd378d69f   Mr. Hot Foods   changes in flight...
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
                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...
354
              })
d121d5539   Kuldeep Arora   UI Changes
355
356
357
358
359
              .state("forgetPassword", {
               url: "/forgetPassword",
               templateUrl: "partials/forgetPassword/forgetPassword.html",
               controller: "forgetPasswordController"
             })
feacde5ff   Rishav   setup acuefuel in...
360
          }
4bb02bb84   Rishav   new integration w...
361
362
363
364
    ])
  
    .run(['$rootScope', '$state', 'LoginService', 'AUTH_EVENTS', function($rootScope, $state, LoginService, AUTH_EVENTS) {
        $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) {
5ff103048   Kuldeep Arora   updates
365
366
            //console.log("from",from, "fromState",fromState)
            $rootScope.previousState = fromState.name;
4bb02bb84   Rishav   new integration w...
367
            $rootScope.currentUser = JSON.parse(window.localStorage.getItem('currentUser'));
565570086   Kuldeep Arora   highcharts(MFS,CS...
368
           // console.log("nextParams",nextParams)
4bb02bb84   Rishav   new integration w...
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
            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...
395
            }else{
c277275bb   Mr. Hot Foods   login changes
396
397
398
399
400
              // if (next.name == 'login') {
              //   event.preventDefault();
              //   $state.go('app.flightDepDashboard');
              // }
                
dd378d69f   Mr. Hot Foods   changes in flight...
401
              
4bb02bb84   Rishav   new integration w...
402
403
404
            }
        });
    }])
feacde5ff   Rishav   setup acuefuel in...
405

d121d5539   Kuldeep Arora   UI Changes
406
       
325c8ff31   Swarn Singh   date issue fixed
407
408
409
410
411
412
413
414
      .directive("datepicker",function(){
        return {
          restrict:"A",
          link:function(scope,el,attr){
            el.datepicker();
          }
        };
      })
325c8ff31   Swarn Singh   date issue fixed
415
    
cf8827d2e   Kuldeep Arora   decimal points fixed
416
    /* Valid number for upto 4 decimal points-Input type */
32ea0c476   Swarn Singh   working on fuel m...
417

cf8827d2e   Kuldeep Arora   decimal points fixed
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
      .directive('validNumber', function() {
        return {
          require: '?ngModel',
          link: function(scope, element, attrs, ngModelCtrl) {
            if(!ngModelCtrl) {
              return; 
            }
  
            ngModelCtrl.$parsers.push(function(val) {
              if (angular.isUndefined(val)) {
                  var val = '';
              }
              
              var clean = val.replace(/[^-0-9\.]/g, '');
              var negativeCheck = clean.split('-');
        var decimalCheck = clean.split('.');
              if(!angular.isUndefined(negativeCheck[1])) {
                  negativeCheck[1] = negativeCheck[1].slice(0, negativeCheck[1].length);
                  clean =negativeCheck[0] + '-' + negativeCheck[1];
                  if(negativeCheck[0].length > 0) {
                    clean =negativeCheck[0];
                  }
                  
              }
                
              if(!angular.isUndefined(decimalCheck[1])) {
                  decimalCheck[1] = decimalCheck[1].slice(0,4);
                  clean =decimalCheck[0] + '.' + decimalCheck[1];
              }
  
              if (val !== clean) {
                ngModelCtrl.$setViewValue(clean);
                ngModelCtrl.$render();
              }
              return clean;
            });
  
            element.bind('keypress', function(event) {
              if(event.keyCode === 32) {
                event.preventDefault();
              }
            });
          }
        };
      })
   /* Valid number for upto 2 decimal points-Input type */
      .directive('decimalNumber', function() {
            return {
              require: '?ngModel',
              link: function(scope, element, attrs, ngModelCtrl) {
                if(!ngModelCtrl) {
                  return; 
                }
  
                ngModelCtrl.$parsers.push(function(val) {
                  if (angular.isUndefined(val)) {
                      var val = '';
                  }
                  
                  var clean = val.replace(/[^-0-9\.]/g, '');
                  var negativeCheck = clean.split('-');
                  var decimalCheck = clean.split('.');
                  if(!angular.isUndefined(negativeCheck[1])) {
                      negativeCheck[1] = negativeCheck[1].slice(0, negativeCheck[1].length);
                      clean =negativeCheck[0] + '-' + negativeCheck[1];
                      if(negativeCheck[0].length > 0) {
                        clean =negativeCheck[0];
                      }
                      
                  }
                    
                  if(!angular.isUndefined(decimalCheck[1])) {
                      decimalCheck[1] = decimalCheck[1].slice(0,2);
                      clean =decimalCheck[0] + '.' + decimalCheck[1];
                  }
  
                  if (val !== clean) {
                    ngModelCtrl.$setViewValue(clean);
                    ngModelCtrl.$render();
                  }
                  return clean;
                });
  
                element.bind('keypress', function(event) {
                  if(event.keyCode === 32) {
                    event.preventDefault();
                  }
                });
              }
            };
          });
feacde5ff   Rishav   setup acuefuel in...
509