Skip to content

Commit 354374c

Browse files
committed
feat(hal browser): use name and title from self link when not specified in embedded resource
1 parent 915a7ee commit 354374c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

vendor/hal-browser/js/hal/resource.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ HAL.Models.Resource = Backbone.Model.extend({
22
initialize: function(representation) {
33
representation = representation || {};
44
this.links = representation._links;
5-
this.title = representation.title;
6-
this.name = representation.name;
5+
this.title = this.buildTitle(representation);
6+
this.name = this.buildName(representation);
77
if(representation._embedded !== undefined) {
88
this.embeddedResources = this.buildEmbeddedResources(representation._embedded);
99
}
@@ -12,6 +12,20 @@ HAL.Models.Resource = Backbone.Model.extend({
1212
this.unset('_links', { silent: true });
1313
},
1414

15+
buildName: function(representation) {
16+
return representation.name ||
17+
(representation._links
18+
&& representation._links.self
19+
&& representation._links.self.name);
20+
},
21+
22+
buildTitle: function(representation) {
23+
return representation.title ||
24+
(representation._links
25+
&& representation._links.self
26+
&& representation._links.self.title);
27+
},
28+
1529
buildEmbeddedResources: function(embeddedResources) {
1630
var result = {};
1731
_.each(embeddedResources, function(obj, rel) {

0 commit comments

Comments
 (0)