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 / contextMenu.js < prev    next >
Encoding:
JavaScript  |  2002-03-25  |  10.5 KB  |  295 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.     },
  46.  
  47.     initOnlineItems : function () {
  48.       this.showItem("context-getMemberInfo", this.onlineTab );
  49.       this.showItem( "context-sendIM", this.onlineTab );
  50.       this.showItem( "context-sendChat", this.onlineTab );
  51.       if (this.screenName != "" && this.screenName != null) {
  52.         this.setItemAttr("sendfileseparator","hidden", this.listSetupTab);
  53.         this.showItem( "context-sendFile", this.onlineTab );
  54.         var isInList = new Object();
  55.         aimBuddyManager().IsBuddyInAlertList(this.screenName, isInList);
  56.         if ( isInList.value == false ) {
  57.           // Set the appropriate node's screen name to the buddy alert menu item
  58.           this.setItemAttr("context-editbuddyAlert","hidden", "true");
  59.           this.setItemAttr("context-delbuddyAlert","hidden", "true");
  60.           var Msg1=window.document.getElementById("context-buddyAlert").getAttribute("label1");
  61.           var Msg2=window.document.getElementById("context-buddyAlert").getAttribute("label2");
  62.           var newlabel=Msg1+this.screenName+Msg2;
  63.           window.document.getElementById("context-buddyAlert").setAttribute('label', newlabel);
  64.           this.setItemAttr("buddyalertseperator","hidden", "false");
  65.           this.setItemAttr("context-buddyAlert","hidden", "false");
  66.         }
  67.         else {
  68.           // Set the Edit and Del buddy alert menu item
  69.           var Msg1=window.document.getElementById("context-delbuddyAlert").getAttribute("label1");
  70.           var Msg2=window.document.getElementById("context-delbuddyAlert").getAttribute("label2");
  71.           var newlabel=Msg1+this.screenName+Msg2;
  72.           this.setItemAttr("context-buddyAlert","hidden", "true");
  73.           window.document.getElementById("context-delbuddyAlert").setAttribute('label', newlabel);
  74.           this.setItemAttr("context-editbuddyAlert","hidden", "false");
  75.           this.setItemAttr("context-delbuddyAlert","hidden", "false");
  76.         }
  77.       }
  78.       else {
  79.         //selected node has no screen name so it is a group
  80.         this.setItemAttr("buddyalertseperator","hidden", "true");
  81.         this.setItemAttr("context-buddyAlert","hidden", "true");
  82.         this.showItem( "context-sendFile", false);
  83.         this.setItemAttr("sendfileseparator","hidden", "true");
  84.       }
  85.       
  86.       this.showItem( "onlineseparator", this.onlineTab );
  87.       //this.showItem( "context-EditList", this.sidebar );
  88.     },
  89.  
  90.     initListSetupItems : function () {
  91.         //this.showItem("context-buddyAlert", this.listSetupTab );
  92.         //this.showItem( "context-addBuddy", this.listSetupTab );
  93. //        this.showItem( "context-addGroup", this.listSetupTab );
  94. //        this.showItem( "context-delete", this.listSetupTab );
  95.         //this.showItem( "context-editAB", this.listSetupTab );
  96.       this.setItemAttr("sendfileseparator","hidden", this.listSetupTab);
  97.     },
  98.  
  99.     // Set various context menu attributes based on the state of the world.
  100.     setTarget : function ( node ) {
  101.         // Remember the node that was clicked.
  102.         this.target = node;
  103.               var sidebarframe=window; 
  104.           // determine if we're in the standalone or sidebar
  105.         var parentState = top.document.getElementById("AimSidebarState");
  106.         if(!parentState)
  107.         {
  108.             var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");
  109.             if (tab.selectedIndex == 0 )  
  110.                 {
  111.                 this.sidebar = true;   
  112.                 this.onlineTab = true;
  113.                 this.listSetupTab = false;
  114.                 }        
  115.                        else
  116.                 {
  117.                 this.sidebar = true;   
  118.                                 this.onlineTab = false;
  119.                                 this.listSetupTab = true;  
  120.                 }
  121.         }
  122.         else
  123.         {
  124.               var curTab;
  125.               curTab = parentState.getAttribute("AimSidebarTab");
  126.           // Determine if we're in the Online tab or List Setup tab
  127.               if(curTab == "Online")
  128.                   {
  129.                       this.onlineTab = true;
  130.                       this.listSetupTab  = false;
  131.               this.sidebar = false;
  132.                   }
  133.               else
  134.                   {
  135.                       this.listSetupTab = true;
  136.                       this.onlineTab = false;
  137.               this.sidebar = false;
  138.                   }
  139.           }
  140.  
  141.         // set the screen name based on the target
  142.         //this.screenName = this.target.parentNode.parentNode.getAttribute('ScreenName');
  143.         this.screenName = getSelectedScreenName();
  144.         
  145.     },
  146.  
  147.     // sendIM
  148.     cmdContextSendIM : function () {
  149.       dump("Context: Send IM\n");
  150.     cmdNewIM();
  151. /*      if (aimIMDoesIMExist(this.screenName))
  152.               aimErrorBox(aimString("msg.DuplicateIM"));
  153.           else 
  154.                 aimIMInvokeIMForm(this.screenName);
  155. */
  156.     },
  157.  
  158.     // sendChat
  159.     cmdContextSendChat : function () {
  160.           //window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no','', false,'outgoingchat');
  161.      inviteArgsObj = {
  162.          inviteProposalScreenName: '', 
  163.          inviteProposalObj: null,
  164.          invitedScreenNames: getSelectedBuddiesFromList(),
  165.          inviteToExistingWindow: false,
  166.          inviteMode: 'outgoingchat'
  167.          }
  168.           window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  169.  
  170.  
  171.           dump("Context: Chat\n");
  172.     },
  173.  
  174.     cmdContextSendFile : function () {
  175.      inviteArgsObj = {
  176.          inviteProposalScreenName: getSelectedScreenName(), 
  177.          inviteProposalObj: null,
  178.          inviteToExistingWindow: false,
  179.          inviteMode: 'outgoingfile'
  180.          }
  181.           window.openDialog('chrome://aim/content/sendfile.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  182.     },
  183.  
  184.     cmdContextGetMemberInfo : function () {
  185.       var screenName = getSelectedScreenName();
  186.       window.openDialog('chrome://aim/content/GetMemberInfo.xul','_blank','chrome,all,dialog=no', screenName);
  187.     },
  188.  
  189.     // Edit List
  190.     cmdContextEditList : function  () {
  191.       dump("Context: Edit List\n");
  192.       //toOpenWindowByType2('Aim:AimApp', 'chrome://aim/content/App.xul');
  193.     },
  194.  
  195.     // addbuddy
  196.     cmdContextAddBuddy : function () {
  197.       dump("Context: Add Buddy\n");
  198.       cmdAddBuddy();
  199.     },
  200.  
  201.     // addGroup
  202.     cmdContextAddGroup : function () {
  203.       dump("Context: Add Group\n");
  204.       cmdAddGroup();
  205.     },
  206.  
  207.       // delete
  208.     cmdContextDelete : function () {
  209.       dump("Context: Delete\n");
  210.       cmdDelete();
  211.     },
  212.  
  213.     cmdContextBuddyAlert : function (isedit) {
  214.       var screenName = getSelectedScreenName();
  215.       if (screenName && (screenName != null)) {
  216.     if (isedit == 1) 
  217.           window.openDialog('chrome://aim/content/AimBuddyAlert.xul','_blank','chrome,all,dialog=no', screenName, 1);
  218.     else
  219.        window.openDialog('chrome://aim/content/AimBuddyAlert.xul','_blank','chrome,all,dialog=no', screenName, null);
  220.      }    
  221.     },
  222.     
  223.     cmdContextDelBuddyAlert : function () {
  224.       var screenName = getSelectedScreenName();
  225.       if (screenName && (screenName != null))
  226.         aimBuddyManager().DeleteBuddyFromAlertList(screenName);
  227.     },
  228.  
  229.  
  230.     //cmdContextEditAB : function () {
  231.       //dump("Context: Edit AddressBook\n");
  232.       //cmdAbEditCard();
  233.     //},     
  234.  
  235.     // Utilities
  236.  
  237.     // Show/hide one item (specified via name or the item element itself).
  238.     showItem : function ( itemOrId, show ) {
  239.         var item = null;
  240.         if ( itemOrId.constructor == String ) {
  241.             // Argument specifies item id.
  242.             item = document.getElementById( itemOrId );
  243.         } else {
  244.             // Argument is the item itself.
  245.             item = itemOrId;
  246.         }
  247.         if ( item ) {
  248.             var styleIn = item.getAttribute( "style" );
  249.             var styleOut = styleIn;
  250.             if ( show ) {
  251.                 // Remove style="display:none;".
  252.                 styleOut = styleOut.replace( "display:none;", "" );
  253.  
  254.             } else {
  255.                 // Set style="display:none;".
  256.                 if ( styleOut.indexOf( "display:none;" ) == -1 ) {
  257.                     // Add style the first time we need to.
  258.                     styleOut += "display:none;";
  259.                 }
  260.             }
  261.             // Only set style if it's different.
  262.             if ( styleIn != styleOut ) {
  263.                 item.setAttribute( "style", styleOut );
  264.             }
  265.         }
  266.     },
  267.  
  268.     // Set given attribute of specified context-menu item.  If the
  269.     // value is null, then it removes the attribute (which works
  270.     // nicely for the disabled attribute).
  271.     setItemAttr : function ( id, attr, val ) {
  272.         var elem = document.getElementById( id );
  273.         if ( elem ) {
  274.             if ( val == null ) {
  275.                 // null indicates attr should be removed.
  276.                 elem.removeAttribute( attr );
  277.             } else {
  278.                 // Set attr=val.
  279.                 elem.setAttribute( attr, val );
  280.             }
  281.         }
  282.     },
  283.  
  284.     // Set context menu attribute according to like attribute of another node
  285.     // (such as a broadcaster).
  286.     setItemAttrFromNode : function ( item_id, attr, other_id ) {
  287.         var elem = document.getElementById( other_id );
  288.         if ( elem && elem.getAttribute( attr ) == "true" ) {
  289.             this.setItemAttr( item_id, attr, "true" );
  290.         } else {
  291.             this.setItemAttr( item_id, attr, null );
  292.         }
  293.     }
  294. };
  295.