Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var returnArray = new Array();
- function regenerateKits(previous_season_id) {
- // send our requests. This is processed by the server. Each one on average takes about 2 minutes.
- 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();
- var result = $.ajax({
- url: regenerateUrl,
- async: false,
- context: document.body
- }).responseText;
- // this returns the primary ids that went into the db so we can check on it's status
- // hide the divs to show they're being processes
- for(i=0;i<=kitsToRegenerate.length;i++) {
- if (kitsToRegenerate[i]) {
- $('#old_'+kitsToRegenerate[i]).hide();
- $('#new_'+kitsToRegenerate[i]).show();
- }
- }
- // add to our global variable so the listener can check on it
- returnArray = result.split(',');
- listen();
- }
- function listen() {
- // Let's let the user know something is happening ...
- $('#welcome').hide();
- $('#waiting').show();
- finished_num = returnArray.length;
- complete = 0;
- attempt = 0;
- // I want to process the array and as they finish it, remove it. when it's empty, we're done.
- while(returnArray.length > 0) {
- attempt++;
- for(i=0;i<=returnArray.length;i++) {
- if (returnArray[i]) {
- // check the status of each primary id. pause for 2 seconds between each request.
- setInterval( function() { checkStatus(returnArray[i], 0);}, 2000 );
- }
- }
- if (attempt == 100) {
- alert('i give up');
- return;
- }
- }
- $('#waiting').hide();
- $('#welcome').show();
- }
- function checkStatus(queue_id, key) {
- var url = '<?=$AppSettings['backend_url']?>/adminTeam/generate_kit_check.php?queue_id='+queue_id;
- var result = $.ajax({
- url: url,
- async: false,
- context: document.body,
- }).responseText;
- if (result != 0) {
- $('#old_'+result).show();
- $('#new_'+result).hide();
- $('#download_link_'+result).show();
- $('#placeholder_'+result).hide();
- returnArray.splice(key, 1);
- }
- }
Add Comment
Please, Sign In to add comment