Advertisement
Guest User

ExtJS Menu for Campaigns Visualforce Component

a guest
Sep 21st, 2010
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <apex:component controller="CampaignHierarchyController">
  2.     <!-- a VF component for selecting a campaign from the hierarchy with an ExtJS menu tree -->
  3.     <!-- Jeff Trull 2010-09-18 -->
  4.     <apex:attribute name="allowinactiveselect" type="Boolean" description="Whether to permit users to select inactive Campaigns" default="false"/>
  5.     <apex:attribute name="fn" type="String" description="name of a Javascript function to call with ID once a Campaign is selected." required="true"/>
  6.  
  7.     <!-- load ExtJS -->
  8.     <apex:stylesheet value="{!$Resource.ExtJS}/resources/css/ext-all.css" />
  9.     <apex:includeScript value="{!$Resource.ExtJS}/adapter/ext/ext-base.js"/>
  10.     <apex:includeScript value="{!$Resource.ExtJS}/ext-all.js"/>      
  11.     <script type="text/javascript">
  12.         Ext.BLANK_IMAGE_URL="{!$Resource.ExtJS}/resources/images/default/s.gif"
  13.     </script>
  14.  
  15.     <!-- Style to better mimic the look of the Campaign tab -->
  16.     <style type="text/css">
  17.         .x-tree-root-ct { background-color: #F3F3EC }
  18.     </style>
  19.  
  20.     <script>
  21.         Ext.onReady(function() {
  22.             // Build campaign menu tree from controller data
  23.             var campMenu = new Ext.menu.Menu({id: 'campMenu'});                      
  24.             var clickAction = function(n) { {!fn}(n.id.substr(4)); }  // execute supplied callback
  25.             var allowinactive = ("{!allowinactiveselect}" == "true");
  26.                                    
  27.             var parentMenu;                                                                                                            
  28.             <apex:repeat value="{!CampaignTree}" var="c" id="menuitems">                                                                
  29.                 // add this Campaign as a menu item.  Use a munged version of the actual ID for the record for reference                
  30.                 parentMenu = Ext.ComponentMgr.get(("{!c.parentid}" == "") ? "campMenu" : ("MENU" + "{!c.parentid}"));                  
  31.                 if ("{!c.isleaf}" == "true") {
  32.                     parentMenu.add({id : ("CAMP" + "{!c.id}"), text : "{!c.name}", hidden : {!NOT(c.isActive)} && !allowinactive,
  33.                     handler: clickAction});
  34.                 }
  35.                 else {            
  36.                     // define submenu as well, for future children
  37.                     // inactive non-leafs are disabled, but not hidden, in case their children are active for some reason
  38.                     parentMenu.addMenuItem({id : ("CAMP" + "{!c.id}"), text : "{!c.name}", disabled : {!NOT(c.isActive)} && !allowinactive,
  39.                                             menu : {id : ("MENU" + "{!c.id}")}, handler: clickAction});
  40.                 }                                                                                                                      
  41.             </apex:repeat>                                                                                                                            
  42.  
  43.             // make a button for the menu to live in
  44.             var tb = new Ext.Button(
  45.             {
  46.                 text:'Campaign Select Menu',
  47.                 menu: campMenu,
  48.                 renderTo: 'tbd'
  49.             });
  50.         });
  51.     </script>
  52.  
  53.     <div id="tbd"/>
  54.  
  55. </apex:component>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement