2014-11-28 20:49:41 -05:00
|
|
|
CocoClass = require 'core/CocoClass'
|
2014-04-11 17:19:17 -04:00
|
|
|
|
|
|
|
namesCache = {}
|
|
|
|
|
|
|
|
class NameLoader extends CocoClass
|
|
|
|
loadNames: (ids) ->
|
2014-06-24 16:41:55 -04:00
|
|
|
toLoad = _.uniq (id for id in ids when not namesCache[id])
|
2014-04-11 17:19:17 -04:00
|
|
|
return false unless toLoad.length
|
2014-04-13 13:29:43 -04:00
|
|
|
jqxhrOptions = {
|
2014-06-30 22:16:26 -04:00
|
|
|
url: '/db/user/x/names',
|
|
|
|
type: 'POST',
|
|
|
|
data: {ids: toLoad},
|
2014-04-16 11:03:41 -04:00
|
|
|
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-06-30 22:16:26 -04:00
|
|
|
|
2014-06-24 17:25:01 -04:00
|
|
|
getName: (id) -> namesCache[id]?.name or id
|
2014-04-11 17:19:17 -04:00
|
|
|
|
|
|
|
module.exports = new NameLoader()
|