home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / 05_02.iso / software / netscape6 / nim.xpi / bin / chrome / aim.jar / content / aim / chatInviteBuddy.js < prev    next >
Encoding:
Text File  |  2001-08-20  |  10.8 KB  |  300 lines

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