Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define("widget/store/Ref", ["dojo"], function(dojo){
- dojo.declare('widget.store.RefWrapper', null, {
- refStore: null,
- refAttribute: '$ref',
- constructor: function(options){
- // summary:
- // A Dojo Data implementation that wraps Dojo stores for reference
- // capability.
- // options:
- // The configuration information to pass into the data store.
- // options.objectStore:
- // The object store to use as the source provider for this data store
- dojo.mixin(this, options);
- this.registerStore();
- },
- registerStore: function() {
- if(this.refStore.service) {
- var service = this.refStore.service;
- // summary:
- // Creates or gets a constructor for objects from this service
- var servicePath = service.servicePath;
- widget.store.RefSchema.registerService(this, servicePath);
- }
- },
- get: function(id){
- // summary:
- // Retrieves an object by its identity
- // id: Number
- // The identity to use to lookup the object
- // returns: Object
- // The object in the store that matches the given id.
- return dojo.when(this.refStore.get(id), dojo.hitch(this, function(result){
- if(result.children) {
- this.resolveReference(result);
- }
- return result;
- }));
- },
- resolveReference: function(object) {
- for(var i=0;i<object.children.length;i++) {
- if(object.children[i][this.refAttribute]) {
- var path = object.children[i][this.refAttribute].replace(/[^\/]*$/,'');
- var store = widget.store.RefSchema.services[path];
- var id = object.children[i][this.refAttribute].replace(/^\/.*\/([^\/]+)$/,'$1');
- dojo.when(store.get(id), dojo.hitch(this, function(result){
- if(result.children) {
- this.resolveReference(result);
- }
- object.children[i] = result;
- object.children[i]._parent = path + object.id;
- }));
- }
- }
- }
- });
- return widget.store.RefWrapper;
- });
- define("widget/store/RefSchema", ["dojo"], function(dojo){
- var jr;
- jr = widget.store.RefSchema = {
- services:{},
- registerService: function(/*Function*/ service, /*String*/ servicePath){
- // summary:
- // Registers a service for as a JsonRest service, mapping it to a path and schema
- // service:
- // This is the service to register
- // servicePath:
- // This is the path that is used for all the ids for the objects returned by service
- // schema:
- // This is a JSON Schema object to associate with objects returned by this service
- servicePath = service.servicePath = servicePath || service.servicePath;
- jr.services[servicePath] = service;
- }
- };
- return widget.store.RefSchema;
- });
Add Comment
Please, Sign In to add comment