workerUrl: '/js/ui/default/staff/offline-db-worker.js'
};
+ // Returns true if the connection was possible
service.connectToWorker = function() {
- if (service.worker) return;
+ if (service.worker) return true;
+ if (service.cannotConnect) return false;
try {
// relative path would be better...
+ throw Error('NOPE');
service.worker = new SharedWorker(service.workerUrl);
} catch (E) {
console.warn('SharedWorker() not supported', E);
service.cannotConnect = true;
- return;
+ return false;
}
service.worker.onerror = function(err) {
});
service.worker.port.start();
+ return true;
}
service.connectToSchemas = function() {
}
service.isCacheGood = function (type) {
+ if (lf.isOffline || !service.connectToWorker()) return $q.when(true);
+
return service.request({
schema: 'cache',
table: 'CacheDate',
service.setStatCatsCache = function (statcats) {
if (lf.isOffline || !statcats ||
- statcats.length === 0 || service.cannotConnect) {
+ statcats.length === 0 || !service.connectToWorker()) {
return $q.when();
}
}
service.getStatCatsCache = function () {
-
return service.request({
schema: 'cache',
table: 'StatCat',
}
service.setSettingsCache = function (settings) {
- if (lf.isOffline || service.cannotConnect) return $q.when();
+ if (lf.isOffline || !service.connectToWorker()) return $q.when();
var rows = [];
angular.forEach(settings, function (val, key) {
}
service.getSettingsCache = function (settings) {
+ if (lf.isOffline || !service.connectToWorker()) return $q.when([]);
var promise;
}
service.destroySettingsCache = function () {
- if (lf.isOffline || service.cannotConnect) return $q.when();
+ if (lf.isOffline || !service.connectToWorker()) return $q.when();
return service.request({
schema: 'cache',
table: 'Setting',
}
service.setListInOfflineCache = function (type, list) {
- if (lf.isOffline || service.cannotConnect) return $q.when();
+ if (lf.isOffline || !service.connectToWorker()) return $q.when();
return service.isCacheGood(type).then(function(good) {
if (good) { return }; // already cached