var service = {};
+ // org unit settings cache.
+ // This allows the caller to avoid local caches
+ service.cachedSettings = {};
+
service.get = function(node_or_id) {
if (typeof node_or_id == 'object')
return node_or_id;
service.settings = function(names, ou_id) {
var deferred = $q.defer();
ou_id = ou_id || egAuth.user().ws_ou();
+ var here = (ou_id == egAuth.user().ws_ou());
+
+ // allow non-array
+ if (!angular.isArray(names)) names = [names];
+
+ if (here) {
+ // only cache org settings retrieved for the current
+ // workstation org unit.
+ var newNames = [];
+ angular.forEach(names, function(name) {
+ if (!angular.isDefined(service.cachedSettings[name]))
+ newNames.push(name)
+ });
+
+ // only retrieve uncached values
+ names = newNames;
+ if (names.length == 0)
+ return $q.when(service.cachedSettings);
+ }
+
egNet.request(
'open-ils.actor',
'open-ils.actor.ou_setting.ancestor_default.batch',
).then(function(blob) {
var settings = {};
angular.forEach(blob, function(val, key) {
- // val is either null or a structure containing
- // the value
- if (val) { settings[key] = val.value }
+ // val is either null or a structure containing the value
+ settings[key] = val ? val.value : null;
+ if (here) service.cachedSettings[key] = settings[key];
});
- deferred.resolve(settings);
+
+ // resolve with cached settings if 'here', since 'settings'
+ // will only contain settings we had to retrieve
+ deferred.resolve(here ? service.cachedSettings : settings);
});
return deferred.promise;
}