* returns, a pending-calls counter is decremented. Once
* it reaches zero, the promise returned by load() /
* loadAll() is resolved.
+ *
+ * App-supplied generic load commands are pushed onto the
+ * service.loaders array. Each item in the array is a
+ * function which returns a promise. Note that loaders in this
+ * array cannot have any dependencies on other startup loaders,
+ * since there is no guarantee which will complete first.
+ *
+ * egEnv.loaders.push(function() {
+ * return egNet.request(...)
+ * .then(function(stuff) { console.log('stuff!') });
+ *
+ * Data requets that have requirements loaded by startup
+ * should run after startup directly in the application.
+ *
+ * TODO: marry egStartup and egEnv?
+ * TODO: support a post-org loader so that loaders can be
+ * added which rely on the org tree?
*/
angular.module('egCoreMod')
// env fetcher
.factory('egEnv',
- ['$q', 'egEnvCache', 'egNet', 'egAuth', 'egPCRUD',
+['$q', 'egEnvCache', 'egNet', 'egAuth', 'egPCRUD',
function($q, egEnvCache, egNet, egAuth, egPCRUD) {
var service = {
+ loaders : [],
get : function(class_) {
return egEnvCache.get(class_);
}
/* returns a promise, loads all of the specified classes */
service.load = function(classes) {
- if (!classes) classes = Object.keys(this.loaders);
+ if (!classes) classes = Object.keys(this.classLoaders);
this.deferred = $q.defer();
- this.in_flight = classes.length;
+ this.in_flight = classes.length + this.loaders.length;
angular.forEach(classes, function(cls) {
- service.loaders[cls]().then(function(){service.onload()});
+ service.classLoaders[cls]().then(function(){service.onload()});
+ });
+ angular.forEach(this.loaders, function(loader) {
+ loader().then(function(){service.onload()});
});
return this.deferred.promise;
};
/* Classes (by hint) to load, their loading routines,
* and their result mungers */
- service.loaders = {
+ service.classLoaders = {
aou : function() {
return egPCRUD.search('aou', {parent_ou : null},
}
// org unit settings, blah, blah
- }
+ };
return service;
}]);