2014-04-11 17:19:17 -04:00
|
|
|
CocoClass = require 'lib/CocoClass'
|
|
|
|
|
|
|
|
namesCache = {}
|
|
|
|
|
|
|
|
class NameLoader extends CocoClass
|
|
|
|
loadNames: (ids) ->
|
|
|
|
toLoad = (id for id in ids when not namesCache[id])
|
|
|
|
return false unless toLoad.length
|
2014-04-13 13:29:43 -04:00
|
|
|
jqxhrOptions = {
|
2014-04-16 11:03:41 -04:00
|
|
|
url: '/db/user/x/names',
|
|
|
|
type:'POST',
|
|
|
|
data:{ids:toLoad},
|
|
|
|
success: @loadedNames
|
2014-04-13 13:29:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return jqxhrOptions
|
|
|
|
|
2014-04-11 17:19:17 -04:00
|
|
|
loadedNames: (newNames) =>
|
|
|
|
_.extend namesCache, newNames
|
|
|
|
|
2014-04-18 14:17:13 -04:00
|
|
|
getName: (id) -> namesCache[id].name
|
2014-04-11 17:19:17 -04:00
|
|
|
|
|
|
|
module.exports = new NameLoader()
|