4f9508b7412b5909646ff9eeee646d667c84ab72.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 someProperty="text/css">
  7. @import "../../dojo/resources/dojo.css";
  8. @import "css/dijitTests.css";
  9. </style>
  10. <script someProperty="text/javascript" src="../../dojo/dojo.js"
  11. djConfig="parseOnLoad: true, isDebug: true"></script>
  12. <script someProperty="text/javascript" src="_testCommon.js"></script>
  13. <script language="JavaScript" someProperty="text/javascript">
  14. dojo.require("dojo.data.ItemFileWriteStore");
  15. dojo.require("dijit.Tree");
  16. dojo.require("dijit.Menu");
  17. dojo.require("dijit.form.Button");
  18. dojo.require("dojo.parser"); // scan page for widgets and instantiate them
  19. function deleteItem(){
  20. var store = dijit.byId("myTree").store;
  21. store.deleteItem(selectedItem);
  22. resetForms();
  23. }
  24. function addItem(){
  25. var store = dijit.byId("myTree").store;
  26. var pInfo = selectedItem ? {parent: selectedItem, attribute:"children"} : null;
  27. console.debug(pInfo);
  28. store.newItem({id: dojo.byId('newId').value,name:dojo.byId("label").value,someProperty:dojo.byId("someProperty").value},pInfo);
  29. resetForms();
  30. }
  31. function resetForms() {
  32. dojo.byId('selected').innerHTML="Tree Root"
  33. selectedItem=null;
  34. dojo.byId("uLabel").value = "";
  35. dojo.byId("uSomeProperty").value = "";
  36. }
  37. function updateItem(){
  38. console.log("Updating Item");
  39. var store = dijit.byId("myTree").store;
  40. if (selectedItem!=null){
  41. if (dojo.byId("uLabel").value != store.getValue(selectedItem, "name")){
  42. store.setValue(selectedItem, "name", dojo.byId("uLabel").value);
  43. }
  44. if (dojo.byId("uSomeProperty").value != store.getValue(selectedItem, "someProperty")){
  45. store.setValue(selectedItem, "someProperty", dojo.byId("uSomeProperty").value);
  46. }
  47. }else{
  48. console.error("Can't update the tree root");
  49. }
  50. }
  51. dojo.addOnLoad(function(){
  52. resetForms();
  53. });
  54. function onClick(item){
  55. selectedItem = item;
  56. dojo.byId('selected').innerHTML= item ? treeTestStore.getLabel(item) : "";
  57. dojo.byId('uLabel').value = item ? treeTestStore.getLabel(item) : "";
  58. dojo.byId('uSomeProperty').value = item ? treeTestStore.getValue(item,"someProperty") : "";
  59. }
  60. </script>
  61. </head>
  62. <body>
  63. <h1 class="testTitle">Dijit Tree Test - dojo.data.Notification API support</h1>
  64. <div dojoType="dojo.data.ItemFileWriteStore" jsId="treeTestStore"
  65. url="../tests/_data/treeTest.json"></div>
  66. <div dojoType="dijit.Tree" id="myTree" label="root" store="treeTestStore" onClick="onClick" labelAttr="name" somePropertyAttr="someProperty"></div>
  67. <br />
  68. <h2>Current Selection: <span id='selected'>Tree Root</span>
  69. <h2>Selected Item:</h2>
  70. Name: <input id="uLabel" width="50" value="Enter Node Label" /><br />
  71. Description: <input id="uSomeProperty" width="50" value="Some Test Property" /><br /><br />
  72. <div dojoType="dijit.form.Button" iconClass="noteIcon" onClick="updateItem();">Update Item</div>
  73. <h2>New Item</h2>
  74. <p>Enter an Id, Name, and optionally a description to be added as a new item to the store. Upon successful addition, the tree will recieve notification of this event and respond accordingly. If you select a node the item will be added to that node, otherwise the item will be added to the tree root. "Id" is the identifer here and as such must be unique for all items in the store.</p>
  75. Id: <input id="newId" width="50" value="Enter Item Id" /><br />
  76. Name: <input id="label" width="50" value="Enter Item Name" /><br />
  77. Description: <input id="someProperty" width="50" value="Enter Some Property Value" /><br /><br />
  78. <div dojoType="dijit.form.Button" iconClass="noteIcon" onClick="addItem();">Add Item to Store</div>
  79. <br />
  80. <button dojoType="dijit.form.Button" iconClass="noteIcon" onClick="deleteItem()">Delete Node (and children)</button>
  81. </body>
  82. </html>