Permalink
Browse files

Rename @urls => @links to correspond with HAL spec

This also makes it more clear these are links to _other_ resources as
suppose to alternate urls for the object.
  • Loading branch information...
1 parent 66358b3 commit b06986cb15891d83165c7f8daa92a21fe8cb3e8b @bruth bruth committed May 7, 2013
@@ -4,16 +4,17 @@ define [
class Model extends c.Backbone.Model
url: ->
- if @isNew() then super else @urls.self
+ if @isNew() then super else @links.self
constructor: (attrs, options) ->
- @urls = {}
+ @links = {}
super(attrs, options)
parse: (attrs, options) ->
if attrs? and attrs._links?
+ @links = {}
for name, link of attrs._links
- @urls[name] = link.href
+ @links[name] = link.href
delete attrs._links
return attrs
@@ -22,16 +23,17 @@ define [
model: Model
url: ->
- if @isNew() then super else @urls.self
+ if @isNew() then super else @links.self
constructor: (attrs, options) ->
- @urls = {}
+ @links = {}
super(attrs, options)
parse: (attrs, options) ->
if attrs? and attrs._links?
+ @links = {}
for name, link of attrs._links
- @urls[name] = link.href
+ @links[name] = link.href
delete attrs._links
return attrs
@@ -24,7 +24,7 @@ define [
if resp?
# Set the endpoint for related fields
- @fields.url = => @urls.fields
+ @fields.url = => @links.fields
if resp.fields?
@fields.set(resp.fields, options)
@@ -10,38 +10,38 @@ define [
@_cache = {}
distribution: (handler, cache=true) ->
- if not @urls.distribution? then handler()
+ if not @links.distribution? then handler()
if cache and @_cache.distribution?
handler(@_cache.distribution)
else
c.Backbone.ajax
- url: @urls.distribution
+ url: @links.distribution
dataType: 'json'
success: (resp) =>
@_cache.distribution = if cache then resp else null
handler(resp)
return
stats: (handler, cache=true) ->
- if not @urls.stats? then handler()
+ if not @links.stats? then handler()
if cache and @_cache.stats?
handler(@_cache.stats)
else
c.Backbone.ajax
- url: @urls.stats
+ url: @links.stats
dataType: 'json'
success: (resp) =>
@_cache.stats = if cache then resp else null
handler(resp)
return
values: (handler, cache=true) ->
- if not @urls.values? then handler()
+ if not @links.values? then handler()
if cache and @_cache.values?
handler(@_cache.values)
else
c.Backbone.ajax
- url: @urls.values
+ url: @links.values
dataType: 'json'
success: (resp) =>
@_cache.values = if cache then resp else null
@@ -57,7 +57,7 @@ define [
@[key].show view
# Only represent for fields that support distributions
- if @options.showChart and @model.urls.distribution?
+ if @options.showChart and @model.links.distribution?
chart = new charts.FieldChart
model: @model
context: @context
@@ -107,7 +107,7 @@ define [
field: model.id
concept: context.get 'concept'
- if not @fieldChartIndex? and model.urls.distribution?
+ if not @fieldChartIndex? and model.links.distribution?
@fieldChartIndex = index
options.showChart = true

0 comments on commit b06986c

Please sign in to comment.