make save button green when slice is dirty
[plstackapi.git] / planetstack / core / xoslib / static / js / xosTenant.js
index 929552c..10e70e6 100644 (file)
@@ -50,6 +50,20 @@ XOSEditUsersView = Marionette.ItemView.extend({
 
             });
 
+XOSTenantSummaryView = XOSDetailView.extend({
+            events: {"change": "onChange"},
+
+            onChange: function(e) {
+                XOSTenantApp.setDirty(true);
+            },
+
+            saveSuccess: function() {
+                console.log("saveSuccess!");
+                XOSTenantApp.setDirty(false);
+            },
+
+            });
+
 
 XOSTenantButtonView = Marionette.ItemView.extend({
             template: "#xos-tenant-buttons-template",
@@ -76,7 +90,11 @@ XOSTenantButtonView = Marionette.ItemView.extend({
                      model = this.options.linkedView.model;
                      model.tenantSiteCollection.putToSlice(model);
                      model.attributes.users = model.usersBuffer;
-                     this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
+
+                     e.preventDefault();
+                     this.options.linkedView.save();
+                     //this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
+                     //XOSTenantApp.setDirty(false);
                      },
             });
 
@@ -96,10 +114,18 @@ XOSTenantApp.addRegions({
     tenantEditUsersInterior: "#tenant-edit-users-interior",
 });
 
+XOSTenantApp.setDirty = function(dirty) {
+    if (dirty) {
+        $("button.btn-tenant-save").addClass("btn-success");
+    } else {
+        $("button.btn-tenant-save").removeClass("btn-success");
+    }
+};
+
 XOSTenantApp.buildViews = function() {
      XOSTenantApp.tenantSites = new XOSTenantSiteCollection();\r
 \r
-     tenantSummaryClass = XOSDetailView.extend({template: "#xos-detail-template",\r
+     tenantSummaryClass = XOSTenantSummaryView.extend({template: "#xos-detail-template",\r
                                                 app: XOSTenantApp,\r
                                                 detailFields: ["serviceClass", "default_image", "default_flavor", "network_ports", "mount_data_sets"],\r
                                                 fieldDisplayNames: {serviceClass: "Service Level", "default_flavor": "Flavor", "default_image": "Image", "mount_data_sets": "Data Sets"},\r
@@ -172,6 +198,7 @@ XOSTenantApp.navToSlice = function(id) {
 XOSTenantApp.adjustCollectionField = function(collectionName, id, fieldName, amount) {\r
     model = XOSTenantApp[collectionName].get(id);\r
     model.set(fieldName, Math.max(model.get(fieldName) + amount, 0));\r
+    XOSTenantApp.setDirty(true);\r
 };\r
 \r
 XOSTenantApp.addSlice = function() {\r
@@ -183,11 +210,12 @@ XOSTenantApp.addSlice = function() {
     }\r
 \r
     model = new xos.slicesPlus.model({site: xos.tenant().current_user_site_id,\r
-                                      name: xos.tenant().current_user_login_base + "_"});\r
+                                      name: xos.tenant().current_user_login_base + "_",\r
+                                      creator: xos.tenant().current_user_id});\r
     console.log(model);\r
     var detailView = new XOSTenantApp.tenantAddView({model: model,\r
-                                                    collection: xos.slicesPlus,\r
-                                                    noSubmitButton: true,\r
+                                                     collection: xos.slicesPlus,\r
+                                                     noSubmitButton: true,\r
                                                     });\r
     detailView.dialog = $("#tenant-addslice-dialog");\r
     app.tenantAddSliceInterior.show(detailView);\r
@@ -264,6 +292,8 @@ XOSTenantApp.viewSlice = function(model) {
         tenantSites = new XOSTenantSiteCollection();\r
         tenantSites.getFromSlice(model);\r
         model.usersBuffer = model.attributes.users; /* save a copy of 'users' that we can edit. This prevents another view (developer) from overwriting our copy with a fetch from the server */\r
+        model.usersOrig = model.attributes.users;   /* save an immutable copy that we'll use for username lookups */\r
+        model.user_namesOrig = model.attributes.user_names;\r
         model.tenantSiteCollection = tenantSites;\r
         XOSTenantApp.tenantSites = tenantSites;\r
 \r
@@ -297,6 +327,9 @@ XOSTenantApp.sanityCheck = function() {
     if (xos.tenant().blessed_sites.length == 0) {\r
         errors.push("no blessed sites");\r
     }\r
+    if (xos.tenant().current_user_site_id == null) {\r
+        errors.push("current user does not have a site");\r
+    }\r
 \r
     if (errors.length > 0) {\r
          $("#tenantSummary").html("Tenant view sanity check failed<br>" + errors.join("<br>"));\r