home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2002 December / PCpro_2002_12.ISO / browser / netscape7 / nim.xpi / bin / chrome / aim.jar / content / aim / GetMemberInfo.js < prev    next >
Encoding:
Text File  |  2002-06-03  |  13.5 KB  |  475 lines

  1. var localeCallbackDefault = new Object();
  2. var localeCallbackAway = new Object();
  3. var localeCallbackProfile = new Object();
  4. var screenName;
  5. var locateManager;
  6. var gotawaymsg=0;
  7. var gotprofile=0;
  8. var profileMsg;
  9. var awayMsg;
  10. var isAway;
  11. var offlinemsg;
  12.  
  13.  
  14.  
  15. //globals for smilies....inherited from Chat code
  16.     var smileyCodes = new Array(7);
  17.     smileyCodes[0] = /:-?\)/g;
  18.   smileyCodes[1] = /:-D/g;
  19.   smileyCodes[2] = /:-?\(/g;
  20.     smileyCodes[3] = /:-\[/g;
  21.   smileyCodes[4] = /;-?\)/g;
  22.   smileyCodes[5] = /:-\\/g;
  23.     smileyCodes[6] = /:-P/g;
  24.  
  25.     var smileyImgs = new Array('<img src="chrome://editor/content/images/smile_n.gif" class="moz-txt-smily" height=19 width=19 align=ABSCENTER>',
  26.                                '<img src="chrome://editor/content/images/laughing_n.gif" class="moz-txt-smily" height=19 width=19 align=ABSCENTER>',
  27.                                '<img src="chrome://editor/content/images/frown_n.gif" class="moz-txt-smily" height=19 width=19 align=ABSCENTER>',
  28.                                '<img src="chrome://editor/content/images/embarrassed_n.gif" class="moz-txt-smily" height=19 width=19 align=ABSCENTER>',
  29.                                '<img src="chrome://editor/content/images/wink_n.gif" class="moz-txt-smily" height=19 width=19 align=ABSCENTER>',
  30.                                '<img src="chrome://editor/content/images/undecided_n.gif" class="moz-txt-smily" height=19 width=19 align=ABSCENTER>',
  31.                                '<img src="chrome://editor/content/images/tongue_n.gif" class="moz-txt-smily" height=19 width=19 align=ABSCENTER>');
  32.  
  33. /*
  34.  * Function: getMemberInfoOnWinLoad()
  35.  *
  36.  * Arguments: None
  37.  * 
  38.  * Return: None
  39.  *
  40.  * Description: This function is called when Get Member Info(GMI) window is loaded. If it has a screenname call
  41.  *  getMemberInfo to get all the values.
  42.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  43.  *              
  44. */
  45.  
  46. function getMemberInfoOnWinLoad() {
  47.   window.title= aimString("gmi.windowtitle").replace(/%ScreenName%/, "");
  48.   doSetOKCancel(getMemberInfo, onCancel);
  49.   screenName = window.arguments[0];
  50.   if (screenName && screenName != "") {
  51.     document.getElementById("screenname").setAttribute("value",screenName);
  52.     getMemberInfo();
  53.   }
  54.   else {
  55.     document.getElementById("screenname").focus();
  56.     document.getElementById("ok").setAttribute("disabled", "true");
  57.   }
  58. }
  59.  
  60. /*
  61.  * Function: snKeyPress()
  62.  *
  63.  * Arguments: event
  64.  * 
  65.  * Return: None
  66.  *
  67.  * Description: This is called on every keypress in the screenname field. The OK button is enabled if length is 
  68.  *  more than one and on enter getMemberInfo fn is called.
  69.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  70.  *              
  71. */
  72.  
  73. function snKeyPress(event) {
  74.   if (event.keyCode != 9)
  75.     clearAllValues();
  76.   screenName = document.getElementById("screenname").value;
  77.   if (screenName && screenName.length > 0)
  78.     document.getElementById("ok").setAttribute("disabled", "false");
  79.   else
  80.     document.getElementById("ok").setAttribute("disabled", "true");
  81.  
  82.   if(screenName && screenName.length > 0 && event.keyCode == 13) {
  83.     //the user has pressed Enter key.
  84.     getMemberInfo();
  85.   }
  86. }
  87.  
  88. /*
  89.  * Function: onCancel()
  90.  *
  91.  * Arguments: None
  92.  * 
  93.  * Return: None
  94.  *
  95.  * Description: Just closes the GMI window. 
  96.  *
  97.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  98.  *              
  99. */
  100. function onCancel() {
  101.   window.close();
  102. }
  103.  
  104. /*
  105.  * Function: clearAllValues()
  106.  *
  107.  * Arguments: None
  108.  * 
  109.  * Return: None
  110.  *
  111.  * Description: Clears all the fields in GMI window.
  112.  *
  113.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  114.  *              
  115. */
  116. function clearAllValues() {
  117.   document.getElementById("userWarningPercent").value = "";
  118.   document.getElementById("userOnlineTime").value = "";
  119.   document.getElementById("awayidlelabel").value = "";
  120.   document.getElementById("awayidletime").value = "";
  121.   window.frames["profilefield"].location = "about:blank";
  122.   window.title= aimString("gmi.windowtitle").replace(/%ScreenName%/, "");
  123.   gotprofile = 0;
  124.   gotawaymsg = 0;
  125. }
  126.  
  127.  
  128. /*
  129.  * Function: getMemberInfo()
  130.  *
  131.  * Arguments: None
  132.  * 
  133.  * Return: None
  134.  *
  135.  * Description: This fn calls RequestUserInfoDefault in LocateManager to get default info (away, idle, online etc). and 
  136.  *   RequestUserInfoSignature to get Profile/Signature info. 
  137.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  138.  *              
  139. */
  140. function getMemberInfo() {
  141.   clearAllValues();
  142.   window.title= aimString("gmi.windowtitle").replace(/%ScreenName%/, screenName);
  143.   var aimBuddy = aimBuddyManager();
  144.   if (!aimBuddy) {
  145.     dump("Unable to create aimBuddy...\n");
  146.     return;
  147.   }
  148.   
  149.  
  150.   locateManager = aimLocateManager();
  151.   if (!locateManager) {
  152.     dump("Unable to create locateManager...\n");
  153.     return;
  154.   }
  155.   locateManager.RequestUserInfoDefault(localeCallbackDefault, screenName);
  156.   
  157.  
  158.   // this is to update the GMI window for every 5 minutes!
  159.   setTimeout('getMemberInfo()', 5 * 60000);
  160.  
  161. }
  162.  
  163.  
  164. /*
  165.  * Function: OnRequestUserInfoDefaultComplete()
  166.  *
  167.  * Arguments: screenname, userObject
  168.  * 
  169.  * Return: None
  170.  *
  171.  * Description: Based on the userObject, user info like Online time, Idle time, warning percent, Away are obtained.
  172.  *   If the user is Away, RequestUserInfoAwayMessage in LocateManager is called to get the Away msg.
  173.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  174.  *              
  175. */
  176.  
  177.  
  178. localeCallbackDefault.OnRequestUserInfoDefaultComplete = function (screenname, userObject) {
  179.   
  180.   locateManager.RequestUserInfoSignature(localeCallbackProfile, screenName);
  181.  
  182.  
  183.   var warningPercent = userObject.GetWarningPercent();
  184.   if (warningPercent >= 0 ) {
  185.     document.getElementById("userWarningPercent").setAttribute("value", warningPercent + "%");
  186.   }
  187.   else {
  188.     document.getElementById("userWarningPercent").setAttribute("value", "");
  189.   }
  190.  
  191.   var onlineTime = userObject.GetOnlineSinceTime();
  192.   var now = new Date().getTime()/1000;
  193.   if (onlineTime >= 0 ) {
  194.     document.getElementById("userOnlineTime").setAttribute("value", getPrettyDateDiff(now, onlineTime));
  195.   }
  196.   else {
  197.     document.getElementById("userOnlineTime").setAttribute("value", "");
  198.   }
  199.  
  200.   var isIdle = userObject.IsIdle();
  201.   var idletime;
  202.   if (isIdle) {
  203.     var idlesincetime = userObject.GetIdleSinceTime();
  204.     idletime = getPrettyDateDiff(now, idlesincetime);
  205.   }
  206.  
  207.   isAway = userObject.IsAway();
  208.   
  209.   if (isIdle) {
  210.     if (isAway) {
  211.       //user is away and idle
  212.       document.getElementById("awayidlelabel").setAttribute("value", aimString("gmi.idleandaway"));
  213.       document.getElementById("awayidletime").setAttribute("value", idletime);
  214.     } else {
  215.       // user is just idle
  216.       document.getElementById("awayidlelabel").setAttribute("value", aimString("gmi.idle"));
  217.       document.getElementById("awayidletime").setAttribute("value", idletime);
  218.     }
  219.   }
  220.   else {
  221.     if (isAway)
  222.       //user is just away.
  223.       document.getElementById("awayidlelabel").setAttribute("value", aimString("gmi.away"));
  224.   }
  225.  
  226.   if (isAway) {
  227.     locateManager.RequestUserInfoAwayMessage(localeCallbackAway, screenName);
  228.   }
  229.  
  230.  
  231. }
  232.  
  233. localeCallbackDefault.OnRequestUserInfoDefaultError = function (screenname, errmsg) {
  234.   //if the user is offline we fall here.
  235.   offlinemsg =  aimString("gmi.infonotavailable").replace(/%ScreenName%/, screenName);
  236.   displayInfo(offlinemsg);
  237.   //dump("In OnRequestUserInfoDefaultError...Nothing for now...\n");
  238. }
  239.  
  240.  
  241. /*
  242.  * Function: OnRequestUserInfoAwayMessageComplete()
  243.  *
  244.  * Arguments: screenname, awaymsg
  245.  * 
  246.  * Return: None
  247.  *
  248.  * Description: This calls another fn displayProfileandAwayMsg to display the information.
  249.  *   processAwayMsg is another utility fn that converts %n, to SN etc.
  250.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  251.  *              
  252. */
  253.  
  254. localeCallbackAway.OnRequestUserInfoAwayMessageComplete = function (screenname, awaymsg) {
  255.   gotawaymsg = 1;
  256.   awaymsg = processAwayMsg(awaymsg);
  257.   awayMsg = awaymsg;
  258.   displayProfileandAwayMsg();
  259. }
  260.  
  261. localeCallbackAway.OnRequestUserInfoAwayMessageError = function (screenname, errmsg) {
  262.   dump("In OnRequestUserInfoAwayMessageError...Nothing for now...\n");
  263.   gotawaymsg = 2;
  264. }
  265.  
  266.  
  267. /*
  268.  * Function: OnRequestUserInfoSignatureComplete()
  269.  *
  270.  * Arguments: screenname, profilemsg
  271.  * 
  272.  * Return: None
  273.  *
  274.  * Description: This is called if the RequestUserInfoSignature is sucessful. displayProfileandAwayMsg fn
  275.  * is called to display the profile/signature msg.
  276.  *
  277.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  278.  *              
  279. */
  280.  
  281. localeCallbackProfile.OnRequestUserInfoSignatureComplete = function (screenname, profilemsg ) {
  282.   gotprofile = 1;
  283.   profileMsg = processAwayMsg(profilemsg);
  284.   displayProfileandAwayMsg();
  285. }
  286.  
  287.  
  288. localeCallbackProfile.OnRequestUserInfoSignatureError = function (screenname, errmsg ) {
  289.   dump("In OnRequestUserInfoSignatureError...Nothing for now...\n");
  290.   gotprofile = 2;
  291. }
  292.  
  293. /*
  294.  * Function: gmiNewIM()
  295.  *
  296.  * Arguments: None
  297.  * 
  298.  * Return: None
  299.  *
  300.  * Description: Creates a new IM conversation window.
  301.  *
  302.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  303.  *              
  304. */
  305.  
  306. function gmiNewIM() {
  307.   screenName = document.getElementById("screenname").value;
  308.   if ( AimOnlineAway() )
  309.         ComeBack();
  310.   var aimBuddy = aimBuddyManager();
  311.   if (!aimBuddy) {
  312.     dump("Unable to create aimBuddy...\n");
  313.     return;
  314.   }
  315.   //Check whether the buddy is online first.
  316.   if (!aimBuddy.IsBuddyOnline(screenName)) {
  317.     screenName = null;
  318.   }
  319.     
  320.     if (screenName != null)
  321.     {
  322.         var pIAimIM = aimIMObject();
  323.         
  324.         if (pIAimIM)
  325.             var pWindow = pIAimIM.GetExistingIM(screenName);
  326.         if (pWindow)
  327.         {
  328.             pWindow.focus();
  329.             return;
  330.         }
  331.     }
  332.   aimIMInvokeIMForm(screenName);
  333. }
  334.  
  335.  
  336. /*
  337.  * Function: gmiAddBuddy()
  338.  *
  339.  * Arguments: None
  340.  * 
  341.  * Return: None
  342.  *
  343.  * Description: Open up the Add Buddy window.
  344.  *
  345.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  346.  *              
  347. */
  348.  
  349. function gmiAddBuddy() {
  350.   screenName = document.getElementById("screenname").value;
  351.   openDialog("chrome://aim/content/BuddyAddBuddy.xul", "", 
  352.         "modal=yes,titlebar,chrome", null, null, screenName);
  353. }
  354.  
  355.  
  356. /*
  357.  * Function: displayProfileandAwayMsg()
  358.  *
  359.  * Arguments: None
  360.  * 
  361.  * Return: None
  362.  *
  363.  * Description: There are two async callbacks involved in GMI feature: localeCallbackAway and localeCallbackProfile.
  364.  *  If both the callbacks are complete then we display the info the user in displayInfo fn.
  365.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  366.  *              
  367. */
  368.  
  369. function displayProfileandAwayMsg() {
  370.   var newMsg;
  371.   // As we have two callbacks we check for both the callback before we display the info. 
  372.   if (gotprofile == 1 && isAway && gotawaymsg == 1) {
  373.     // Most of the users doesn't have profile/signature info. Just display the default in that case.
  374.     if (!profileMsg || profileMsg == "") {
  375.       profileMsg = aimString("gmi.noprofileavailable");
  376.       newMsg = awayMsg + "<hr>" + profileMsg;
  377.     }
  378.     else {
  379.       newMsg = awayMsg + "<hr>" + profileMsg;
  380.     }
  381.     displayInfo(newMsg);
  382.   }
  383.   else {
  384.     if (gotprofile == 1 && !isAway) {
  385.       if (!profileMsg || profileMsg == "") {
  386.         profileMsg = aimString("gmi.noprofileavailable");
  387.       }
  388.       newMsg = profileMsg;
  389.       displayInfo(newMsg);
  390.     }
  391.   }
  392.  
  393. }
  394.  
  395.  
  396. /*
  397.  * Function: displayInfo()
  398.  *
  399.  * Arguments: Msg.
  400.  * 
  401.  * Return: None
  402.  *
  403.  * Description: Just displays the Msg in the GMI window. Converts smilies, html info etc. Mostly inherited from Chat code.
  404.  *
  405.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  406.  *              
  407. */
  408.  
  409.  
  410. function displayInfo(newMsg) {
  411.  
  412.  
  413.   var moz = Components.classesByID["{77c0e42a-1dd2-11b2-8ebf-edc6606f2f4b}"];
  414.   var moztxt = moz.createInstance(Components.interfaces.mozITXTToHTMLConv);
  415.   var iface = Components.interfaces.mozITXTToHTMLConv;
  416.   var mozURL = iface.kURLs;
  417.   var smileyFeatureEnabled = aimPrefsManager().GetBoolPref("aim.general.im.smilies", null, false);
  418.        
  419.   if (smileyFeatureEnabled)
  420.     newMsg = convertToSmileyImg(newMsg);
  421.  
  422.   var theLogNode = top.frames['profilefield'];
  423.   var myRange = theLogNode.document.createRange();
  424.   var theLogBody =theLogNode.document.getElementsByTagName("body").item(0)
  425.   myRange.setStartAfter(theLogBody);
  426.   var docFrag;
  427.       
  428.   if(newMsg) {
  429.     newMsg = moztxt.scanHTML(newMsg, mozURL);
  430.   }
  431.  
  432.   docFrag = myRange.createContextualFragment("<html>"+  newMsg +"</html><br>");
  433.   var prevdocHeight = theLogNode.document.height;
  434.   var isLocked=((theLogNode.scrollY + theLogNode.innerHeight) >= theLogNode.document.height) 
  435.                     || (( theLogNode.document.height - theLogNode.scrollY ) <= 5)
  436.       theLogBody.appendChild(docFrag)
  437.               
  438.       
  439.   if (isLocked){
  440.     if ((theLogNode.innerHeight - (prevdocHeight-theLogNode.scrollY)) <= 5)
  441.       return;
  442.     if ((theLogNode.innerHeight < theLogNode.document.height) && (theLogNode.scrollY == prevdocHeight))
  443.       return;
  444.  
  445.     theLogNode.scrollTo(theLogNode.scrollX, theLogNode.document.height)
  446.   }
  447.  
  448.   //once we are done displaying the info disable the ok button. 
  449.   document.getElementById("ok").setAttribute("disabled", "true");
  450.  
  451. }
  452.  
  453. /*
  454.  * Function: convertToSmileyImg()
  455.  *
  456.  * Arguments: Msg.
  457.  * 
  458.  * Return: returns the msg converted to smilies.
  459.  *
  460.  * Description: convers a msg with smilies to actual smilies. Inherited from Chat code.
  461.  *
  462.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  463.  *              
  464. */
  465.  
  466. function convertToSmileyImg(msg){
  467.     var count;
  468.   if (msg) {
  469.       for (count = 0; count < smileyCodes.length; count++)        
  470.           msg = msg.replace(smileyCodes[count], smileyImgs[count] );
  471.   }
  472.     
  473.     return msg;
  474.  
  475. }