Guest User

Untitled

a guest
Apr 7th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. is_user_valid = Array();
  2.  
  3. is_player_added = Array();
  4.  
  5. function validate_users() {
  6.  
  7. inputs = cssQuery('p.player input');
  8.  
  9. is_valid = true;
  10.  
  11. for (i=0; i<inputs.length; i++) {
  12. input = inputs[i];
  13. if (input.value == '') is_valid = false;
  14. }
  15.  
  16. if (!is_valid) return alert('All fields must be filled.');
  17.  
  18. list = cssQuery('p.player');
  19.  
  20. for (i=0; i<list.length; i++) {
  21.  
  22. player = list[i];
  23. id = player.getAttribute('id');
  24. username = cssQuery('p.player#' + id + ' input#' + id + '_username')[0].value;
  25. password = cssQuery('p.player#' + id + ' input#' + id + '_password')[0].value;
  26.  
  27. clsGolfGameWebService.ValidateUser(username, password, function(result) {
  28.  
  29. if (result == '0') {
  30.  
  31. alert('before:' + is_user_valid.length)
  32. is_user_valid[i] = false;
  33. alert('after:' + is_user_valid.length)
  34.  
  35. r = cssQuery('p.player#' + id + ' span.invalid');
  36.  
  37. if (r.length < 1) {
  38.  
  39. el = document.createElement('span');
  40. el.setAttribute('class', 'invalid');
  41. el.innerHTML = 'invalid';
  42. player.appendChild(el);
  43.  
  44. } else {
  45.  
  46. r[0].innerHTML = 'invalid';
  47. r[0].setAttribute('class', 'invalid');
  48.  
  49. }
  50.  
  51. } else {
  52.  
  53. alert('before:' + is_user_valid.length)
  54. is_user_valid[i] = true;
  55. alert('after:' + is_user_valid.length)
  56.  
  57. r = cssQuery('p.player#' + id + ' span.invalid');
  58.  
  59. if (r.length >= 1) {
  60.  
  61. r[0].parentNode.removeChild(r[0]);
  62.  
  63. }
  64.  
  65. }
  66.  
  67. document.getElementById('log').innerHTML += "<p>" + is_user_valid.toString() + "</p>";
  68.  
  69. }, AjaxErrorHandler, AjaxTimeOutHandler);
  70.  
  71. }
  72.  
  73. }
  74.  
  75. function add_players_to_match(golfcourse_id, match_id) {
  76. list = cssQuery('p.player');
  77.  
  78. for (i=0; i<list.length; i++) {
  79. is_player_added[i] = false;
  80. }
  81.  
  82. for (i=0; i<list.length; i++) {
  83.  
  84. player = list[i];
  85. id = player.getAttribute('id');
  86. username = cssQuery('p.player#' + id + ' input#' + id
  87. + '_username')[0].value;
  88. password = cssQuery('p.player#' + id + ' input#' + id
  89. + '_password')[0].value;
  90.  
  91. clsGolfGameWebService.AddPlayerToMatch(golfcourse_id, match_id, username, password, function(result) {
  92.  
  93. document.getElementById('log').innerHTML += "<p>added player " + i + "</p>";
  94.  
  95. if (result) is_player_added[i] = true;
  96.  
  97. }, AjaxErrorHandler, AjaxTimeOutHandler);
  98.  
  99. }
  100.  
  101. // alert("Added players to match.")
  102.  
  103. }
  104.  
  105. function start_if_ready(MatchId) {
  106.  
  107. debug = document.getElementById('log');
  108.  
  109. for (i=0; i<is_player_added.length; i++) {
  110. debug.innerHTML += '<p>is_player_added[' + i + ']: ' + is_player_added[i] + '</p>';
  111. if (!is_player_added[i]) return false;
  112. }
  113.  
  114. clearInterval(players_checker);
  115.  
  116. // var PlayMatchUrl = 'PlayMatch.aspx?MatchId=' + MatchId;
  117. //
  118. // window.location = PlayMatchUrl;
  119.  
  120. }
  121.  
  122. function start_if_valid(GolfCourse) {
  123.  
  124. debug = document.getElementById('log');
  125.  
  126. for (i=0; i<is_user_valid.length; i++) {
  127. debug.innerHTML += '<p>is_user_valid[' + i + ']: ' + is_user_valid[i] + '</p>';
  128. if (!is_user_valid[i]) return false;
  129. }
  130.  
  131. clearInterval(user_validation_checker);
  132.  
  133. clsGolfGameWebService.InsertNewMatch(GolfCourse, function(MatchId) {
  134.  
  135. add_players_to_match(GolfCourse, MatchId);
  136.  
  137. players_checker = setInterval(function() { start_if_ready(MatchId); }, 100);
  138.  
  139. }, AjaxErrorHandler, AjaxTimeOutHandler);
  140.  
  141. }
  142.  
  143. function start_match_onclick() {
  144.  
  145. var PublicGolfCourseGuid = GetUrlParameters("id");
  146. if (PublicGolfCourseGuid == null) {
  147. alert('No golf course specified');
  148. return;
  149. }
  150.  
  151. // Start the validation process.
  152. validate_users();
  153.  
  154. // Periodically check if we have valid users yet. If we do, start.
  155. user_validation_checker = setInterval(function() { start_if_valid(PublicGolfCourseGuid); }, 100);
  156.  
  157. }
Add Comment
Please, Sign In to add comment