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