LP#1768947 Offline DB runs in shared web worker
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / offline.js
index 947aa42..0e990a1 100644 (file)
@@ -17,8 +17,10 @@ function($routeProvider , $locationProvider , $compileProvider) {
      * Route resolvers allow us to run async commands
      * before the page controller is instantiated.
      */
-    var resolver = {delay : ['egCore', 
-        function(egCore) {
+    var resolver = {delay : ['egCore', 'egLovefield',
+        function(egCore, egLovefield) {
+            // the 'offline' schema is only active in the offline UI.
+            egLovefield.activeSchemas.push('offline');
             return egCore.startup.go();
         }
     ]};
@@ -251,8 +253,12 @@ function($routeProvider , $locationProvider , $compileProvider) {
 ])
 
 .controller('OfflineCtrl', 
-           ['$q','$scope','$window','$location','$rootScope','egCore','egLovefield','$routeParams','$timeout','$http','ngToast','egConfirmDialog','egUnloadPrompt',
-    function($q , $scope , $window , $location , $rootScope , egCore , egLovefield , $routeParams , $timeout , $http , ngToast , egConfirmDialog , egUnloadPrompt) {
+           ['$q','$scope','$window','$location','$rootScope','egCore',
+            'egLovefield','$routeParams','$timeout','$http','ngToast',
+            'egConfirmDialog','egUnloadPrompt','egProgressDialog',
+    function($q , $scope , $window , $location , $rootScope , egCore , 
+             egLovefield , $routeParams , $timeout , $http , ngToast , 
+             egConfirmDialog , egUnloadPrompt, egProgressDialog) {
 
         // Immediately redirect if we're really offline
         if (!$window.navigator.onLine) {
@@ -388,28 +394,16 @@ function($routeProvider , $locationProvider , $compileProvider) {
         });
 
         $scope.downloadBlockList = function () {
-            var url = '/standalone/list.txt?ses='
-                + egCore.auth.token()
-                + '&' + new Date().getTime();
-            return $http.get(url).then(
-                function (res) {
-                    if (res.data) {
-                        var lines = res.data.split('\n');
-                        egLovefield.destroyOfflineBlocks().then(function(){
-                            angular.forEach(lines, function (l) {
-                                var parts = l.split(' ');
-                                egLovefield.addOfflineBlock(parts[0], parts[1]);
-                            });
-                            return $q.when();
-                        }).then(function(){
-                            ngToast.create(egCore.strings.OFFLINE_BLOCKLIST_SUCCESS);
-                        });
-                    }
-                },function(){
+            egProgressDialog.open();
+            egLovefield.populateBlockList().then(
+                function(){
+                    ngToast.create(egCore.strings.OFFLINE_BLOCKLIST_SUCCESS);
+                },
+                function(){
                     ngToast.warning(egCore.strings.OFFLINE_BLOCKLIST_FAIL);
                     egCore.audio.play('warning.offline.blocklist_fail');
                 }
-            );
+            )['finally'](egProgressDialog.close);
         }
 
         $scope.createOfflineXactBlob = function () {
@@ -847,7 +841,7 @@ function($routeProvider , $locationProvider , $compileProvider) {
                         return egLovefield.reconstituteList('asva');
                     }).then(function() {
                         angular.forEach(egCore.env.asv.list, function (s) {
-                            s.questions( egCore.env.asva.list.filter( function (a) {
+                            s.questions( egCore.env.asvq.list.filter( function (q) {
                                 return q.survey().id == s.id();
                             }));
                         });