Advertisement
Guest User

ExtJS TreePanel for Campaigns Visualforce Component

a guest
Sep 21st, 2010
464
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 TreePanel -->
  3.     <!-- Jeff Trull 2010-09-19 -->
  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.     <script type="text/javascript">
  16.         Ext.onReady(function(){
  17.             var allowinactive = ("{!allowinactiveselect}" == "true");
  18.             var tree = new Ext.tree.TreePanel({
  19.                 renderTo: 'treediv',
  20.                 useArrows: true,
  21.                 autoScroll: true,
  22.                 animate: true,
  23.                 containerScroll: true,
  24.                 border: false,
  25.                 root: new Ext.tree.TreeNode({
  26.                     text: 'All Campaigns',
  27.                     expanded: true,
  28.                     disabled: true,
  29.                     id: 'camproot'
  30.                 }),
  31.                 listeners: {
  32.                     // for the treepanel - but apparently not the menu - I can define a single event function for the whole thing
  33.                     click: function(n) { {!fn}(n.id.substr(4)); }  // execute supplied callback
  34.                 }
  35.             });
  36.             // add the campaigns as tree nodes
  37.             var parentNode;
  38.             <apex:repeat value="{!CampaignTree}" var="c" id="treenodes">
  39.                 // add this Campaign as a menu item
  40.                 parentNode = tree.getNodeById(("{!c.parentid}" == "") ? "camproot" : ("NODE" + "{!c.parentid}"));
  41.                 parentNode.appendChild(new Ext.tree.TreeNode({id : ("NODE" + "{!c.id}"), text : "{!c.name}", leaf : "{!c.isleaf}",
  42.                                                               // do not allow selecting inactive campaigns
  43.                                                               disabled : !allowinactive && {!NOT(c.isActive)},
  44.                                                               // if they are leafs, do not even show them...
  45.                                                               hidden : !allowinactive && {!AND(c.isLeaf, NOT(c.isActive))}}));
  46.             </apex:repeat>
  47.         });
  48.     </script>
  49.     <div id="treediv"/>
  50.  
  51. </apex:component>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement