Commit 87814a97a3b6c1d99b2b437dca7facf043fb0c68

Authored by Utkarsh Singh
1 parent 50e27950

changes regarding case browser refresh button click

400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js
1 1 'use strict';
2 2  
3   -AIA.controller("HomeController", ["$rootScope", "Modules", "$log", "$location", "$timeout", "DataService", "AuthenticationService", "LoginConstants","UserModules","LoginMessageConstants","AdminService", "AdminConstants", "UserTypeConstants",
4   -function ($rootScope, Modules, $log, $location, $timeout, DataService, AuthenticationService, LoginConstants, UserModules, LoginMessageConstants, AdminService, AdminConstants, UserTypeConstants) {
  3 +AIA.controller("HomeController", ["$rootScope", "Modules", "$log", "$location", "$timeout", "DataService", "AuthenticationService", "LoginConstants","UserModules","LoginMessageConstants","AdminService", "AdminConstants", "UserTypeConstants", "$window",
  4 +function ($rootScope, Modules, $log, $location, $timeout, DataService, AuthenticationService, LoginConstants, UserModules, LoginMessageConstants, AdminService, AdminConstants, UserTypeConstants, $window) {
5 5  
6 6 //$scope.pageToOpen = {
7 7 // name: 'MainMenu'
... ... @@ -135,8 +135,9 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
135 135 $rootScope.userModules = result.modules;
136 136 $rootScope.isVisibleLogin = false;
137 137  
138   - localStorage.setItem('loggedInUserDetails', JSON.stringify(result));
139   - $('#dvUserModulesInfo').modal('show');
  138 + sessionStorage.setItem('loggedInUserDetails', JSON.stringify(result));
  139 + $('#dvUserModulesInfo').modal('show');
  140 + $('#visited').val('1');
140 141  
141 142 var userType = result.userType + '';
142 143  
... ... @@ -175,14 +176,17 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
175 176  
176 177  
177 178 $rootScope.LogoutUser = function () {
178   - localStorage.removeItem('loggedInUserDetails');
179   - document.location = '/';
  179 + sessionStorage.removeItem('loggedInUserDetails');
  180 + localStorage.clear();
  181 + $('#visited').val('0');
  182 + //document.location = '/';
  183 + $location.path('/');
180 184 $rootScope.isVisibleLogin = true;
181 185 }
182 186  
183 187 function getUserDetails() {
184 188 //Retain logged in user details
185   - var currentUserDetails = localStorage.getItem('loggedInUserDetails');
  189 + var currentUserDetails = sessionStorage.getItem('loggedInUserDetails');
186 190 if (currentUserDetails) {
187 191 try {
188 192 var userInfo = JSON.parse(currentUserDetails);
... ... @@ -194,7 +198,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
194 198 }
195 199 }
196 200 catch (e) {
197   - localStorage.removeItem('loggedInUserDetails');
  201 + sessionStorage.removeItem('loggedInUserDetails');
198 202 }
199 203 }
200 204 }
... ... @@ -3359,9 +3363,51 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
3359 3363  
3360 3364 }
3361 3365  
3362   - $rootScope.CheckRefresh = function (e) {
3363   - if ((e.keyCode === 116) || (e.keyCode == 82 && e.ctrlKey))
  3366 + $rootScope.CheckRefresh = function (e) {
  3367 + e.preventDefault();
  3368 + if ((e.keyCode === 116) || (e.keyCode == 82 && e.ctrlKey) || $('#visited').val()==='1')
3364 3369 $location.path('/');
  3370 + //e.form.name.val();
  3371 + //var currentForm = document.forms[0]; //e.form.name.val();
  3372 + //var fcount = document.forms.length;
  3373 + //alert(currentForm);
  3374 + //if (document.body.visited.value == "")
  3375 + // document.body.visited.value = "1";
  3376 + //if(window.event)
  3377 + //{
  3378 + // if(window.event.clientX < 40 && window.event.clientY < 0)
  3379 + // {
  3380 + // alert("Browser back button is clicked...");
  3381 + // }
  3382 + // else
  3383 + // {
  3384 + // alert("Browser refresh button is clicked...");
  3385 + // }
  3386 + //}
  3387 + //else
  3388 + //{
  3389 + // if(event.currentTarget.performance.navigation.type == 1)
  3390 + // {
  3391 + // alert("Browser refresh button is clicked...");
  3392 + // }
  3393 + // if(event.currentTarget.performance.navigation.type == 2)
  3394 + // {
  3395 + // alert("Browser back button is clicked...");
  3396 + // }
  3397 + //}
  3398 + /*if($('#visited').length===0)
  3399 + $('#visited').val('1');
  3400 + else
  3401 + $location.path('/');*/
  3402 +
  3403 + //if ($window.event) {
  3404 + // if ($window.event.clientX < 40 && $window.event.clientY < 0) {
  3405 + // alert("Browser back button is clicked...");
  3406 + // }
  3407 + // else {
  3408 + // alert("Browser refresh button is clicked...");
  3409 + // }
  3410 + //}
3365 3411 };
3366 3412 }]
3367 3413 );
3368 3414 \ No newline at end of file
... ...
400-SOURCECODE/AIAHTML5.Web/index.html
... ... @@ -160,7 +160,7 @@
160 160  
161 161  
162 162 </head>
163   -<body ng-controller="HomeController" id="bo" ng-init="initializeAIA()" ng-keydown="CheckRefresh($event)">
  163 +<body ng-controller="HomeController" id="bo" ng-init="initializeAIA()" ng-keydown="CheckRefresh($event)"><!-- onload="alert('called..')"JavaScript:checkRefresh();-->
164 164 <div ng-hide="isVisibleResetPass">
165 165 <div id="login" ng-show="isVisibleLogin">
166 166  
... ... @@ -1293,7 +1293,7 @@
1293 1293 </div>
1294 1294 </div>
1295 1295 </div>
1296   -
  1296 + <input type="hidden" name="visited" id="visited" value="" />
1297 1297 <script>
1298 1298  
1299 1299 function enableDisableFillOption() {
... ... @@ -1918,6 +1918,49 @@
1918 1918 }
1919 1919 }
1920 1920 </script>
  1921 + <script>
  1922 + function checkRefresh() {
  1923 + // Get the time now and convert to UTC seconds
  1924 + var today = new Date();
  1925 + var now = today.getUTCSeconds();
  1926 + document.cookie = 'CURRENT_TIME=' + now + ';';
  1927 + document.cookie = 'CURRENT_URL=' + escape(location.href) + ';';
  1928 + // Get the cookie
  1929 + var cookie = document.cookie;
  1930 + var cookieArray = cookie.split('; ');
  1931 +
  1932 + // Parse the cookies: get the stored time
  1933 + for (var loop = 0; loop < cookieArray.length; loop++) {
  1934 + var nameValue = cookieArray[loop].split('=');
  1935 + // Get the cookie time stamp
  1936 + if (nameValue[0].toString() == 'CURRENT_TIME') {
  1937 + var cookieTime = parseInt(nameValue[1]);
  1938 + }
  1939 + // Get the cookie page
  1940 + else if (nameValue[0].toString() == 'CURRENT_URL') {
  1941 + var cookieName = nameValue[1];
  1942 + }
  1943 + }
  1944 +
  1945 + if (cookieName &&
  1946 + cookieTime &&
  1947 + cookieName == escape(location.href) &&
  1948 + Math.abs(now - cookieTime) < 5) {
  1949 + // Refresh detected
  1950 + document.location.href = '/';
  1951 + // Insert code here representing what to do on
  1952 + // a refresh
  1953 +
  1954 + // If you would like to toggle so this refresh code
  1955 + // is executed on every OTHER refresh, then
  1956 + // uncomment the following line
  1957 + // refresh_prepare = 0;
  1958 + }
  1959 +
  1960 + // You may want to add code in an else here special
  1961 + // for fresh page loads
  1962 + }
  1963 + </script>
1921 1964 </body>
1922 1965  
1923 1966 </html>
1924 1967 \ No newline at end of file
... ...