| 1 | dojo.provide("dojox.wire.ml.DataStore"); |
| 2 | |
| 3 | dojo.require("dijit._Widget"); |
| 4 | dojo.require("dojox.wire._base"); |
| 5 | |
| 6 | dojo.declare("dojox.wire.ml.DataStore", dijit._Widget, { |
| 7 | // summary: |
| 8 | // A widget for a data store |
| 9 | // description: |
| 10 | // This widget represents a data store of 'storeClass' attribute. |
| 11 | // storeClass: |
| 12 | // A class name of a data store |
| 13 | storeClass: "", |
| 14 | |
| 15 | postCreate: function(){ |
| 16 | // summary: |
| 17 | // Call _createStore() |
| 18 | // description: |
| 19 | // See _createStore(). |
| 20 | this.store = this._createStore(); |
| 21 | }, |
| 22 | |
| 23 | _createStore: function(){ |
| 24 | // summary: |
| 25 | // Create a data store |
| 26 | // description: |
| 27 | // A data store of 'storeClass' is created with arguments |
| 28 | // specified with attributes. |
| 29 | // returns: |
| 30 | // A data store |
| 31 | if(!this.storeClass){ |
| 32 | return null; //null |
| 33 | } |
| 34 | var storeClass = dojox.wire._getClass(this.storeClass); |
| 35 | if(!storeClass){ |
| 36 | return null; //null |
| 37 | } |
| 38 | var args = {}; |
| 39 | var attributes = this.domNode.attributes; |
| 40 | for(var i = 0; i < attributes.length; i++){ |
| 41 | var a = attributes.item(i); |
| 42 | if(a.specified && !this[a.nodeName]){ |
| 43 | args[a.nodeName] = a.nodeValue; |
| 44 | } |
| 45 | } |
| 46 | return new storeClass(args); //Object |
| 47 | }, |
| 48 | |
| 49 | getFeatures: function(){ |
| 50 | // summary: |
| 51 | // Call getFeatures() method of a data store |
| 52 | // description: |
| 53 | // See dojo/data/api/Read.getFeatures(). |
| 54 | // returns: |
| 55 | // A features object |
| 56 | return this.store.getFeatures(); //Object |
| 57 | }, |
| 58 | |
| 59 | fetch: function(/*Object*/request){ |
| 60 | // summary: |
| 61 | // Call fetch() method of a data store |
| 62 | // description: |
| 63 | // See dojo/data/api/Read.fetch(). |
| 64 | // request: |
| 65 | // A request object |
| 66 | // returns: |
| 67 | // A request object |
| 68 | return this.store.fetch(request); //Object |
| 69 | }, |
| 70 | |
| 71 | save: function(/*Object*/args){ |
| 72 | // summary: |
| 73 | // Call save() method of a data store |
| 74 | // description: |
| 75 | // See dojo/data/api/Write.save(). |
| 76 | // args: |
| 77 | // A save arguments object |
| 78 | this.store.save(args); |
| 79 | }, |
| 80 | |
| 81 | newItem: function(/*Object*/args){ |
| 82 | // summary: |
| 83 | // Call newItem() method of a data store |
| 84 | // description: |
| 85 | // See dojo/data/api/Write.newItem(). |
| 86 | // args: |
| 87 | // A new item arguments object |
| 88 | // returns: |
| 89 | // A new item |
| 90 | return this.store.newItem(args); //Object |
| 91 | }, |
| 92 | |
| 93 | deleteItem: function(/*Object*/item){ |
| 94 | // summary: |
| 95 | // Call deleteItem() method of a data store |
| 96 | // description: |
| 97 | // See dojo/data/api/Write.deleteItem(). |
| 98 | // returns: |
| 99 | // A boolean |
| 100 | return this.store.deleteItem(item); //Boolean |
| 101 | }, |
| 102 | |
| 103 | revert: function(){ |
| 104 | // summary: |
| 105 | // Call revert() method of a data store |
| 106 | // description: |
| 107 | // See dojo/data/api/Write.revert(). |
| 108 | // returns: |
| 109 | // A boolean |
| 110 | return this.store.revert(); //Boolean |
| 111 | } |
| 112 | }); |