a315a5533bd21eb2f8c22712f5c4d2eb84bde8a5.svn-base 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5. <title>Dijit Tree Test</title>
  6. <style type="text/css">
  7. @import "../../dojo/resources/dojo.css";
  8. @import "css/dijitTests.css";
  9. </style>
  10. <script type="text/javascript" src="../../dojo/dojo.js"
  11. djConfig="parseOnLoad: true, isDebug: true"></script>
  12. <script type="text/javascript" src="_testCommon.js"></script>
  13. <script language="JavaScript" type="text/javascript">
  14. dojo.require("dojo.data.ItemFileReadStore");
  15. dojo.require("dijit.Tree");
  16. dojo.require("dijit.ColorPalette");
  17. dojo.require("dijit.Menu");
  18. dojo.require("dojo.parser"); // scan page for widgets and instantiate them
  19. </script>
  20. </head>
  21. <body>
  22. <h1 class="testTitle">Dijit Tree Test</h1>
  23. <div dojoType="dojo.data.ItemFileReadStore" jsId="continentStore"
  24. url="../tests/_data/countries.json"></div>
  25. <h3>Tree with hardcoded root node (not corresponding to any item in the store)</h3>
  26. <div dojoType="dijit.Tree" id="mytree" store="continentStore" query="{type:'continent'}"
  27. labelAttr="name" label="Continents">
  28. <script type="dojo/method" event="onClick" args="item">
  29. if(item){
  30. alert("Execute of node " + continentStore.getLabel(item)
  31. +", population=" + continentStore.getValue(item, "population"));
  32. }else{
  33. alert("Execute on root node");
  34. }
  35. </script>
  36. <script type="dojo/method" event="getIconClass" args="item">
  37. return "noteIcon";
  38. </script>
  39. </div>
  40. <button onclick="dijit.byId('mytree').destroyRecursive();">destroy</button>
  41. <h2>A rootless tree (no "continents" node) with context menus</h2>
  42. <ul dojoType="dijit.Menu" id="tree_menu" style="display: none;">
  43. <li dojoType="dijit.MenuItem" onClick="alert('Hello world');">Enabled Item</li>
  44. <li dojoType="dijit.MenuItem" disabled="true">Disabled Item</li>
  45. <li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCut"
  46. onClick="alert('not actually cutting anything, just a test!')">Cut</li>
  47. <li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCopy"
  48. onClick="alert('not actually copying anything, just a test!')">Copy</li>
  49. <li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconPaste"
  50. onClick="alert('not actually pasting anything, just a test!')">Paste</li>
  51. <li dojoType="dijit.PopupMenuItem">
  52. <span>Enabled Submenu</span>
  53. <ul dojoType="dijit.Menu" id="submenu2">
  54. <li dojoType="dijit.MenuItem" onClick="alert('Submenu 1!')">Submenu Item One</li>
  55. <li dojoType="dijit.MenuItem" onClick="alert('Submenu 2!')">Submenu Item Two</li>
  56. <li dojoType="dijit.PopupMenuItem">
  57. <span>Deeper Submenu</span>
  58. <ul dojoType="dijit.Menu" id="submenu4">
  59. <li dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 1!')">Sub-sub-menu Item One</li>
  60. <li dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 2!')">Sub-sub-menu Item Two</li>
  61. </ul>
  62. </li>
  63. </ul>
  64. </li>
  65. <li dojoType="dijit.PopupMenuItem" disabled="true">
  66. <span>Disabled Submenu</span>
  67. <ul dojoType="dijit.Menu" id="submenu3" style="display: none;">
  68. <li dojoType="dijit.MenuItem" onClick="alert('Submenu 1!')">Submenu Item One</li>
  69. <li dojoType="dijit.MenuItem" onClick="alert('Submenu 2!')">Submenu Item Two</li>
  70. </ul>
  71. </li>
  72. </ul>
  73. <div dojoType="dijit.Tree" id="tree2" store="continentStore" query="{type:'continent'}">
  74. <script type="dojo/connect">
  75. var menu = dijit.byId("tree_menu");
  76. // when we right-click anywhere on the tree, make sure we open the menu
  77. menu.bindDomNode(this.domNode);
  78. dojo.connect(menu, "_openMyself", this, function(e){
  79. // get a hold of, and log out, the tree node that was the source of this open event
  80. var tn = this._domElement2TreeNode(e.target);
  81. console.debug(tn);
  82. // now inspect the data store item that backs the tree node:
  83. console.debug(tn.item);
  84. // contrived condition: if this tree node doesn't have any children, disable all of the menu items
  85. menu.getChildren().forEach(function(i){ i.setDisabled(!tn.item.children); });
  86. // IMPLEMENT CUSTOM MENU BEHAVIOR HERE
  87. });
  88. </script>
  89. <script type="dojo/method" event="getIconClass" args="item">
  90. return "noteIcon";
  91. </script>
  92. </div>
  93. </body>
  94. </html>