Write.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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["dojo.data.api.Write"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojo.data.api.Write"] = true;
  8. dojo.provide("dojo.data.api.Write");
  9. dojo.require("dojo.data.api.Read");
  10. dojo.declare("dojo.data.api.Write", dojo.data.api.Read, {
  11. // summary:
  12. // This is an abstract API that data provider implementations conform to.
  13. // This file defines function signatures and intentionally leaves all the
  14. // functionss unimplemented.
  15. getFeatures: function(){
  16. // summary:
  17. // See dojo.data.api.Read.getFeatures()
  18. return {
  19. 'dojo.data.api.Read': true,
  20. 'dojo.data.api.Write': true
  21. };
  22. },
  23. newItem: function(/* Object? */ keywordArgs, /*Object?*/ parentInfo){
  24. // summary:
  25. // Returns a newly created item. Sets the attributes of the new
  26. // item based on the *keywordArgs* provided. In general, the attribute
  27. // names in the keywords become the attributes in the new item and as for
  28. // the attribute values in keywordArgs, they become the values of the attributes
  29. // in the new item. In addition, for stores that support hierarchical item
  30. // creation, an optional second parameter is accepted that defines what item is the parent
  31. // of the new item and what attribute of that item should the new item be assigned to.
  32. // In general, this will assume that the attribute targetted is multi-valued and a new item
  33. // is appended onto the list of values for that attribute.
  34. //
  35. // keywordArgs:
  36. // A javascript object defining the initial content of the item as a set of JavaScript 'property name: value' pairs.
  37. // parentInfo:
  38. // An optional javascript object defining what item is the parent of this item (in a hierarchical store. Not all stores do hierarchical items),
  39. // and what attribute of that parent to assign the new item to. If this is present, and the attribute specified
  40. // is a multi-valued attribute, it will append this item into the array of values for that attribute. The structure
  41. // of the object is as follows:
  42. // {
  43. // parent: someItem,
  44. // attribute: "attribute-name-string"
  45. // }
  46. //
  47. // exceptions:
  48. // Throws an exception if *keywordArgs* is a string or a number or
  49. // anything other than a simple anonymous object.
  50. // Throws an exception if the item in parentInfo is not an item from the store
  51. // or if the attribute isn't an attribute name string.
  52. // example:
  53. // | var kermit = store.newItem({name: "Kermit", color:[blue, green]});
  54. var newItem;
  55. throw new Error('Unimplemented API: dojo.data.api.Write.newItem');
  56. return newItem; // item
  57. },
  58. deleteItem: function(/* item */ item){
  59. // summary:
  60. // Deletes an item from the store.
  61. //
  62. // item:
  63. // The item to delete.
  64. //
  65. // exceptions:
  66. // Throws an exception if the argument *item* is not an item
  67. // (if store.isItem(item) returns false).
  68. // example:
  69. // | var success = store.deleteItem(kermit);
  70. throw new Error('Unimplemented API: dojo.data.api.Write.deleteItem');
  71. return false; // boolean
  72. },
  73. setValue: function( /* item */ item,
  74. /* string */ attribute,
  75. /* almost anything */ value){
  76. // summary:
  77. // Sets the value of an attribute on an item.
  78. // Replaces any previous value or values.
  79. //
  80. // item:
  81. // The item to modify.
  82. // attribute:
  83. // The attribute of the item to change represented as a string name.
  84. // value:
  85. // The value to assign to the item.
  86. //
  87. // exceptions:
  88. // Throws an exception if *item* is not an item, or if *attribute*
  89. // is neither an attribute object or a string.
  90. // Throws an exception if *value* is undefined.
  91. // example:
  92. // | var success = store.set(kermit, "color", "green");
  93. throw new Error('Unimplemented API: dojo.data.api.Write.setValue');
  94. return false; // boolean
  95. },
  96. setValues: function(/* item */ item,
  97. /* string */ attribute,
  98. /* array */ values){
  99. // summary:
  100. // Adds each value in the *values* array as a value of the given
  101. // attribute on the given item.
  102. // Replaces any previous value or values.
  103. // Calling store.setValues(x, y, []) (with *values* as an empty array) has
  104. // the same effect as calling store.unsetAttribute(x, y).
  105. //
  106. // item:
  107. // The item to modify.
  108. // attribute:
  109. // The attribute of the item to change represented as a string name.
  110. // values:
  111. // An array of values to assign to the attribute..
  112. //
  113. // exceptions:
  114. // Throws an exception if *values* is not an array, if *item* is not an
  115. // item, or if *attribute* is neither an attribute object or a string.
  116. // example:
  117. // | var success = store.setValues(kermit, "color", ["green", "aqua"]);
  118. // | success = store.setValues(kermit, "color", []);
  119. // | if (success) {assert(!store.hasAttribute(kermit, "color"));}
  120. throw new Error('Unimplemented API: dojo.data.api.Write.setValues');
  121. return false; // boolean
  122. },
  123. unsetAttribute: function( /* item */ item,
  124. /* string */ attribute){
  125. // summary:
  126. // Deletes all the values of an attribute on an item.
  127. //
  128. // item:
  129. // The item to modify.
  130. // attribute:
  131. // The attribute of the item to unset represented as a string.
  132. //
  133. // exceptions:
  134. // Throws an exception if *item* is not an item, or if *attribute*
  135. // is neither an attribute object or a string.
  136. // example:
  137. // | var success = store.unsetAttribute(kermit, "color");
  138. // | if (success) {assert(!store.hasAttribute(kermit, "color"));}
  139. throw new Error('Unimplemented API: dojo.data.api.Write.clear');
  140. return false; // boolean
  141. },
  142. save: function(/* object */ keywordArgs){
  143. // summary:
  144. // Saves to the server all the changes that have been made locally.
  145. // The save operation may take some time and is generally performed
  146. // in an asynchronous fashion. The outcome of the save action is
  147. // is passed into the set of supported callbacks for the save.
  148. //
  149. // keywordArgs:
  150. // {
  151. // onComplete: function
  152. // onError: function
  153. // scope: object
  154. // }
  155. //
  156. // The *onComplete* parameter.
  157. // function();
  158. //
  159. // If an onComplete callback function is provided, the callback function
  160. // will be called just once, after the save has completed. No parameters
  161. // are generally passed to the onComplete.
  162. //
  163. // The *onError* parameter.
  164. // function(errorData);
  165. //
  166. // If an onError callback function is provided, the callback function
  167. // will be called if there is any sort of error while attempting to
  168. // execute the save. The onError function will be based one parameter, the
  169. // error.
  170. //
  171. // The *scope* parameter.
  172. // If a scope object is provided, all of the callback function (
  173. // onComplete, onError, etc) will be invoked in the context of the scope
  174. // object. In the body of the callback function, the value of the "this"
  175. // keyword will be the scope object. If no scope object is provided,
  176. // the callback functions will be called in the context of dojo.global.
  177. // For example, onComplete.call(scope) vs.
  178. // onComplete.call(dojo.global)
  179. //
  180. // returns:
  181. // Nothing. Since the saves are generally asynchronous, there is
  182. // no need to return anything. All results are passed via callbacks.
  183. // example:
  184. // | store.save({onComplete: onSave});
  185. // | store.save({scope: fooObj, onComplete: onSave, onError: saveFailed});
  186. throw new Error('Unimplemented API: dojo.data.api.Write.save');
  187. },
  188. revert: function(){
  189. // summary:
  190. // Discards any unsaved changes.
  191. // description:
  192. // Discards any unsaved changes.
  193. //
  194. // example:
  195. // | var success = store.revert();
  196. throw new Error('Unimplemented API: dojo.data.api.Write.revert');
  197. return false; // boolean
  198. },
  199. isDirty: function(/* item? */ item){
  200. // summary:
  201. // Given an item, isDirty() returns true if the item has been modified
  202. // since the last save(). If isDirty() is called with no *item* argument,
  203. // then this function returns true if any item has been modified since
  204. // the last save().
  205. //
  206. // item:
  207. // The item to check.
  208. //
  209. // exceptions:
  210. // Throws an exception if isDirty() is passed an argument and the
  211. // argument is not an item.
  212. // example:
  213. // | var trueOrFalse = store.isDirty(kermit); // true if kermit is dirty
  214. // | var trueOrFalse = store.isDirty(); // true if any item is dirty
  215. throw new Error('Unimplemented API: dojo.data.api.Write.isDirty');
  216. return false; // boolean
  217. }
  218. });
  219. }