Browse Source

CategoryIndex: _loadChildrenCategories: callback when all finished

master
parent
commit
f0dc49c7e9
  1. 1
      package.json
  2. 47
      src/CategoryIndex.js

1
package.json

@ -7,6 +7,7 @@
"author": "Stephan Bösch-Plepelits <skunk@xover.mud.at>",
"license": "GPL-3.0",
"dependencies": {
"async": "^2.5.0",
"font-awesome": "^4.7.0",
"i18next-client": "^1.11.4",
"ip-location": "^1.0.1",

47
src/CategoryIndex.js

@ -1,3 +1,4 @@
var async = require('async')
var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader')
var CategoryBase = require('./CategoryBase')
@ -21,7 +22,9 @@ CategoryIndex.prototype.open = function () {
return
}
this._loadChildrenCategories()
this._loadChildrenCategories(function (err) {
console.log(err)
})
}
CategoryIndex.prototype.recalc = function () {
@ -32,35 +35,43 @@ CategoryIndex.prototype.recalc = function () {
}
}
CategoryIndex.prototype._loadChildrenCategories = function () {
CategoryIndex.prototype._loadChildrenCategories = function (callback) {
this.childrenCategories = {}
for (var i = 0; i < this.data.subCategories.length; i++) {
var data = this.data.subCategories[i]
var childDom = document.createElement('div')
childDom.className = 'categoryWrapper'
this.domContent.appendChild(childDom)
this.childrenDoms[data.id] = childDom
this.childrenCategories[data.id] = null
if ('type' in data) {
OpenStreetBrowserLoader.getCategoryFromData(data.id, data, this._loadChildCategory.bind(this))
} else {
OpenStreetBrowserLoader.getCategory(data.id, this._loadChildCategory.bind(this))
async.forEach(this.data.subCategories,
function (data, callback) {
var childDom = document.createElement('div')
childDom.className = 'categoryWrapper'
this.domContent.appendChild(childDom)
this.childrenDoms[data.id] = childDom
this.childrenCategories[data.id] = null
if ('type' in data) {
OpenStreetBrowserLoader.getCategoryFromData(data.id, data, this._loadChildCategory.bind(this, callback))
} else {
OpenStreetBrowserLoader.getCategory(data.id, this._loadChildCategory.bind(this, callback))
}
}.bind(this),
function (err) {
if (callback) {
callback(err)
}
}
}
)
}
CategoryIndex.prototype._loadChildCategory = function (err, category) {
CategoryIndex.prototype._loadChildCategory = function (callback, err, category) {
if (err) {
return
return callback(err)
}
this.childrenCategories[category.id] = category
category.setParent(this)
category.setParentDom(this.childrenDoms[category.id])
callback(err, category)
}
CategoryIndex.prototype.close = function () {

Loading…
Cancel
Save