Guest User

Untitled

a guest
Jan 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     var returnArray = new Array();
  2.  
  3.     function regenerateKits(previous_season_id) {
  4.         // send our requests.  This is processed by the server.  Each one on average takes about 2 minutes.
  5.         var regenerateUrl = '<?=$AppSettings['backend_url']?>/adminTeam/generate_kit_batch_background.php?client_code=<?=$AppSettings['client_code']?>&previous_season_id=' + previous_season_id + '&game_ids=' + kitsToRegenerate.toString();
  6.         var result = $.ajax({
  7.           url: regenerateUrl,
  8.           async: false,
  9.           context: document.body
  10.         }).responseText;
  11.        
  12.         // this returns the primary ids that went into the db so we can check on it's status
  13.        
  14.         // hide the divs to show they're being processes
  15.         for(i=0;i<=kitsToRegenerate.length;i++) {
  16.             if (kitsToRegenerate[i]) {
  17.                 $('#old_'+kitsToRegenerate[i]).hide();
  18.                 $('#new_'+kitsToRegenerate[i]).show();
  19.             }
  20.         }
  21.        
  22.         // add to our global variable so the listener can check on it
  23.         returnArray = result.split(',');
  24.         listen();
  25.     }
  26.  
  27.     function listen() {
  28.         // Let's let the user know something is happening ...
  29.         $('#welcome').hide();
  30.         $('#waiting').show();
  31.  
  32.         finished_num = returnArray.length;
  33.         complete = 0;
  34.         attempt = 0;
  35.        
  36.         // I want to process the array and as they finish it, remove it.  when it's empty, we're done.
  37.        
  38.         while(returnArray.length > 0) {
  39.             attempt++;
  40.             for(i=0;i<=returnArray.length;i++) {
  41.                if (returnArray[i]) {
  42.                    // check the status of each primary id.  pause for 2 seconds between each request.
  43.                    setInterval( function() { checkStatus(returnArray[i], 0);}, 2000 );
  44.                }
  45.             }
  46.            
  47.             if (attempt == 100) {
  48.                 alert('i give up');
  49.                 return;
  50.             }
  51.         }
  52.         $('#waiting').hide();
  53.         $('#welcome').show();
  54.     }
  55.  
  56.    
  57.     function checkStatus(queue_id, key) {
  58.         var url = '<?=$AppSettings['backend_url']?>/adminTeam/generate_kit_check.php?queue_id='+queue_id;
  59.         var result = $.ajax({
  60.               url: url,
  61.               async: false,
  62.               context: document.body,
  63.         }).responseText;
  64.         if (result != 0) {
  65.             $('#old_'+result).show();
  66.             $('#new_'+result).hide();
  67.             $('#download_link_'+result).show();
  68.             $('#placeholder_'+result).hide();
  69.             returnArray.splice(key, 1);
  70.         }
  71.     }
Add Comment
Please, Sign In to add comment