home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2003 October / cmycha200310.iso / NHL2004 / NHL2004Demo.exe / fe / COMMON / js / User_Profile.js < prev    next >
Text File  |  2003-08-20  |  9KB  |  273 lines

  1. function User_Profile(sGameType)
  2. {
  3.     if( !(this instanceof User_Profile)) return new User_Profile( );
  4.     var protect            = this.createProtection(JAX_Object);
  5.     protect.name        = "";
  6.     protect.userID         = ""
  7.       protect.walletPoints    = "";
  8.     protect.careerPoints    = "";
  9.     protect.level        = "";
  10.     protect.clubID        = "";
  11.     protect.clubName    = "";
  12.     protect.isClub_GM    = false;
  13.     protect.entitledGames    = [];
  14.     protect.profileCardImgID    = "";
  15.     protect.baseStats            = new User_Stats_Base();
  16.     if (sGameType) {
  17.         switch (sGameType) {
  18.             default:
  19.                 protect.gameStats    = new NHL_Stats_Base();
  20.             break;
  21.         };
  22.     } else {
  23.         protect.gameStats        = new NHL_Stats_Base();
  24.     };
  25. }
  26. User_Profile.prototype                    = new JAX_Object;
  27. User_Profile.prototype.getGameStats        = function()
  28. {
  29.     var protect        = this.getProtection(User_Profile);
  30.     return protect.gameStats;
  31. };
  32. User_Profile.prototype.getBaseStats            = function()
  33. {
  34.     var protect        = this.getProtection(User_Profile);
  35.     return protect.baseStats;
  36. };
  37.  
  38. User_Profile.prototype.getName            = function()
  39. {
  40.     try {
  41.         var protect        = this.getProtection(User_Profile);
  42.         return protect.name;
  43.     } catch (e) {
  44.         return "";
  45.     };
  46. };
  47. User_Profile.prototype.getUserID            = function()
  48. {
  49.     try {
  50.         var protect        = this.getProtection(User_Profile);
  51.         return protect.userID;
  52.     } catch (e) {
  53.         return "";
  54.     };
  55. };
  56. User_Profile.prototype.getWalletPoints        = function()
  57. {
  58.     try {
  59.         var protect        = this.getProtection(User_Profile);
  60.         return protect.walletPoints;
  61.     } catch (e) {
  62.         return "";
  63.     };    
  64. };
  65. User_Profile.prototype.setWalletPoints        = function( points)
  66. {
  67.     try {
  68.         var protect        = this.getProtection(User_Profile);
  69.         protect.walletPoints = points;
  70.     } catch (e) {
  71.     };    
  72. };
  73. User_Profile.prototype.getCareerPoints        = function()
  74. {
  75.     try {
  76.         var protect        = this.getProtection(User_Profile);
  77.         return protect.careerPoints;
  78.     } catch (e) {
  79.         return "";
  80.     };
  81. };
  82. User_Profile.prototype.getLevel            = function()
  83. {
  84.     try {
  85.         var protect        = this.getProtection(User_Profile);
  86.         return protect.level;
  87.     } catch (e) {
  88.         return "";
  89.     };
  90. };
  91. User_Profile.prototype.getClubID            = function()
  92. {
  93.     try {
  94.         var protect        = this.getProtection(User_Profile);
  95.         return protect.clubID;
  96.     } catch (e) {
  97.         return "";
  98.     };
  99. };
  100. User_Profile.prototype.getClubName            = function()
  101. {
  102.     try {
  103.         var protect        = this.getProtection(User_Profile);
  104.         return protect.clubName;
  105.     } catch (e) {
  106.         return "";
  107.     };
  108. };
  109. User_Profile.prototype.isClubGM            = function()
  110. {
  111.     try {
  112.         var protect        = this.getProtection(User_Profile);
  113.         return protect.isClub_GM;
  114.     } catch (e) {
  115.         return false;
  116.     };
  117. };
  118. User_Profile.prototype.getProfileCardImageID    = function()
  119. {
  120.     return this.getProtection(User_Profile).profileCardImgID;
  121. };
  122. User_Profile.prototype.getProfileCardImageSrc    = function()
  123. {
  124.     var protect            = this.getProtection(User_Profile);
  125.     var id = this.getProfileCardImageID();
  126.     return "fe/sc/images/profile/card/"+ id +"_card_front.jpg";
  127. };
  128. User_Profile.prototype.getProfileHeadshotImageSrc = function()
  129. {
  130.     var protect            = this.getProtection(User_Profile);
  131.     var id                = this.getProfileCardImageID();
  132.     return "fe/sc/images/profile/card/"+ id +"_head.jpg";
  133. };
  134. User_Profile.prototype.setClub                = function(clubID, clubName, isGM)
  135. {
  136.     var protect    = this.getProtection(User_Profile);
  137.     protect.clubName    = (clubName) ? clubName : "";
  138.     protect.clubID        = ( !(isNaN(parseInt(clubID))) ) ? clubID : "";
  139.     protect.isClub_GM    = (isGM) ? isGM : false;
  140. };
  141. User_Profile.prototype.setProfileCard        = function(profileCardID)
  142. {
  143.     var protect    = this.getProtection(User_Profile);
  144.     protect.profileCardImgID        = (profileCardID) ? profileCardID : 0;
  145. };
  146. User_Profile.prototype.getGames            = function()
  147. {
  148.     var protect    = this.getProtection(User_Profile);
  149.     return protect.entitledGames;
  150. };
  151. User_Profile.prototype.load                = function(screenName, serverURL, onLoaded, onLoading, cacheProfile)
  152. {
  153.     var protect        = this.getProtection(User_Profile);
  154.     serverURL    = (serverURL) ? serverURL : "sc/profile/get_user_profile.jsp";
  155.     var paramStr        = (screenName) ? "screenname=" + screenName + "&" : "";
  156.     var request        = null;
  157.     if (onLoaded) {
  158.         request        =  new Remote_Request(serverURL, paramStr, true);
  159.         request.setOnComplete(function() { OnProfileLoaded(request.getValue()); });
  160.     } else {
  161.         request        = new Remote_Request(serverURL, paramStr);
  162.     };
  163.       request.setIsPostRequest(true);
  164.     if ( !(isNaN(parseInt(cacheProfile))) ) {
  165.         request.cacheRequest(cacheProfile);
  166.     };
  167.      request.send();
  168.     if (!onLoaded) {
  169.         OnProfileLoaded(request.getValue());
  170.     };
  171.     function OnProfileLoaded(requestDom)
  172.     {
  173.         if (request.isError() || request.badHTTPStatus ) 
  174.         {
  175.             if (onLoaded) {
  176.                 onLoaded(false);
  177.                 return;
  178.             } else {
  179.                 if (request.isError()) {
  180.                     var e                = new Error();
  181.                           e.description    = request.isError();
  182.                          System.handleError(e.description);
  183.                          return;
  184.                  };
  185.                 if (request.badHTTPStatus) {
  186.                     var e                = new Error();
  187.                           e.description    = request.isError();
  188.                          System.handleError("::99::" + scMsg("SC_REGERROR_99"));
  189.                          return;
  190.                 };
  191.             };
  192.         };
  193.         var topNode            = requestDom.selectSingleNode("PROFILE");
  194.         try {
  195.             if (topNode) {
  196.                 var gameNode                    = topNode.selectSingleNode("EA_GAMES/GAME");
  197.                 var statsNode                    = (gameNode) ? gameNode.selectSingleNode("USER_STATS") : null;
  198.                 var clubNode                    = (gameNode) ? gameNode.selectSingleNode("CLUB") : null;
  199.                 if ( (gameNode) && (statsNode)  ) {
  200.                     protect.name                = unescape(topNode.selectSingleNode("NAME").text);
  201.                            protect.userID                = topNode.selectSingleNode("ID").text;
  202.                     protect.walletPoints            = topNode.selectSingleNode("WALLET_POINTS").text;
  203.                     protect.careerPoints            = topNode.selectSingleNode("LIFETIME_POINTS").text;
  204.                     protect.level                = gameNode.selectSingleNode("LEVEL").text;
  205.                     protect.profileCardImgID        = topNode.selectSingleNode("PROFILE_CARD").text;
  206.                     if (clubNode) {
  207.                         protect.clubID            = clubNode.selectSingleNode("ID").text;
  208.                         protect.clubName        = unescape(clubNode.selectSingleNode("NAME").text);
  209.                         protect.isClub_GM            = false;
  210.                         if (clubNode.selectSingleNode("IS_GM").text == "true"  )
  211.                             protect.isClub_GM        = true ;
  212.                     } else {
  213.                         protect.clubID                = "";
  214.                         protect.clubName            = "";
  215.                         protect.isClub_GM            = false;
  216.                     };
  217.                     protect.baseStats.setGamesPlayed(statsNode.selectSingleNode("GAMES").text);
  218.                     protect.baseStats.setWins(statsNode.selectSingleNode("WINS").text);
  219.                     protect.baseStats.setLosses(statsNode.selectSingleNode("LOSSES").text);
  220.                     protect.baseStats.setDisconnects(statsNode.selectSingleNode("DISCONNECTS").text);
  221.                     protect.baseStats.setRating(statsNode.selectSingleNode("RATING").text);
  222.                     protect.baseStats.setWinPercentage(statsNode.selectSingleNode("AVG").text);
  223.                     if (protect.gameStats) {
  224.                         protect.gameStats.setGamePoints(statsNode.selectSingleNode("PTS").text);
  225.                         protect.gameStats.setOT_Wins(statsNode.selectSingleNode("OTW").text);
  226.                         protect.gameStats.setOT_Losses(statsNode.selectSingleNode("OTL").text);
  227.                         protect.gameStats.setDraws(statsNode.selectSingleNode("DRAWS").text);
  228.                     } else {
  229.                         protect.gameStats.setGamePoints("0");
  230.                         protect.gameStats.setOT_Wins("0");
  231.                         protect.gameStats.setOT_Losses("0");
  232.                         protect.gameStats.setDraws("0");                                        
  233.                     }
  234.                 } else {
  235.                     protect.name                = "";
  236.                         protect.userID                  = "";
  237.                     protect.walletPoints            = "";
  238.                     protect.careerPoints            = "";
  239.                     protect.level                = "";
  240.                     protect.clubID                = "";
  241.                     protect.clubName            = "";
  242.                     protect.isClub_GM            = false;
  243.                     protect.gameStats.setGamePoints("0");
  244.                     protect.gameStats.setOT_Wins("0");
  245.                     protect.gameStats.setOT_Losses("0");
  246.                     protect.gameStats.setDraws("0");
  247.                     protect.baseStats.setGamesPlayed("0");
  248.                     protect.baseStats.setWins("0");
  249.                     protect.baseStats.setLosses("0");
  250.                     protect.baseStats.setDisconnects("0");
  251.                     protect.baseStats.setRating("");
  252.                     protect.baseStats.setWinPercentage("");
  253.                 };
  254.                 var titlesNode            = topNode.selectSingleNode("TITLES");
  255.                 for (var idx = 0; idx < titlesNode.childNodes.length; idx++)
  256.                 {
  257.                     protect.entitledGames[titlesNode.childNodes[idx].nodeName] = titlesNode.childNodes[idx].nodeName;
  258.                 };
  259.             };
  260.         } catch (e) { 
  261.             if (onLoaded) {
  262.                 onLoaded(false);
  263.                 return;
  264.             } else {
  265.                 System.handleError( "::99::" + scMsg("SC_REGERROR_99"));
  266.                 return;
  267.             };
  268.         };
  269.         if (onLoaded) {
  270.             onLoaded(true);
  271.         };
  272.     };
  273. };