DataStore.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.wire.ml.DataStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.wire.ml.DataStore"] = true;
  8. dojo.provide("dojox.wire.ml.DataStore");
  9. dojo.require("dijit._Widget");
  10. dojo.require("dojox.wire._base");
  11. dojo.declare("dojox.wire.ml.DataStore", dijit._Widget, {
  12. // summary:
  13. // A widget for a data store
  14. // description:
  15. // This widget represents a data store of 'storeClass' attribute.
  16. // storeClass:
  17. // A class name of a data store
  18. storeClass: "",
  19. postCreate: function(){
  20. // summary:
  21. // Call _createStore()
  22. // description:
  23. // See _createStore().
  24. this.store = this._createStore();
  25. },
  26. _createStore: function(){
  27. // summary:
  28. // Create a data store
  29. // desription:
  30. // A data store of 'storeClass' is created with arguments
  31. // specified with attributes.
  32. // returns:
  33. // A data store
  34. if(!this.storeClass){
  35. return null; //null
  36. }
  37. var storeClass = dojox.wire._getClass(this.storeClass);
  38. if(!storeClass){
  39. return null; //null
  40. }
  41. var args = {};
  42. var attributes = this.domNode.attributes;
  43. for(var i = 0; i < attributes.length; i++){
  44. var a = attributes.item(i);
  45. if(a.specified && !this[a.nodeName]){
  46. args[a.nodeName] = a.nodeValue;
  47. }
  48. }
  49. return new storeClass(args); //Object
  50. },
  51. getFeatures: function(){
  52. // summary:
  53. // Call getFeatures() method of a data store
  54. // description:
  55. // See dojo.data.api.Read.getFeatures().
  56. // returns:
  57. // A features object
  58. return this.store.getFeatures(); //Object
  59. },
  60. fetch: function(/*Object*/request){
  61. // summary:
  62. // Call fetch() method of a data store
  63. // description:
  64. // See dojo.data.api.Read.fetch().
  65. // request:
  66. // A request object
  67. // returns:
  68. // A request object
  69. return this.store.fetch(request); //Object
  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. newItem: function(/*Object*/args){
  81. // summary:
  82. // Call newItem() method of a data store
  83. // description:
  84. // See dojo.data.api.Write.newItem().
  85. // args:
  86. // A new item arguments object
  87. // returns:
  88. // A new item
  89. return this.store.newItem(args); //Object
  90. },
  91. deleteItem: function(/*Object*/item){
  92. // summary:
  93. // Call deleteItem() method of a data store
  94. // description:
  95. // See dojo.data.api.Write.deleteItem().
  96. // returns:
  97. // A boolean
  98. return this.store.deleteItem(item); //Boolean
  99. },
  100. revert: function(){
  101. // summary:
  102. // Call revert() method of a data store
  103. // description:
  104. // See dojo.data.api.Write.revert().
  105. // returns:
  106. // A boolean
  107. return this.store.revert(); //Boolean
  108. }
  109. });
  110. }