From 354374cd686a4e59ebc30c2e0449b15c72061158 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 15 Sep 2017 16:51:15 +1000 Subject: [PATCH] feat(hal browser): use name and title from self link when not specified in embedded resource --- vendor/hal-browser/js/hal/resource.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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) {