Sha256: 0b9f568b8f920088e9ba5f491f78b5232c06d6f88407374abda21792a89c873f

Contents?: true

Size: 1.56 KB

Versions: 74

Compression:

Stored size: 1.56 KB

Contents

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

  buildName: function(representation) {
    return representation.name ||
      (representation._links
        && representation._links.self
        && representation._links.self.name);
  },

  buildTitle: function(representation) {
    return representation.title ||
      (representation._links
        && representation._links.self
        && representation._links.self.title);
  },

  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

74 entries across 74 versions & 1 rubygems

Version Path
pact_broker-2.53.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.52.2 vendor/hal-browser/js/hal/resource.js
pact_broker-2.52.1 vendor/hal-browser/js/hal/resource.js
pact_broker-2.52.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.51.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.50.1 vendor/hal-browser/js/hal/resource.js
pact_broker-2.50.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.49.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.48.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.47.1 vendor/hal-browser/js/hal/resource.js
pact_broker-2.47.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.46.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.45.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.44.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.43.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.42.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.41.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.40.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.39.0 vendor/hal-browser/js/hal/resource.js
pact_broker-2.38.1 vendor/hal-browser/js/hal/resource.js