progress bar on startup, and make sure stuff is loaded before we display it
[plstackapi.git] / planetstack / core / xoslib / static / js / xosAdminSite.js
index 99cf851..212c1b4 100644 (file)
@@ -134,6 +134,24 @@ XOSAdminApp.rewriteLinks = function () {
     });\r
 };\r
 \r
+XOSAdminApp.startNavigation = function() {\r
+    Backbone.history.start();\r
+    XOSAdminApp.navigationStarted = true;\r
+}\r
+\r
+XOSAdminApp.collectionLoadChange = function() {\r
+    stats = xos.getCollectionStatus();\r
+\r
+    if (!XOSAdminApp.navigationStarted) {\r
+        if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {\r
+            XOSAdminApp.startNavigation();\r
+        } else {\r
+            $("#detail").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");\r
+            $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});\r
+        }\r
+    }\r
+};\r
+\r
 XOSAdminApp.on("start", function() {\r
      XOSAdminApp.buildViews();
 
@@ -143,10 +161,11 @@ XOSAdminApp.on("start", function() {
 
      XOSAdminApp.rewriteLinks();
 
-     if (Backbone.history) {
-         console.log("history start");
-         Backbone.history.start();
-     }
+     // fire it once to initially show the progress bar
+     XOSAdminApp.collectionLoadChange();
+
+     // fire it each time the collection load status is updated
+     Backbone.on("xoslib:collectionLoadChange", XOSAdminApp.collectionLoadChange);
 });
 
 $(document).ready(function(){