Sha256: ee64ef5cbe84995eb41c182629829dc1f8a07b9a2f803b19c46941401e580fac

Contents?: true

Size: 1.13 KB

Versions: 43

Compression:

Stored size: 1.13 KB

Contents

HAL.Models.Resource = Backbone.Model.extend({
  initialize: function(representation) {
    representation = representation || {};
    this.links = representation._links;
    this.title = representation.title;
    if(representation._embedded !== undefined) {
      this.embeddedResources = this.buildEmbeddedResources(representation._embedded);
    }
    this.set(representation);
    this.unset('_embedded', { silent: true });
    this.unset('_links', { silent: true });
  },

  buildEmbeddedResources: function(embeddedResources) {
    var result = {};
    _.each(embeddedResources, function(obj, rel) {
      if($.isArray(obj)) {
        var arr = [];
        _.each(obj, function(resource, i) {
          var newResource = new HAL.Models.Resource(resource);
          newResource.identifier = rel + '[' + i + ']';
          newResource.embed_rel = rel;
          arr.push(newResource);
        });
        result[rel] = arr;
      } else {
        var newResource = new HAL.Models.Resource(obj);
        newResource.identifier = rel;
        newResource.embed_rel = rel;
        result[rel] = newResource;
      }
    });
    return result;
  }
});

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
pact_broker-2.3.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.2.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.1.1 vendor/hal-browser/js/hal/resource.js
pact_broker-2.1.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.5 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.4 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.3 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.2 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.1 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.0.beta.8 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.0.beta.7 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.0.beta.6 vendor/hal-browser/js/hal/resource.js
pact_broker-1.18.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.0.beta.5 vendor/hal-browser/js/hal/resource.js
pact_broker-1.18.0.beta.1 vendor/hal-browser/js/hal/resource.js
pact_broker-1.17.2 vendor/hal-browser/js/hal/resource.js
pact_broker-1.17.1 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.0.beta.4 vendor/hal-browser/js/hal/resource.js
pact_broker-2.0.0.beta.3 vendor/hal-browser/js/hal/resource.js