Advertisement
Guest User

Untitled

a guest
May 24th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.57 KB | None | 0 0
  1. var map;
  2. var formShown = false;
  3. var debtShown = false;
  4. var loadmap = function (mapId) {
  5. map = new google.maps.Map(document.getElementById(mapId), {
  6. center: {lat: 51.13, lng: 3.13},
  7. scrollwheel: false,
  8. zoom: 8
  9. });
  10. };
  11.  
  12. var loadEventMap = function () {
  13. if (window.location.pathname === "/DebtAware/CEvent.php") {
  14. console.log('hey');
  15. loadmap('map1');
  16. google.maps.event.addListener(map, 'click', function (event) {
  17. addBar(event.latLng);
  18. });
  19. infoWindow = new google.maps.InfoWindow;
  20. $("#loader").show();
  21.  
  22. if (navigator.geolocation) {
  23. navigator.geolocation.getCurrentPosition(function (position) {
  24. var pos = {
  25. lat: position.coords.latitude,
  26. lng: position.coords.longitude
  27. };
  28. infoWindow.setPosition(pos);
  29. $("#loader").hide();
  30. infoWindow.setContent('Location found.');
  31. infoWindow.open(map);
  32. map.setCenter(pos);
  33. }, function () {
  34. handleLocationError(true, infoWindow, map.getCenter());
  35. });
  36. } else {
  37. handleLocationError(false, infoWindow, map.getCenter());
  38. }
  39. }
  40. };
  41.  
  42. var handleLocationError = function (browserHasGeolocation, infoWindow, pos) {
  43. infoWindow.setPosition(pos);
  44. $("#loadingtest").html("");
  45. infoWindow.setContent(browserHasGeolocation ?
  46. 'Error: The Geolocation service failed.' :
  47. 'Error: Your browser doesn\'t support geolocation.');
  48. infoWindow.open(map);
  49. };
  50.  
  51. var startup = function () {
  52. regCacheApi();
  53. $('select').material_select();
  54. $('.button-collapse').sideNav({
  55. menuWidth: 300, // Default is 300
  56. edge: 'left', // Choose the horizontal origin
  57. closeOnClick: false, // Closes side-nav on <a> clicks, useful for Angular/Meteor
  58. draggable: true // Choose whether you can drag to open on touch screens
  59. });
  60. $(document).ready(function () {
  61. $('select').material_select();
  62. });
  63. $('.carousel.carousel-slider').carousel({
  64. fullWidth: true,
  65. height: 200
  66. });
  67. $('#peopleForm').hide();
  68. $('#addDebt').hide();
  69. };
  70.  
  71. var addPeople = function (e) {
  72. e.preventDefault();
  73. var data = {
  74. name: $('#eventName').val(),
  75. description: $('#textarea1').val(),
  76. long: 32,
  77. lat: 23
  78. };
  79. $.ajax({
  80. url: '/DebtAware/process.php',
  81. data: {userd: data, action: 'processEventForm'},
  82. type: 'post',
  83. success: function (output) {
  84. console.log(output);
  85. }
  86. });
  87. window.location.assign('People.php');
  88. };
  89.  
  90. var goToEvent = function () {
  91. $('#addPeople').slideUp();
  92. $('#event').slideDown();
  93. };
  94.  
  95. var goToWelcome = function () {
  96. $('#addPeople').hide();
  97. $('#event').hide();
  98. $('#welcome').slideDown();
  99. };
  100.  
  101. var goToAddDebt = function () {
  102. console.log('jow');
  103. if (!debtShown){
  104. $('#event').slideUp();
  105. $('#addDebt').slideDown();
  106. debtShown = true;
  107. } else{
  108. $('#event').slideDown();
  109. $('#addDebt').slideUp();
  110. debtShown = false;
  111. }
  112. };
  113.  
  114. var addDebt = function (e) {
  115. e.preventDefault();
  116. $('#selectedPersonEvent').material_select();
  117. var id = $('#selectedPersonEvent').val();
  118. var amount = $('#formAmount').val();
  119. console.log(id + "+" + amount);
  120. data = {
  121. id: id,
  122. amount: amount
  123. };
  124. $.ajax({
  125. url: '/DebtAware/process.php',
  126. data: {userd: data, action: 'processDebt'},
  127. type: 'post',
  128. success: function (output) {
  129. console.log(output);
  130. }
  131. });
  132. window.location.assign('event.php');
  133. };
  134.  
  135. var addPersonForm = function () {
  136. if (!formShown) {
  137. $('#peopleForm').slideDown();
  138. formShown = true;
  139. } else {
  140. $('#peopleForm').slideUp();
  141. formShown = false;
  142. }
  143. };
  144.  
  145. var addPersonProcessForm = function (e) {
  146. e.preventDefault();
  147. $('#selectedPerson').material_select();
  148. var id = $('#selectedPerson').val();
  149. data = {
  150. id: id
  151. };
  152. $.ajax({
  153. url: '/DebtAware/process.php',
  154. data: {userd: data, action: 'addPerson'},
  155. type: 'post',
  156. success: function (output) {
  157. console.log(output);
  158. var newOutput = JSON.parse(output);
  159. showPersons(newOutput);
  160. }
  161. });
  162. };
  163.  
  164. var showPersons = function (output) {
  165. html = "";
  166. output.forEach(function (o) {
  167. html += "<tr><td>" + o.name + "</td><td>" + o.ccnumber + "</td></tr>";
  168. });
  169. console.log(html);
  170. $('#addTableRow').html(html);
  171. };
  172.  
  173. var showHeaderEvent = function () {
  174. console.log();
  175. data = {
  176. eventid: $(this).val()
  177. };
  178. $.ajax({
  179. url: '/DebtAware/process.php',
  180. data: {userd: data, action: 'showEvent'},
  181. type: 'post',
  182. success: function (output) {
  183. window.location.assign('event.php');
  184. }
  185. });
  186. };
  187.  
  188. var validateRegister = function (e) {
  189. e.preventDefault();
  190. data = {
  191. username: $('#registername').val(),
  192. email: $('#registeremail').val(),
  193. password: $('#registerpass').val(),
  194. rpassword: $('#registerpass2').val(),
  195. ccnumber: $('#registerccNumber').val()
  196. };
  197. $.ajax({
  198. url: '/DebtAware/process.php',
  199. data: {userd: data, action: 'ValidateRegister'},
  200. type: 'post',
  201. success: function (output) {
  202. var errormessage = JSON.parse(output);
  203. console.log(errormessage);
  204. if (errormessage[0] == "error") {
  205. writeErrors(errormessage);
  206. } else {
  207. window.location.assign('index.php');
  208. }
  209. }
  210. });
  211. };
  212.  
  213. var validateLogin = function (e) {
  214. e.preventDefault();
  215. data = {
  216. username: $('#loginusername').val(),
  217. password: $('#loginpassword').val()
  218. };
  219. $.ajax({
  220. url: '/DebtAware/process.php',
  221. data: {userd: data, action: 'ValidateLogin'},
  222. type: 'post',
  223. success: function (output) {
  224. var errormessage = JSON.parse(output);
  225. if (errormessage[0] == "error") {
  226. console.log(output);
  227. writeErrors(errormessage);
  228. } else {
  229. window.location.assign('index.php');
  230. }
  231. }
  232. });
  233. };
  234.  
  235. var writeErrors = function (errors) {
  236. var html = "<div><i class='large material-icons'>info_outline</i>";
  237. errors.forEach(function (data) {
  238. if (data == "error") {
  239.  
  240. } else {
  241. html += "<p>" + data + "</p>";
  242. }
  243. });
  244. $('#errors').html(html);
  245. };
  246.  
  247. var regCacheApi = function () {
  248. if ('serviceWorker' in navigator) {
  249. navigator.serviceWorker.register('sw.js')
  250. .then(r => console.log('sw registered'))
  251. .catch(console.error);
  252. }
  253. };
  254.  
  255. (function () {
  256. loadEventMap();
  257. startup();
  258. $('#AddPeople').on('click', addPeople);
  259. $('.Create').on('click', goToEvent);
  260. $('#DebtAware').on('click', goToWelcome);
  261. $('#buttonAddPeople').on('click', addPersonForm);
  262. $('#addPersonButton').on('click', addPersonProcessForm);
  263. $('#addDebtLaunchButton').on('click', goToAddDebt);
  264. $('#addDebtToPerson').on('click', addDebt);
  265. $('body').on('click', '.headerEvent', showHeaderEvent);
  266. $('#registerPerson').on('click', validateRegister);
  267. $('#login').on('click', validateLogin);
  268. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement