Guest User

Untitled

a guest
Dec 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. $.ajax({
  2. type: "GET",
  3. url: 'http://localhost:59927//api//GARO//GetGAROList',
  4. success: function (data, status, xhr) {
  5. data = JSON.parse(data);
  6. var l1 = document.createElement('li');
  7. l1.className = "FirstClass";
  8. document.getElementById('dropdown').appendChild(l1);
  9. for (var i = 0; i < data.Table.length; i++) {
  10.  
  11. $.each(data.Table[i], function (key, values) {
  12. count++;
  13. var li = document.createElement('a');
  14. li.setAttribute('class', 'dropdown-toggle');
  15. li.setAttribute('href', '#homeSubmenu' + count);
  16. li.setAttribute('data-toggle', 'collapse');
  17. li.setAttribute('aria-expanded', 'false');
  18. l1.appendChild(li);
  19. li.textContent = key;
  20. var i = document.createElement('i');
  21. i.setAttribute('class', 'fas fa-layer-group');
  22. li.appendChild(i);
  23. var ul = document.createElement('ul');
  24. ul.setAttribute('class', 'collapse list-unstyled');
  25. ul.setAttribute('id', 'homeSubmenu' + count);
  26. l1.appendChild(ul);
  27. li = document.createElement('li');
  28. ul.appendChild(li);
  29. $.each(values, function (i, val) {
  30. var a1 = document.createElement('a');
  31. a1.setAttribute('href', '');
  32. li.appendChild(a1);
  33. a1.textContent = val;
  34. a1.setAttribute('value', val);
  35. a1.onclick = function () {
  36. value = a1.getAttribute('value');
  37. getCookie("Token", value);
  38.  
  39. return false;
  40. };
  41.  
  42.  
  43. });
  44. });
  45.  
  46.  
  47. }
  48. },
  49. error: function (xhr) {
  50. alert(xhr.responseText);
  51. }
  52. });
  53. $.ajax({
  54. type: "GET",
  55. url: 'http://localhost:59927//api//Values//FlagingDevice(WithoutParameters)',
  56. contentType: 'application/json; charset=utf-8',
  57. dataType: 'json',
  58. success: function (data, status, xhr) {
  59. for (var i = 0; i < data.Table.length; i++) {
  60. circle[i] = L.circle([data.Table[i].Latitude, data.Table[i].Longitude], 50, { color: '#FFFFFF', opacity: 0.5, fillColor: 'red', fillOpacity: .3 }).addTo(map);
  61. data1[i] = { Latitude: data.Table[i].Latitude, Longitude: data.Table[i].Longitude };
  62. }
  63. },
  64. error: function (xhr) {
  65. alert(xhr.responseText);
  66. }
  67. });
  68.  
  69.  
  70.  
  71. function getCookie(Token, value) {
  72. alert(value);
  73. variable = value;
  74. var name = Token + "=";
  75. var decodedCookie = decodeURIComponent(document.cookie);
  76. var ca = decodedCookie.split(';');
  77. for (var i = 0; i < ca.length; i++) {
  78. var c = ca[i];
  79. while (c.charAt(0) === ' ') {
  80. c = c.substring(1);
  81. }
  82. if (c.indexOf(name) === 0) {
  83. $.ajax({
  84. type: "POST",
  85. url: 'http://localhost:59927//api//Values//GetLocation',
  86. data: {
  87. DivisionName: value
  88. },
  89. success: function (data, status, xhr) {
  90.  
  91. for (var s = 0; s < marker1.length; s++) {
  92. map.removeLayer(marker1[s]);
  93. }
  94.  
  95. for (var i = 0; i < data.length; i++) {
  96. check = geolib.isPointInCircle(
  97. { latitude: data[i].Latitude, longitude: data[i].Longitude },
  98. { latitude: data1[i].Latitude, longitude: data1[i].Longitude },
  99. 5000
  100. );
  101. marker1[i] = L.marker([data[i].Latitude, data[i].Longitude]);
  102. var value = i + 1;
  103. if (check == true) {
  104. var customPopup1 = 'Station: ' + data[i].PollingStationName;
  105.  
  106. var customOptions1 =
  107. {
  108. 'maxWidth': '500',
  109. 'className': 'custom'
  110.  
  111. };
  112.  
  113. circle[i].bindPopup(customPopup1, customOptions1);
  114.  
  115. }
  116.  
  117. else {
  118. marker1[i] = L.marker([data[i].Latitude, data[i].Longitude]).addTo(map);
  119.  
  120. var customPopup = 'Latitude: ' + data[i].Latitude + '</br>Longitude: ' + data[i].Longitude
  121. + '</br>Station: ' + data[i].PollingStationName + ' </br>Box: ' + data[i].BoxName + '</br>Timestamp: ' + data[i].LocationSend
  122. + `<br/><a href='/Home/History?DeviceID=${value}'>Click here for Location History</a><br/>`;
  123.  
  124. marker1[i].bindPopup(customPopup);
  125. }
  126.  
  127.  
  128.  
  129.  
  130.  
  131. }
  132. setTimeout(function () { getCookie("Token", variable); }, 30000);
  133.  
  134. },
  135. error: function (xhr) {
  136. alert(xhr.responseText);
  137. }
  138. });
  139.  
  140. return c.substring(Token.length, c.length);
  141. }
  142. }
  143. if (window.location.href === 'http://localhost:59927/Home/Login') {
  144. return;
  145. }
  146. else {
  147. alert("Session Has Expired");
  148. location.href = "http://localhost:59927/Home/Login";
  149. }
  150.  
  151. }
Add Comment
Please, Sign In to add comment