home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 July & August / PCWorld_2005-07-08_cd.bin / komunikace / netscape / nsb-install-8-0.exe / chrome / aim.jar / content / aim / chatInviteBuddy.js < prev    next >
Text File  |  2004-12-02  |  9KB  |  231 lines

  1. // globals
  2. // window arguments defined here, but may not be used.
  3. // mainly to test & explain valid arguments.
  4.  
  5. inviteArgsObj = window.arguments[0];
  6.  
  7. invitedScreenNames        = inviteArgsObj.invitedScreenNames;
  8. inviteToExistingWindow    = inviteArgsObj.inviteToExistingWindow;
  9. inviteMode                = inviteArgsObj.inviteMode;
  10. inviteMsg                 = inviteArgsObj.invitationmsg;
  11. inviteProposalObj         = inviteArgsObj.inviteProposalObj;
  12. inviteProposalScreenName  = inviteArgsObj.inviteProposalScreenName;
  13. inviteToExistingRoom      = inviteArgsObj.inviteToExistingRoom;
  14.  
  15. // for incoming chat invitation
  16. var incomingChatScreenName = inviteProposalScreenName;
  17. var incomingChatWarningLevel;
  18. var incomingChatRoomName;
  19. var incomingChatRoomDate;
  20. var incomingChatRoomInviteMsg;
  21. var incomingChatRoom;
  22.  
  23. var ChatManagerCallBack = new Object();
  24. var RoomCreationTimeStamp = null;
  25.  
  26. ChatManagerCallBack.OnRequestRoomComplete =  function(roomName,chatRoomObj)
  27. {
  28.   incomingChatRoom=chatRoomObj;
  29.   incomingChatRoomName = chatRoomObj.GetName();
  30.   document.getElementById("chatRendezvousRoomName001").setAttribute("value",incomingChatRoomName);   
  31. }
  32.  
  33. ChatManagerCallBack.OnRequestRoomError =  function(roomName,errMsg)
  34. {
  35.   window.close();
  36. }
  37.  
  38. myExecutionCallback = new Object();
  39. myExecutionCallback.ExecuteIfReady = function()
  40. {
  41.   // get chatroom and callbacks
  42.   inviteProposalObj.Accept();
  43.   aimChatManager().RequestProposedRoom(ChatManagerCallBack, inviteProposalObj);
  44. }
  45.  
  46. function setButtons(okLabel, cancelLabel, okTooltip, cancelTooltip)
  47. {
  48.   var buttons = document.getElementsByTagName("button");
  49.   for (i=0;i<buttons.length;i++) {
  50.     if (okLabel && buttons[i].getAttribute('id') == "ok") {
  51.       buttons[i].label = okLabel;
  52.     }
  53.     else if (cancelLabel && buttons[i].getAttribute('id') == "cancel") {
  54.       buttons[i].label = cancelLabel;
  55.     }
  56.   }
  57. }
  58.  
  59. function chatInviteBuddyOnWinLoad(){
  60.   doSetOKCancel(chatInviteBuddyCmdInvite, onCancel);
  61.  
  62.   /* VISHY - this is a performance optimization. 
  63.      Since chat needs time to get ready, this tells it to 
  64.      get ready, well before we actually use it */
  65.   aimChatManager().ExecuteIfReady(null);
  66.  
  67.   if(inviteMode && inviteMode=="incomingchat") {
  68.     setButtons(aimString('chat.YesButton'), aimString('chat.NoButton'), aimString('accept.tooltip'), aimString('decline.tooltip'));
  69.     doSetOKCancel(chatInviteBuddyCmdAcceptRendezvous, chatInviteBuddyCmdDeclineRendezvous);
  70.     document.getElementById("cibdeck001").setAttribute("selectedIndex",2);
  71.     incomingChatWarningLevel =  " " + aimString("chat.WarningLevel").replace(/%Level%/, inviteProposalObj.GetProposer().GetWarningPercent());
  72.     incomingChatRoomName = " ";
  73.     incomingChatRoomDate= new Date();
  74.  
  75.     // use international date format
  76.     try {
  77.       var IDateTime = Components.classes["@mozilla.org/intl/scriptabledateformat;1"].createInstance();
  78.       var dateFormatter = IDateTime.QueryInterface(Components.interfaces.nsIScriptableDateFormat);
  79.       var curYear = incomingChatRoomDate.getYear() + 1900;
  80.       var curMonth = incomingChatRoomDate.getMonth() + 1;
  81.       var curDay = incomingChatRoomDate.getDate();
  82.       var curHours = incomingChatRoomDate.getHours();
  83.       var curMinutes = incomingChatRoomDate.getMinutes();
  84.       var curSeconds = incomingChatRoomDate.getSeconds();
  85.  
  86.       dateTimeStr = dateFormatter.FormatDateTime("",
  87.                                     Components.interfaces.nsIScriptableDateFormat.dateFormatLong,
  88.                                     Components.interfaces.nsIScriptableDateFormat.timeFormatSeconds,
  89.                                     curYear,curMonth,curDay,curHours,curMinutes,curSeconds);
  90.       incomingChatRoomDate = dateTimeStr;
  91.     }
  92.     catch(e) {
  93.       dump("Error using FormatDateTime: " + e + "\n");
  94.     }
  95.  
  96.     incomingChatRoomInviteMsg = inviteProposalObj.GetInvitation();
  97.     document.getElementById("chatRendezvousScreenName001").setAttribute("value",incomingChatScreenName);
  98.     document.getElementById("chatRendezvousScreenName002").setAttribute("label",incomingChatScreenName);
  99.     document.getElementById("chatRendezvousScreenName003").setAttribute("value",incomingChatScreenName);
  100.     document.getElementById("chatRendezvousWarningLevel001").setAttribute("value",incomingChatWarningLevel);
  101.     document.getElementById("chatRendezvousRoomName001").setAttribute("value",incomingChatRoomName);
  102.     document.getElementById("chatRendezvousChatRoomDate").setAttribute("value",incomingChatRoomDate);
  103.     document.getElementById("chatRendezvousInvitationMsg").setAttribute("value", incomingChatRoomInviteMsg);
  104.  
  105.     //XXXVISHY - unfortunately you need to get the Chat Room 
  106.     // in order to find its name ;-)
  107.     aimChatManager().ExecuteIfReady(myExecutionCallback);
  108.   }
  109.  
  110.   if(inviteMode && inviteMode=="outgoingchat") {
  111.     setButtons(aimString('chat.InviteButton'), null, aimString('chatInvite.tooltip'), aimString('chatCancel.tooltip'));
  112.     document.getElementById("cibdeck001").setAttribute("selectedIndex",1)
  113.     if (!invitedScreenNames || invitedScreenNames == "") {
  114.       invitedScreenNames = "";
  115.       document.getElementById("invitedscreennames").focus();
  116.     }
  117.  
  118.     document.getElementById("invitedscreennames").value = invitedScreenNames;
  119.     if (inviteMsg)
  120.       document.getElementById("invitationmsg").value=inviteMsg;
  121.     else
  122.       document.getElementById("invitationmsg").value=aimString("chat.JoinMe");
  123.  
  124.     if(inviteToExistingRoom) {
  125.       document.getElementById("buddychatroomname").value = inviteToExistingRoom;
  126.       document.getElementById("buddychatroomname").setAttribute("readonly","true");
  127.     }
  128.     else
  129.       chatPreFillRoomName();
  130.   }
  131.  
  132. }
  133.  
  134. function onCancel(){
  135.    return true;
  136. }
  137.  
  138. function chatInviteBuddyCmdInvite() {
  139.   document.getElementById("cibdeck001").setAttribute("selectedIndex",3);
  140.   if(!inviteToExistingWindow) {
  141.     var invitedScreenNames = document.getElementById("invitedscreennames").value;
  142.     var cp = new String(invitedScreenNames);
  143.     if (!IsValidChar(cp)) {
  144.       // Cannot contain invalid characters 
  145.       aimErrorBox(aimString("msg.InvalidScreenName"));
  146.       document.getElementById("cibdeck001").setAttribute("selectedIndex",1)
  147.       return;
  148.     }
  149.     var chatRoomName = document.getElementById("buddychatroomname").value;
  150.     var chatMsg = document.getElementById("invitationmsg").value;
  151.  
  152.     // just send one argument to window.openDialog - but build an object. This way you dont have to worry about
  153.     // keeping track of the argument's order.
  154.     chatContentArgs = new Object();
  155.     chatContentArgs.invitedScreenNames = invitedScreenNames;
  156.     chatContentArgs.chatRoomName = chatRoomName;
  157.     chatContentArgs.chatMsg = chatMsg;
  158.     // not incoming chat
  159.     chatContentArgs.incomingChat = false;
  160.     chatContentArgs.incomingChatInviteProposalScreenName = ''
  161.     chatContentArgs.incomingChatInviteProposalObj=null
  162.     chatContentArgs.incomingChatRoom=null;
  163.     window.openDialog("chrome://aim/content/chatContent.xul","","chrome,all,dialog=no",chatContentArgs);
  164.   }
  165.   else {
  166.     window.opener.chatContentInviteMany(document.getElementById("invitedscreennames").value,document.getElementById("invitationmsg").value);
  167.     window.opener.chatMsg = document.getElementById("invitationmsg").value;
  168.     window.close();
  169.   }
  170.  
  171. }
  172.  
  173. function cmdChatIncomingWarn()
  174. {
  175.   var warnUserArgs = new Object();
  176.   warnUserArgs.screenName = incomingChatScreenName;
  177.   window.openDialog("chrome://aim/content/WarnUser.xul","_blank", "chrome,dialog=no",warnUserArgs)
  178. }
  179.  
  180. function cmdChatIncomingBlock()
  181. {
  182.   var pIAimPrivacy = aimPrivacy();
  183.   if ( !pIAimPrivacy )
  184.     return false;
  185.  
  186.   pIAimPrivacy.BlockUser(incomingChatScreenName);
  187.   inviteProposalObj.Reject();
  188.   window.close();
  189. }
  190.  
  191. function cmdChatIncomingIM()
  192. {
  193.   aimIMInvokeIMForm(incomingChatScreenName);
  194. }
  195.  
  196. function chatInviteBuddyCmdDeclineRendezvous()
  197. {
  198.   inviteProposalObj.Reject();
  199.   window.close();
  200. }
  201.  
  202. function chatInviteBuddyCmdAcceptRendezvous()
  203. {
  204.   document.getElementById("cibdeck001").setAttribute("selectedIndex",3)
  205.   // code to accept rendezvous here
  206.   var invitedScreenNames = "";
  207.   var chatRoomName=incomingChatRoomName
  208.   var chatMsg = "";
  209.  
  210.   // just send one argument to window.openDialog - but build an object. This way you dont have to worry about
  211.   // keeping track of the argument's order.
  212.   chatContentArgs = new Object();
  213.   chatContentArgs.invitedScreenNames = invitedScreenNames;
  214.   chatContentArgs.chatRoomName = chatRoomName;
  215.   chatContentArgs.chatMsg = chatMsg;
  216.   chatContentArgs.incomingChat = true;
  217.   chatContentArgs.incomingChatInviteProposalScreenName = inviteProposalScreenName;
  218.   chatContentArgs.incomingChatInviteProposalObj=inviteProposalObj
  219.   chatContentArgs.incomingChatRoom=incomingChatRoom;
  220.   window.openDialog("chrome://aim/content/chatContent.xul","","chrome,all,dialog=no",chatContentArgs);
  221. }
  222.  
  223. function chatPreFillRoomName() {
  224.   if(aimManager()) {
  225.     var currentScreenName = aimSessionCurrentScreenName()
  226.     var someRandomNumber = Math.ceil(Math.random()*100);
  227.     document.getElementById("buddychatroomname").value = currentScreenName + " " + aimString("chat.roomname") + " " + someRandomNumber;
  228.   }
  229. }
  230.  
  231.