UI initial implementation.
[validation.git] / ui / src / main / webapp / resources / js / CommonController.js
1 /*
2  * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 var AECBlueprintValidationUIApp = angular
18         .module('BlueprintValidationUIManagement');
19
20 AECBlueprintValidationUIApp.controller('CommonController', function($scope,
21         $http, $sce, ngDialog, $filter, $rootScope, $state, $templateCache) {
22     $scope.errorHandle = function(error) {
23         if (error.status == 400) {
24             localStorage.removeItem("tokenId");
25             $state.transitionTo('login');
26             localStorage.removeItem("tokenId");
27             $rootScope.message = 'Session Invalid, please login again...';
28         } else if (error.status == 401) {
29             localStorage.removeItem("tokenId");
30             $state.transitionTo('login');
31             $rootScope.message = 'Invalid Credentials, please try again...';
32         } else if (error.status == 307) {
33             localStorage.removeItem("tokenId");
34             $state.transitionTo('login');
35             $rootScope.message = 'Session expired,Please try again...';
36         }
37     }
38
39     $scope.$on('onBeforeUnload', function(e, confirmation) {
40         var e2 = e || window.event;
41         if (e2) {
42             confirmation.message = "All data willl be lost.";
43             e2.preventDefault();
44         }
45     });
46     $scope.$on('onUnload', function() {
47         $templateCache.removeAll();
48     });
49
50     $scope.cmp = function(x, y) {
51         return x > y ? 1 : x < y ? -1 : 0;
52     };
53
54 });