Blame view

app/js/app.js 9.49 KB
feacde5ff   Rishav   setup acuefuel in...
1
  'use strict';
7e481a068   Rishav   implement toogle ...
2
    angular.module('acufuel', ['ngCookies', 'ngResource', 'ui.router', 'ngAnimate', 'ui.bootstrap', 'xeditable', 'ui.toggle'])
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
81
82
  
    .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",
                controller: "customersController"
              })
3a9f4472b   Rishav   Implement contact...
83
84
85
86
87
88
  
              .state("app.accountSetting", {
                url: "/accountSetting",
                templateUrl: "partials/accountSetting/accountSetting.html",
                controller: "AccountSettingController"
              })
4bb02bb84   Rishav   new integration w...
89
90
91
92
93
94
95
96
97
98
              .state("app.ContactView", {
                url: "/ContactView",
                templateUrl: "partials/ContactView/ContactView.html",
                controller: "ContactViewController"
              })
              .state("app.FuelVendors", {
                url: "/FuelVendors",
                templateUrl: "partials/FuelVendors/FuelVendors.html",
                controller: "FuelVendorsController"
              })
feacde5ff   Rishav   setup acuefuel in...
99
100
101
102
103
104
105
106
107
108
109
110
111
  
              .state("app.analytics", {
                url: "/analytics",
                templateUrl: "partials/analytics/analytics.html",
                controller: "analyticsController"
              })
  
              .state("app.account", {
                url: "/account",
                templateUrl: "partials/account/account.html",
                controller: "accountController"
              })
              
3a9f4472b   Rishav   Implement contact...
112
              .state("app.dashboard", {
feacde5ff   Rishav   setup acuefuel in...
113
114
115
116
                url: "/dashboard",
                templateUrl: "partials/dashboard/dashboard.html",
                controller: "dashboardController"
              })
feacde5ff   Rishav   setup acuefuel in...
117
118
119
120
121
              .state("app.elements", {
                url: "/elements",
                templateUrl: "partials/elements/elements.html",
                controller: "elementsController"
              })
feacde5ff   Rishav   setup acuefuel in...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
              .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",
                controller: "formsController"
              })
  
              .state("app.fuelManager", {
                url: "/fuelManager",
                templateUrl: "partials/fuelManager/fuelManager.html",
                controller: "fuelManagerController"
              })
feacde5ff   Rishav   setup acuefuel in...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
              .state("app.pricing", {
                url: "/pricing",
                templateUrl: "partials/pricing/pricing.html",
                controller: "pricingController"
              })
  
              .state("app.reports", {
                url: "/reports",
                templateUrl: "partials/reports/reports.html",
                controller: "reportsController"
              })
  
              .state("app.scheduler", {
                url: "/scheduler",
                templateUrl: "partials/scheduler/scheduler.html",
                controller: "schedulerController"
              })
              .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...
171
172
173
174
                controller: "updateFuelManagerController",
                // data: {
                //     authorizedRoles: ["fbo"],
                // }
feacde5ff   Rishav   setup acuefuel in...
175
              })
cd330b5ee   Rishav   fuel vendor and v...
176
              .state("app.viewCompany", {
55e075d7e   Rishav   add contact, add ...
177
                url: "/viewCompany/:id",
feacde5ff   Rishav   setup acuefuel in...
178
179
180
                templateUrl: "partials/viewCompany/viewCompany.html",
                controller: "viewCompanyController"
              }) 
ea15674c8   Rishav   minor changes for...
181
182
183
184
              .state("app.viewFuelVendor", {
                url: "/viewFuelVendor/:id",
                templateUrl: "partials/viewFuelVendor/viewFuelVendor.html",
                controller: "ViewFuelVendorController"
cd330b5ee   Rishav   fuel vendor and v...
185
              }) 
88dad9efc   Rishav   remove unused fil...
186
              .state("app.fuelOrders", {
4bb02bb84   Rishav   new integration w...
187
188
189
190
191
192
193
194
195
196
                url: "/fuelOrders",
                templateUrl: "partials/fuelOrders/fuelOrders.html",
                controller: "fuelOrdersController"
              })
  
               .state("app.DispatchFuel", {
                url: "/DispatchFuel",
                templateUrl: "partials/DispatchFuel/DispatchFuel.html",
                controller: "DispatchFuelController"
              })
3a9f4472b   Rishav   Implement contact...
197
              .state("app.searchDispatchFuel", {
4bb02bb84   Rishav   new integration w...
198
199
200
201
                url: "/searchDispatchFuel",
                templateUrl: "partials/searchDispatchFuel/searchDispatchFuel.html",
                controller: "searchDispatchFuelController"
              })
3a9f4472b   Rishav   Implement contact...
202
              .state("app.Accept", {
4bb02bb84   Rishav   new integration w...
203
204
205
206
                url: "/Accept",
                templateUrl: "partials/Accept/Accept.html",
                controller: "AcceptController"
              })
3a9f4472b   Rishav   Implement contact...
207
208
  
              .state("app.delselected", {
4bb02bb84   Rishav   new integration w...
209
210
211
212
213
214
215
216
217
218
                url: "/delselected",
                templateUrl: "partials/delselected/delselected.html",
                controller: "delselectedController"
              })
              
              .state("app.pricingcontact", {
                url: "/pricingcontact",
                templateUrl: "partials/pricingcontact/pricingcontact.html",
                controller: "pricingcontactController"
              })
3a9f4472b   Rishav   Implement contact...
219
              .state("app.viewContact", {
3cab9e8a3   Rishav   implement view co...
220
221
222
                url: "/viewContact/:id",
                templateUrl: "partials/viewcontact/viewcontact.html",
                controller: "viewcontactController"
4bb02bb84   Rishav   new integration w...
223
              })
feacde5ff   Rishav   setup acuefuel in...
224
          }
4bb02bb84   Rishav   new integration w...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
    ])
  
    .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');
              }
            }
        });
    }])
feacde5ff   Rishav   setup acuefuel in...
260

32ea0c476   Swarn Singh   working on fuel m...
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
    .directive("datepicker", function () {
      return {
        restrict: "A",
        require: "ngModel",
        link: function (scope, elem, attrs, ngModelCtrl) {
          var updateModel = function (dateText) {
            scope.$apply(function () {
              ngModelCtrl.$setViewValue(dateText);
            });
          };
          var options = {
            dateFormat: "dd/mm/yy",
            onSelect: function (dateText) {
              updateModel(dateText);
            }
          };
          elem.datepicker(options);
        }
      }
    })
feacde5ff   Rishav   setup acuefuel in...
281