| 1 | <!-- |
|---|
| 2 | This file is a test of the reference integrity code of ItemFileWriteStore and its interaction with widgets. |
|---|
| 3 | --> |
|---|
| 4 | <html> |
|---|
| 5 | <head> |
|---|
| 6 | <title>Demo of Tree widget and reference integrity in ItemFileWriteStore</title> |
|---|
| 7 | <style type="text/css"> |
|---|
| 8 | @import "dijit/themes/tundra/tundra.css"; |
|---|
| 9 | @import "dojo/resources/dojo.css"; |
|---|
| 10 | @import "dijit/tests/css/dijitTests.css"; |
|---|
| 11 | </style> |
|---|
| 12 | |
|---|
| 13 | <script type="text/javascript" src="dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script> |
|---|
| 14 | <script type="text/javascript"> |
|---|
| 15 | dojo.require("dojo.parser"); |
|---|
| 16 | dojo.require("dijit.form.ComboBox"); |
|---|
| 17 | dojo.require("dijit.Tree"); |
|---|
| 18 | dojo.require("dijit.form.Button"); |
|---|
| 19 | dojo.require("dojo.data.ItemFileWriteStore"); |
|---|
| 20 | |
|---|
| 21 | function init(){ |
|---|
| 22 | function deleteItem(){ |
|---|
| 23 | console.log("Button clicked."); |
|---|
| 24 | function onItem(item, request){ |
|---|
| 25 | if (item) { |
|---|
| 26 | console.log("Deletion in process."); |
|---|
| 27 | refStore.deleteItem(item); |
|---|
| 28 | refStore.save(); |
|---|
| 29 | } |
|---|
| 30 | } |
|---|
| 31 | function onError(error, request){ |
|---|
| 32 | console.debug(error); |
|---|
| 33 | } |
|---|
| 34 | refStore.fetchItemByIdentity({identity: 10, onItem: onItem, onError: onError}); |
|---|
| 35 | } |
|---|
| 36 | dojo.connect(deleteButton, "onClick", deleteItem); |
|---|
| 37 | |
|---|
| 38 | function onSet(item, attribute, oldValue, newValue){ |
|---|
| 39 | console.log("Item modified: " + refStore.getValue(item, "name") + ". Modified Attribute: " + attribute); |
|---|
| 40 | } |
|---|
| 41 | dojo.connect(refStore, "onSet", onSet); |
|---|
| 42 | function onDelete(item){ |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | console.log("Item deleted: " + item["name"][0]); |
|---|
| 46 | } |
|---|
| 47 | dojo.connect(refStore, "onDelete", onDelete); |
|---|
| 48 | |
|---|
| 49 | } |
|---|
| 50 | dojo.addOnLoad(init) |
|---|
| 51 | |
|---|
| 52 | </script> |
|---|
| 53 | </head> |
|---|
| 54 | |
|---|
| 55 | <body class="tundra"> |
|---|
| 56 | <h1> |
|---|
| 57 | TEST: Test that verifies reference integrity properly works with dijit.Tree |
|---|
| 58 | </h1> |
|---|
| 59 | <hr> |
|---|
| 60 | <h3> |
|---|
| 61 | Description: |
|---|
| 62 | </h3> |
|---|
| 63 | <p> |
|---|
| 64 | This simple test loads a set of data with lots of references, then allows you to delete the item with id 10. That should ripple reference cleanup through the tree |
|---|
| 65 | </p> |
|---|
| 66 | |
|---|
| 67 | <!-- |
|---|
| 68 | The store instances used by this demo. |
|---|
| 69 | --> |
|---|
| 70 | <div dojoType="dojo.data.ItemFileWriteStore" url="dojo/tests/data/reference_integrity.json" jsId="refStore"></div> |
|---|
| 71 | |
|---|
| 72 | <h3> |
|---|
| 73 | Tree widget using ItemFileWriteStore: |
|---|
| 74 | </h3> |
|---|
| 75 | <blockquote> |
|---|
| 76 | |
|---|
| 77 | <div dojoType="dijit.form.Button" label="Delete Item 10" jsId="deleteButton"></div> |
|---|
| 78 | <BR> |
|---|
| 79 | <BR> |
|---|
| 80 | <b>Tree:</b><br> |
|---|
| 81 | <div dojoType="dijit.Tree" id="tree" label="Items" childrenAttr="friends, enemies, sibblings" store="refStore"></div> |
|---|
| 82 | </blockquote> |
|---|
| 83 | </body> |
|---|
| 84 | </html> |
|---|