home *** CD-ROM | disk | FTP | other *** search
/ PC World 2006 December / PCWorld_2006-12_cd.bin / komunikace / netscape / nsb-install-8-1-2.exe / chrome / aim.jar / content / aim / contextMenu.js < prev    next >
Text File  |  2006-01-06  |  13KB  |  332 lines

  1. /*------------------------------ nsContextMenu ---------------------------------
  2. |   This JavaScript "class" is used to implement the IM standalon's            |
  3. |   content-area context menu.                                                 |
  4. |                                                                              |
  5. |   For usage, see references to this class in contextMenu.xul.                |
  6. |                                                                              |
  7. ------------------------------------------------------------------------------*/
  8. // global context menu
  9. //var contextMenu = null;
  10.  
  11. function nsContextMenu( xulMenu ) {
  12.   this.menu                  = null;
  13.   this.onlineTab        = false;
  14.   this.listSetupTab     = false;
  15.   this.sidebar          = false;
  16.   this.screenName       = "";
  17.   this.target           = null;
  18.  
  19.   // Initialize new menu.
  20.   this.initMenu( xulMenu );
  21. }
  22.  
  23. // Prototype for nsContextMenu "class."
  24. nsContextMenu.prototype = {
  25.  
  26.     // onDestroy is a no-op at this point.
  27.     onDestroy : function () {
  28.     },
  29.  
  30.     // Initialize context menu.
  31.     initMenu : function ( popup, event ) {
  32.         
  33.         this.menu = popup;
  34.  
  35.         // Get contextual info.
  36.         this.setTarget( document.popupNode );
  37.     
  38.         // Initialize (disable/remove) menu items.
  39.         this.initItems();
  40.     },
  41.  
  42.     initItems : function () {
  43.         this.initOnlineItems();
  44.         this.initListSetupItems();
  45.         var supportmailim = aimPrefsManager().GetBoolPref("aim.session.supportmailim", null, false);
  46.         if (!supportmailim) {
  47.           this.setItemAttr("menu_switchview","hidden", "true");
  48.           this.setItemAttr("dispNameseparator","hidden", "true");
  49.           this.setItemAttr("context-editbuddyinfo","hidden", "true");
  50.           // this.setItemAttr("context-editdispname","hidden", "true");
  51.           // this.setItemAttr("context-updateemail","hidden", "true");
  52.           this.setItemAttr("preemailseperator","hidden", "true");
  53.           this.setItemAttr("context-sendemail","hidden", "true");
  54.           this.setItemAttr("context-checkemail","hidden", "true");
  55.           this.setItemAttr("gmiseparator","hidden", "true");
  56.         }
  57.     },
  58.  
  59.     initOnlineItems : function () {
  60.       this.showItem("context-getMemberInfo", this.onlineTab );
  61.       this.showItem( "context-sendIM", this.onlineTab );
  62.       this.showItem( "context-sendChat", this.onlineTab );
  63.       this.showItem("context-block");
  64.       this.showItem("blockseperator");
  65.       if (this.screenName != "" && this.screenName != null) {
  66.         this.setItemAttr("sendfileseparator","hidden", this.listSetupTab);
  67.         this.showItem( "context-sendFile", this.onlineTab );
  68.         this.showItem("context-block", this.menu);
  69.         this.showItem("blockseperator", this.menu);
  70.         var isInList = new Object();
  71.         aimBuddyManager().IsBuddyInAlertList(this.screenName, isInList);
  72.         if ( isInList.value == false ) {
  73.           // Set the appropriate node's screen name to the buddy alert menu item
  74.           this.setItemAttr("context-editbuddyAlert","hidden", "true");
  75.           this.setItemAttr("context-delbuddyAlert","hidden", "true");
  76.           var Msg1=window.document.getElementById("context-buddyAlert").getAttribute("label1");
  77.           var Msg2=window.document.getElementById("context-buddyAlert").getAttribute("label2");
  78.           var newlabel=Msg1+this.screenName+Msg2;
  79.           window.document.getElementById("context-buddyAlert").setAttribute('label', newlabel);
  80.           this.setItemAttr("buddyalertseperator","hidden", "false");
  81.           this.setItemAttr("context-buddyAlert","hidden", "false");
  82.         }
  83.         else {
  84.           // Set the Edit and Del buddy alert menu item
  85.           var Msg1=window.document.getElementById("context-delbuddyAlert").getAttribute("label1");
  86.           var Msg2=window.document.getElementById("context-delbuddyAlert").getAttribute("label2");
  87.           var newlabel=Msg1+this.screenName+Msg2;
  88.           this.setItemAttr("context-buddyAlert","hidden", "true");
  89.           window.document.getElementById("context-delbuddyAlert").setAttribute('label', newlabel);
  90.           this.setItemAttr("context-editbuddyAlert","hidden", "false");
  91.           this.setItemAttr("context-delbuddyAlert","hidden", "false");
  92.         }
  93.       }
  94.       else {
  95.         //selected node has no screen name so it is a group
  96.         this.setItemAttr("sendfileseparator","hidden", "true");
  97.         //this.setItemAttr("buddyalertseperator","hidden", "true");
  98.         this.setItemAttr("context-buddyAlert","hidden", "true");
  99.         this.setItemAttr("context-editbuddyAlert","hidden", "true");
  100.         this.setItemAttr("buddyalertseperator","hidden", "true");
  101.         this.showItem( "context-sendFile", false);
  102.         this.showItem("sendfileseparator", false);
  103.         //this.showItem("context-editdispname", false);
  104.         //this.showItem("context-sendemail", false);
  105.         //this.showItem("context-checkemail", false);
  106.         //this.showItem("context-updateemail", false);
  107.         //this.setItemAttr("dispNameseparator","hidden", "true");
  108.         //this.setItemAttr("preemailseperator","hidden", "true");
  109.         //this.setItemAttr("emailseperator","hidden", "true");
  110.         this.setItemAttr("sendfileseparator","hidden", "true");
  111.       }
  112.       
  113.       this.showItem( "onlineseparator", this.onlineTab );
  114.       //this.showItem( "context-EditList", this.sidebar );
  115.     },
  116.  
  117.     initListSetupItems : function () {
  118.         //this.showItem("context-buddyAlert", this.listSetupTab );
  119.         //this.showItem( "context-addBuddy", this.listSetupTab );
  120. //        this.showItem( "context-addGroup", this.listSetupTab );
  121. //        this.showItem( "context-delete", this.listSetupTab );
  122.         //this.showItem( "context-editAB", this.listSetupTab );
  123.       this.setItemAttr("sendfileseparator","hidden", this.listSetupTab);
  124.       this.setItemAttr("dispNameseparator","hidden", this.listSetupTab);
  125.     },
  126.  
  127.     // Set various context menu attributes based on the state of the world.
  128.     setTarget : function ( node ) {
  129.         // Remember the node that was clicked.
  130.         this.target = node;
  131.               var sidebarframe=window; 
  132.           // determine if we're in the standalone or sidebar
  133.         var parentState = top.document.getElementById("AimSidebarState");
  134.         if(!parentState)
  135.         {
  136.             var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");
  137.             if (tab.selectedIndex == 0 )  
  138.                 {
  139.                 this.sidebar = true;   
  140.                 this.onlineTab = true;
  141.                 this.listSetupTab = false;
  142.                 }        
  143.                        else
  144.                 {
  145.                 this.sidebar = true;   
  146.                                 this.onlineTab = false;
  147.                                 this.listSetupTab = true;  
  148.                 }
  149.         }
  150.         else
  151.         {
  152.               var curTab;
  153.               curTab = parentState.getAttribute("AimSidebarTab");
  154.           // Determine if we're in the Online tab or List Setup tab
  155.               if(curTab == "Online")
  156.                   {
  157.                       this.onlineTab = true;
  158.                       this.listSetupTab  = false;
  159.               this.sidebar = false;
  160.                   }
  161.               else
  162.                   {
  163.                       this.listSetupTab = true;
  164.                       this.onlineTab = false;
  165.               this.sidebar = false;
  166.                   }
  167.           }
  168.  
  169.         // set the screen name based on the target
  170.         //this.screenName = this.target.parentNode.parentNode.getAttribute('ScreenName');
  171.         this.screenName = getSelectedScreenName();
  172.         
  173.     },
  174.  
  175.     // sendIM
  176.     cmdContextSendIM : function () {
  177.       dump("Context: Send IM\n");
  178.     cmdNewIM();
  179. /*      if (aimIMDoesIMExist(this.screenName))
  180.               aimErrorBox(aimString("msg.DuplicateIM"));
  181.           else 
  182.                 aimIMInvokeIMForm(this.screenName);
  183. */
  184.     },
  185.  
  186.     // sendChat
  187.     cmdContextSendChat : function () {
  188.           //window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no','', false,'outgoingchat');
  189.      inviteArgsObj = {
  190.          inviteProposalScreenName: '', 
  191.          inviteProposalObj: null,
  192.          invitedScreenNames: getSelectedBuddiesFromList(),
  193.          inviteToExistingWindow: false,
  194.          inviteMode: 'outgoingchat'
  195.          }
  196.           window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  197.  
  198.  
  199.           dump("Context: Chat\n");
  200.     },
  201.  
  202.     cmdContextSendFile : function () {
  203.      inviteArgsObj = {
  204.          inviteProposalScreenName: getSelectedScreenName(), 
  205.          inviteProposalObj: null,
  206.          inviteToExistingWindow: false,
  207.          inviteMode: 'outgoingfile'
  208.          }
  209.           window.openDialog('chrome://aim/content/sendfile.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  210.     },
  211.  
  212.     cmdContextGetMemberInfo : function () {
  213.       var screenName = getSelectedScreenName();
  214.       window.openDialog('chrome://aim/content/GetMemberInfo.xul','_blank','chrome,all,dialog=no', screenName);
  215.     },
  216.  
  217.     // Edit List
  218.     cmdContextEditList : function  () {
  219.       dump("Context: Edit List\n");
  220.       //toOpenWindowByType2('Aim:AimApp', 'chrome://aim/content/App.xul');
  221.     },
  222.  
  223.     // addbuddy
  224.     cmdContextAddBuddy : function () {
  225.       dump("Context: Add Buddy\n");
  226.       cmdAddBuddy();
  227.     },
  228.  
  229.     // addGroup
  230.     cmdContextAddGroup : function () {
  231.       dump("Context: Add Group\n");
  232.       cmdAddGroup();
  233.     },
  234.  
  235.       // delete
  236.     cmdContextDelete : function () {
  237.       dump("Context: Delete\n");
  238.       cmdDelete();
  239.     },
  240.  
  241.     cmdContextBuddyAlert : function (isedit) {
  242.       var screenName = getSelectedScreenName();
  243.       var groupName = getGroupForScreenName();
  244.       if (screenName && (screenName != null) && groupName && (groupName != null)) 
  245.       {
  246.         if (isedit == 1) 
  247.           window.openDialog('chrome://aim/content/AimBuddyAlert.xul','_blank','chrome,all,dialog=no', screenName, groupName, 1);
  248.         else
  249.           window.openDialog('chrome://aim/content/AimBuddyAlert.xul','_blank','chrome,all,dialog=no', screenName, groupName, null);
  250.       }    
  251.     },
  252.     
  253.     cmdContextDelBuddyAlert : function () {
  254.       var screenName = getSelectedScreenName();
  255.       var groupName = getGroupForScreenName();
  256.       if (screenName && (screenName != null) && groupName && (groupName != null))
  257.         aimBuddyManager().DeleteBuddyFromAlertList(screenName, groupName);
  258.     },
  259.  
  260.     cmdContextBlockBuddy : function () {
  261.       var pIAimPrivacy = aimPrivacy();
  262.       if ( !pIAimPrivacy )
  263.         return false;
  264.       pIAimPrivacy.BlockUser(this.screenName);
  265.     },
  266.  
  267.     //cmdContextEditAB : function () {
  268.       //dump("Context: Edit AddressBook\n");
  269.       //cmdAbEditCard();
  270.     //},     
  271.  
  272.     // Utilities
  273.  
  274.     // Show/hide one item (specified via name or the item element itself).
  275.     showItem : function ( itemOrId, show ) {
  276.         var item = null;
  277.         if ( itemOrId.constructor == String ) {
  278.             // Argument specifies item id.
  279.             item = document.getElementById( itemOrId );
  280.         } else {
  281.             // Argument is the item itself.
  282.             item = itemOrId;
  283.         }
  284.         if ( item ) {
  285.             var styleIn = item.getAttribute( "style" );
  286.             var styleOut = styleIn;
  287.             if ( show ) {
  288.                 // Remove style="display: none;".
  289.                 styleOut = styleOut.replace( "display: none;", "" );
  290.  
  291.             } else {
  292.                 // Set style="display: none;".
  293.                 if ( styleOut.indexOf( "display: none;" ) == -1 ) {
  294.                     // Add style the first time we need to.
  295.                     styleOut += "display: none;";
  296.                 }
  297.             }
  298.             // Only set style if it's different.
  299.             if ( styleIn != styleOut ) {
  300.                 item.setAttribute( "style", styleOut );
  301.             }
  302.         }
  303.     },
  304.  
  305.     // Set given attribute of specified context-menu item.  If the
  306.     // value is null, then it removes the attribute (which works
  307.     // nicely for the disabled attribute).
  308.     setItemAttr : function ( id, attr, val ) {
  309.         var elem = document.getElementById( id );
  310.         if ( elem ) {
  311.             if ( val == null ) {
  312.                 // null indicates attr should be removed.
  313.                 elem.removeAttribute( attr );
  314.             } else {
  315.                 // Set attr=val.
  316.                 elem.setAttribute( attr, val );
  317.             }
  318.         }
  319.     },
  320.  
  321.     // Set context menu attribute according to like attribute of another node
  322.     // (such as a broadcaster).
  323.     setItemAttrFromNode : function ( item_id, attr, other_id ) {
  324.         var elem = document.getElementById( other_id );
  325.         if ( elem && elem.getAttribute( attr ) == "true" ) {
  326.             this.setItemAttr( item_id, attr, "true" );
  327.         } else {
  328.             this.setItemAttr( item_id, attr, null );
  329.         }
  330.     }
  331. };
  332.