add sanity check; add default_flavors and default_images
Scott Baker [Mon, 12 Jan 2015 21:37:31 +0000 (13:37 -0800)]
planetstack/core/xoslib/static/js/xosTenant.js

index 5a548ed..8bf2442 100644 (file)
@@ -73,7 +73,7 @@ XOSTenantApp.buildViews = function() {
 \r
      tenantSummaryClass = XOSDetailView.extend({template: "#xos-detail-template",\r
                                                 app: XOSTenantApp,\r
-                                                detailFields: ["serviceClass", "image_preference", "network_ports", "mount_data_sets"]});\r
+                                                detailFields: ["serviceClass", "default_image", "default_flavor", "network_ports", "mount_data_sets"]});\r
 \r
      XOSTenantApp.tenantSummaryView = tenantSummaryClass;\r
 \r
@@ -117,6 +117,12 @@ make_choices = function(list_of_names, list_of_values) {
             displayName = list_of_names[index];\r
             result.push( [displayName, displayName] );\r
         }\r
+    } else {\r
+        for (index in list_of_names) {\r
+            displayName = list_of_names[index];\r
+            id = list_of_values[index];\r
+            result.push( [displayName, id] );\r
+        }\r
     }\r
     return result;\r
 };\r
@@ -173,8 +179,10 @@ XOSTenantApp.viewSlice = function(model) {
     XOSTenantApp.tenantSliceSelector.show(sliceSelector);\r
 \r
     tenantSummary = new XOSTenantApp.tenantSummaryView({model: model,\r
-                                                        choices: {mount_data_sets: make_choices(xos.tenantview.models[0].attributes.public_volume_names, null),\r
-                                                                  image_preference: make_choices(xos.tenantview.models[0].attributes.blessed_image_names, null)},\r
+                                                        choices: {mount_data_sets: make_choices(xos.tenant().public_volume_names, null),\r
+                                                                  serviceClass: make_choices(xos.tenant().blessed_service_class_names, xos.tenant().blessed_service_classes),\r
+                                                                  default_image: make_choices(xos.tenant().blessed_image_names, xos.tenant().blessed_image_ids),\r
+                                                                  default_flavor: make_choices(xos.tenant().blessed_flavor_names, xos.tenant().blessed_flavor_ids),},\r
                                                        });\r
     XOSTenantApp.tenantSummary.show(tenantSummary);\r
 \r
@@ -190,9 +198,27 @@ XOSTenantApp.viewSlice = function(model) {
                                                                 linkedView: tenantSummary } ) );\r
 };\r
 \r
-XOSTenantApp.startNavigation = function() {\r
-    Backbone.history.start();\r
-    XOSTenantApp.navigationStarted = true;\r
+XOSTenantApp.sanityCheck = function() {\r
+    errors = [];\r
+    if (xos.tenant().blessed_service_classes.length == 0) {\r
+        errors.push("no blessed service classes");\r
+    }\r
+    if (xos.tenant().blessed_flavors.length == 0) {\r
+        errors.push("no blessed flavors");\r
+    }\r
+    if (xos.tenant().blessed_images.length == 0) {\r
+        errors.push("no blessed images");\r
+    }\r
+    if (xos.tenant().blessed_sites.length == 0) {\r
+        errors.push("no blessed sites");\r
+    }\r
+\r
+    if (errors.length > 0) {\r
+         $("#tenantSummary").html("Tenant view sanity check failed<br>" + errors.join("<br>"));\r
+         return false;\r
+    }\r
+\r
+    return true;\r
 }\r
 \r
 XOSTenantApp.collectionLoadChange = function() {\r
@@ -200,7 +226,9 @@ XOSTenantApp.collectionLoadChange = function() {
 \r
     if (!XOSTenantApp.navigationStarted) {\r
         if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {\r
-            XOSTenantApp.viewSlice(undefined);\r
+            if (XOSTenantApp.sanityCheck()) {\r
+                XOSTenantApp.viewSlice(undefined);\r
+            }\r
         } else {\r
             $("#tenantSummary").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");\r
             $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});\r