fetchRelatives recursively handles arrays
This commit is contained in:
parent
471fb03bb2
commit
797a4f210a
2 changed files with 11 additions and 4 deletions
|
@ -110,12 +110,12 @@ Metamaps.Listeners = {
|
||||||
var node = nodes[nodes.length - 1]
|
var node = nodes[nodes.length - 1]
|
||||||
if (opts.center && opts.reveal) {
|
if (opts.center && opts.reveal) {
|
||||||
Metamaps.Topic.centerOn(node.id, function() {
|
Metamaps.Topic.centerOn(node.id, function() {
|
||||||
Metamaps.Topic.fetchRelatives(node)
|
Metamaps.Topic.fetchRelatives(nodes)
|
||||||
})
|
})
|
||||||
} else if (opts.center) {
|
} else if (opts.center) {
|
||||||
Metamaps.Topic.centerOn(node.id)
|
Metamaps.Topic.centerOn(node.id)
|
||||||
} else if (opts.reveal) {
|
} else if (opts.reveal) {
|
||||||
Metamaps.Topic.fetchRelatives(node)
|
Metamaps.Topic.fetchRelatives(nodes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}; // end Metamaps.Listeners
|
}; // end Metamaps.Listeners
|
||||||
|
|
|
@ -111,7 +111,11 @@ Metamaps.Topic = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fetchRelatives: function (node, metacode_id) {
|
fetchRelatives: function (nodes, metacode_id) {
|
||||||
|
var self = this
|
||||||
|
|
||||||
|
var node = $.isArray(nodes) ? nodes[0] : nodes
|
||||||
|
|
||||||
var topics = Metamaps.Topics.map(function (t) { return t.id })
|
var topics = Metamaps.Topics.map(function (t) { return t.id })
|
||||||
var topics_string = topics.join()
|
var topics_string = topics.join()
|
||||||
|
|
||||||
|
@ -162,13 +166,16 @@ Metamaps.Topic = {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
if ($.isArray(nodes) && nodes.length > 1) {
|
||||||
|
self.fetchRelatives(nodes.slice(1), metacode_id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var paramsString = metacode_id ? 'metacode=' + metacode_id + '&' : ''
|
var paramsString = metacode_id ? 'metacode=' + metacode_id + '&' : ''
|
||||||
paramsString += 'network=' + topics_string + '&creators=' + creators_string
|
paramsString += 'network=' + topics_string + '&creators=' + creators_string
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'Get',
|
type: 'GET',
|
||||||
url: '/topics/' + topic.id + '/relatives.json?' + paramsString,
|
url: '/topics/' + topic.id + '/relatives.json?' + paramsString,
|
||||||
success: successCallback,
|
success: successCallback,
|
||||||
error: function () {}
|
error: function () {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue