Write.js 7.9 KB

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