applicationActionManager.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2008 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. //attempt to stop people doing two things at once
  11. //which causes all kinds of bother
  12. function ApplicationActionManager(){
  13. //write to the status bar
  14. this.debug_flag = false;
  15. //track the http_requests
  16. this.http_count = 0;
  17. this.is_blocked = false;
  18. //the auto unblocker could get tangled on new requests
  19. ///give it a unique id (system time)
  20. this.unblock_id = 0;
  21. }
  22. //called by anything doing asynch http requests
  23. ApplicationActionManager.prototype.httpStart = function(){
  24. this.http_count++;
  25. if(this.http_count >= 2){
  26. this.blockActions();
  27. }if(this.http_count < 0){
  28. //auto correction, if the calling code gets mangled
  29. //this.http_count = 1;
  30. }
  31. this.debug();
  32. }
  33. //called by anything doing asynch http requests
  34. ApplicationActionManager.prototype.httpStop = function(ex){
  35. this.http_count--;
  36. if(this.http_count < 2){
  37. this.allowActions();
  38. }
  39. this.debug(ex);
  40. }
  41. ApplicationActionManager.prototype.isBlocked = function(){
  42. return this.is_blocked;
  43. }
  44. ApplicationActionManager.prototype.unBlock = function(id){
  45. if(id == this.unblock_id && id != 0){
  46. this.unblock_id = 0;
  47. this.is_blocked = false;
  48. //if(this.debug_flag){
  49. //alert(new Date().getTime() - new Date(id).getTime());
  50. //}
  51. }else{
  52. //if(this.debug_flag){
  53. // alert("failed unblocker thread");
  54. //}
  55. }
  56. this.debug();
  57. }
  58. ApplicationActionManager.prototype.debug = function(ex){
  59. if(this.debug_flag){
  60. window.defaultStatus = "http requests: " + this.http_count + ", " + (this.is_blocked ? "blocked" : "unblocked") + (ex ? " error: " + ex : "");
  61. }
  62. }
  63. ApplicationActionManager.prototype.blockActions = function(){
  64. this.is_blocked = true;
  65. this.debug();
  66. this.unblock_id = (new Date()).getTime();
  67. //as a get out.... un block in 8 seconds.. why not
  68. setTimeout("applicationActionManager.unBlock("+this.unblock_id+")", 12000);
  69. return this.unblock_id;
  70. }
  71. ApplicationActionManager.prototype.allowActions = function(){
  72. this.is_blocked = false;
  73. this.debug();
  74. }
  75. function setCursorStyle(style){
  76. getConfigFrame().document.body.style.cursor = style;
  77. getMessageIFrame().document.body.style.cursor = style;
  78. }
  79. function setStatus(message){
  80. window.defaultStatus = message;
  81. }
  82. //this function is passed to the dispatcher so that we keep the http count steady
  83. function cDispatchErrorHandler(location_name, ex){
  84. applicationActionManager.httpStop(ex);
  85. }
  86. var applicationActionManager = new ApplicationActionManager();