Write.js 7.9 KB

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