Guest User

Untitled

a guest
Jan 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. define("widget/store/Ref", ["dojo"], function(dojo){
  2. dojo.declare('widget.store.RefWrapper', null, {
  3. refStore: null,
  4. refAttribute: '$ref',
  5.  
  6. constructor: function(options){
  7. // summary:
  8. // A Dojo Data implementation that wraps Dojo stores for reference
  9. // capability.
  10. // options:
  11. // The configuration information to pass into the data store.
  12. // options.objectStore:
  13. // The object store to use as the source provider for this data store
  14. dojo.mixin(this, options);
  15. this.registerStore();
  16. },
  17.  
  18. registerStore: function() {
  19. if(this.refStore.service) {
  20. var service = this.refStore.service;
  21. // summary:
  22. // Creates or gets a constructor for objects from this service
  23. var servicePath = service.servicePath;
  24. widget.store.RefSchema.registerService(this, servicePath);
  25. }
  26. },
  27.  
  28. get: function(id){
  29. // summary:
  30. // Retrieves an object by its identity
  31. // id: Number
  32. // The identity to use to lookup the object
  33. // returns: Object
  34. // The object in the store that matches the given id.
  35. return dojo.when(this.refStore.get(id), dojo.hitch(this, function(result){
  36. if(result.children) {
  37. this.resolveReference(result);
  38. }
  39. return result;
  40. }));
  41.  
  42.  
  43. },
  44. resolveReference: function(object) {
  45. for(var i=0;i<object.children.length;i++) {
  46. if(object.children[i][this.refAttribute]) {
  47. var path = object.children[i][this.refAttribute].replace(/[^\/]*$/,'');
  48. var store = widget.store.RefSchema.services[path];
  49. var id = object.children[i][this.refAttribute].replace(/^\/.*\/([^\/]+)$/,'$1');
  50. dojo.when(store.get(id), dojo.hitch(this, function(result){
  51. if(result.children) {
  52. this.resolveReference(result);
  53. }
  54. object.children[i] = result;
  55. object.children[i]._parent = path + object.id;
  56. }));
  57. }
  58. }
  59. }
  60. });
  61. return widget.store.RefWrapper;
  62. });
  63.  
  64. define("widget/store/RefSchema", ["dojo"], function(dojo){
  65. var jr;
  66. jr = widget.store.RefSchema = {
  67. services:{},
  68. registerService: function(/*Function*/ service, /*String*/ servicePath){
  69. // summary:
  70. // Registers a service for as a JsonRest service, mapping it to a path and schema
  71. // service:
  72. // This is the service to register
  73. // servicePath:
  74. // This is the path that is used for all the ids for the objects returned by service
  75. // schema:
  76. // This is a JSON Schema object to associate with objects returned by this service
  77. servicePath = service.servicePath = servicePath || service.servicePath;
  78. jr.services[servicePath] = service;
  79. }
  80. };
  81. return widget.store.RefSchema;
  82. });
Add Comment
Please, Sign In to add comment