Debian Codegraph @

dojox/data/tests/stores/test_Tree_on_JsonRestStore.html

raw symbols SCIP
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Dijit Tree Test</title>
5
6 <style>
7 @import "../../../../dojo/resources/dojo.css";
8 @import "../../../../dijit/tests/css/dijitTests.css";
9 </style>
10
11 <!-- required: a default theme file -->
12 <link rel="stylesheet" id="themeStyles" href="../../../../dijit/themes/tundra/tundra.css">
13
14 <!-- required: dojo.js -->
15 <script src="../../../../dojo/dojo.js"
16 djConfig="parseOnLoad: true, isDebug: true"></script>
17
18 <!-- do not use: only for testing alternate themes -->
19 <script src="../../../../dijit/tests/_testCommon.js"></script>
20
21 <script>
22 dojo.require("dojox.data.JsonRestStore");
23 dojo.require("dijit.Tree");
24 dojo.require("dijit.Menu");
25 dojo.require("dijit.form.Button");
26 dojo.require("dojo.parser"); // scan page for widgets and instantiate them
27 treeTestStore = new dojox.data.JsonRestStore({target:"./", labelAttribute:"name"});
28 treeTestModel = new dijit.tree.ForestStoreModel({
29 store: treeTestStore,
30 deferItemLoadingUntilExpand: true,
31 query: "treeTestRoot",
32 childrenAttrs: ["children"]
33 });
34 function deleteItem(){
35 var store = dijit.byId("myTree").store;
36 store.deleteItem(selectedItem);
37 resetForms();
38 }
39
40 function addItem(){
41 var store = dijit.byId("myTree").store;
42 var pInfo = selectedItem ? {parent: selectedItem, attribute:"children"} : null;
43 console.debug(pInfo);
44 store.newItem({id: dojo.byId('newId').value,name:dojo.byId("label").value,someProperty:dojo.byId("someProperty").value},pInfo);
45 resetForms();
46 }
47
48 function resetForms() {
49 dojo.byId('selected').innerHTML="Tree Root"
50 selectedItem=null;
51 dojo.byId("uLabel").value = "";
52 dojo.byId("uSomeProperty").value = "";
53 }
54
55 function updateItem(){
56 console.log("Updating Item");
57 var store = dijit.byId("myTree").store;
58
59 if (selectedItem!=null){
60 if (dojo.byId("uLabel").value != store.getValue(selectedItem, "name")){
61 store.setValue(selectedItem, "name", dojo.byId("uLabel").value);
62 }
63
64 if (dojo.byId("uSomeProperty").value != store.getValue(selectedItem, "someProperty")){
65 store.setValue(selectedItem, "someProperty", dojo.byId("uSomeProperty").value);
66 }
67
68 }else{
69 console.error("Can't update the tree root");
70 }
71 }
72
73 dojo.addOnLoad(function(){
74 resetForms();
75 });
76
77 function onClick(item){
78 selectedItem = item;
79 dojo.byId('selected').innerHTML= item ? treeTestStore.getLabel(item) : "";
80 dojo.byId('uLabel').value = item ? treeTestStore.getLabel(item) : "";
81 dojo.byId('uSomeProperty').value = item ? treeTestStore.getValue(item,"someProperty") : "";
82 }
83 </script>
84
85 </head>
86 <body class="tundra">
87
88 <h1 class="testTitle">Dijit Tree Test - dojo.data.Notification API support</h1>
89
90
91 <div dojoType="dijit.Tree" id="myTree" label="root" deferItemLoadingUntilExpand="true" model="treeTestModel" onClick="onClick" labelAttr="name" somePropertyAttr="someProperty"></div>
92
93 <br />
94 <h2>Current Selection: <span id='selected'>Tree Root</span></h2>
95
96 <h2>Selected Item:</h2>
97 Name: <input id="uLabel" width="50" value="Enter Node Label" /><br />
98 Description: <input id="uSomeProperty" width="50" value="Some Test Property" /><br /><br />
99 <div dojoType="dijit.form.Button" iconClass="noteIcon" onClick="updateItem();">Update Item</div>
100
101 <h2>New Item</h2>
102 <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 receive 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>
103 Id: <input id="newId" width="50" value="Enter Item Id" /><br />
104 Name: <input id="label" width="50" value="Enter Item Name" /><br />
105 Description: <input id="someProperty" width="50" value="Enter Some Property Value" /><br /><br />
106
107 <div dojoType="dijit.form.Button" iconClass="noteIcon" onClick="addItem();">Add Item to Store</div>
108 <br />
109 <button dojoType="dijit.form.Button" iconClass="noteIcon" onClick="deleteItem()">Delete Node (and children)</button>
110
111
112 </body>
113 </html>