Identity.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.Identity"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojo.data.api.Identity"] = true;
  8. dojo.provide("dojo.data.api.Identity");
  9. dojo.require("dojo.data.api.Read");
  10. dojo.declare("dojo.data.api.Identity", dojo.data.api.Read, {
  11. // summary:
  12. // This is an abstract API that data provider implementations conform to.
  13. // This file defines methods signatures and intentionally leaves all the
  14. // methods 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.Identity': true
  21. };
  22. },
  23. getIdentity: function(/* item */ item){
  24. // summary:
  25. // Returns a unique identifier for an item. The return value will be
  26. // either a string or something that has a toString() method (such as,
  27. // for example, a dojox.uuid.Uuid object).
  28. // item:
  29. // The item from the store from which to obtain its identifier.
  30. // exceptions:
  31. // Conforming implementations may throw an exception or return null if
  32. // item is not an item.
  33. // example:
  34. // | var itemId = store.getIdentity(kermit);
  35. // | assert(kermit === store.findByIdentity(store.getIdentity(kermit)));
  36. throw new Error('Unimplemented API: dojo.data.api.Identity.getIdentity');
  37. var itemIdentityString = null;
  38. return itemIdentityString; // string
  39. },
  40. getIdentityAttributes: function(/* item */ item){
  41. // summary:
  42. // Returns an array of attribute names that are used to generate the identity.
  43. // For most stores, this is a single attribute, but for some complex stores
  44. // such as RDB backed stores that use compound (multi-attribute) identifiers
  45. // it can be more than one. If the identity is not composed of attributes
  46. // on the item, it will return null. This function is intended to identify
  47. // the attributes that comprise the identity so that so that during a render
  48. // of all attributes, the UI can hide the the identity information if it
  49. // chooses.
  50. // item:
  51. // The item from the store from which to obtain the array of public attributes that
  52. // compose the identifier, if any.
  53. // example:
  54. // | var itemId = store.getIdentity(kermit);
  55. // | var identifiers = store.getIdentityAttributes(itemId);
  56. // | assert(typeof identifiers === "array" || identifiers === null);
  57. throw new Error('Unimplemented API: dojo.data.api.Identity.getIdentityAttributes');
  58. return null; // string
  59. },
  60. fetchItemByIdentity: function(/* object */ keywordArgs){
  61. // summary:
  62. // Given the identity of an item, this method returns the item that has
  63. // that identity through the onItem callback. Conforming implementations
  64. // should return null if there is no item with the given identity.
  65. // Implementations of fetchItemByIdentity() may sometimes return an item
  66. // from a local cache and may sometimes fetch an item from a remote server,
  67. //
  68. // keywordArgs:
  69. // An anonymous object that defines the item to locate and callbacks to invoke when the
  70. // item has been located and load has completed. The format of the object is as follows:
  71. // {
  72. // identity: string|object,
  73. // onItem: Function,
  74. // onError: Function,
  75. // scope: object
  76. // }
  77. // The *identity* parameter.
  78. // The identity parameter is the identity of the item you wish to locate and load
  79. // This attribute is required. It should be a string or an object that toString()
  80. // can be called on.
  81. //
  82. // The *onItem* parameter.
  83. // Function(item)
  84. // The onItem parameter is the callback to invoke when the item has been loaded. It takes only one
  85. // parameter, the item located, or null if none found.
  86. //
  87. // The *onError* parameter.
  88. // Function(error)
  89. // The onError parameter is the callback to invoke when the item load encountered an error. It takes only one
  90. // parameter, the error object
  91. //
  92. // The *scope* parameter.
  93. // If a scope object is provided, all of the callback functions (onItem,
  94. // onError, etc) will be invoked in the context of the scope object.
  95. // In the body of the callback function, the value of the "this"
  96. // keyword will be the scope object. If no scope object is provided,
  97. // the callback functions will be called in the context of dojo.global.
  98. // For example, onItem.call(scope, item, request) vs.
  99. // onItem.call(dojo.global, item, request)
  100. if(!this.isItemLoaded(keywordArgs.item)){
  101. throw new Error('Unimplemented API: dojo.data.api.Identity.fetchItemByIdentity');
  102. }
  103. }
  104. });
  105. }