diff --git a/vendor/hal-browser/js/hal/resource.js b/vendor/hal-browser/js/hal/resource.js index 941f747fe..61331858f 100644 --- a/vendor/hal-browser/js/hal/resource.js +++ b/vendor/hal-browser/js/hal/resource.js @@ -2,8 +2,8 @@ HAL.Models.Resource = Backbone.Model.extend({ initialize: function(representation) { representation = representation || {}; this.links = representation._links; - this.title = representation.title; - this.name = representation.name; + this.title = this.buildTitle(representation); + this.name = this.buildName(representation); if(representation._embedded !== undefined) { this.embeddedResources = this.buildEmbeddedResources(representation._embedded); } @@ -12,6 +12,20 @@ HAL.Models.Resource = Backbone.Model.extend({ 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) {