edit users button in tenant view
[plstackapi.git] / planetstack / core / xoslib / static / js / xosTenant.js
index 8bf2442..fc510f3 100644 (file)
@@ -9,7 +9,7 @@ XOSTenantSiteCollection = XOSCollection.extend( {
     modelName: "tenantSite",
     collectionName: "tenantSites",
 
-    updateFromSlice: function(slice) {
+    getFromSlice: function(slice) {
         var tenantSites = [];
         var id = 0;
         for (siteName in slice.attributes.site_allocation) {
@@ -26,8 +26,31 @@ XOSTenantSiteCollection = XOSCollection.extend( {
         }
         this.set(tenantSites);
     },
+
+    putToSlice: function(slice) {
+        slice.attributes.site_allocation = {};
+        for (index in this.models) {
+            model = this.models[index];
+            slice.attributes.site_allocation[ model.attributes.name ] = model.attributes.allocated;
+        }
+    },
 });
 
+XOSEditUsersView = Marionette.ItemView.extend({
+            template: "#tenant-edit-users",
+            viewInitializers: [],
+
+            onShow: function() {
+                _.each(this.viewInitializers, function(initializer) {
+                    initializer();
+                });
+            },
+
+            templateHelpers: function() { return { detailView: this, model: this.model }; },
+
+            });
+
+
 XOSTenantButtonView = Marionette.ItemView.extend({
             template: "#xos-tenant-buttons-template",
 
@@ -46,9 +69,12 @@ XOSTenantButtonView = Marionette.ItemView.extend({
                      },
 
             addUserClicked: function(e) {
+                     XOSTenantApp.editUsers(this.options.linkedView.model);
                      },
 
             saveClicked: function(e) {
+                     model = this.options.linkedView.model;
+                     model.tenantSiteCollection.putToSlice(model);
                      this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
                      },
             });
@@ -66,6 +92,7 @@ XOSTenantApp.addRegions({
     tenantSiteList: "#tenantSiteList",
     tenantButtons: "#tenantButtons",
     tenantAddSliceInterior: "#tenant-addslice-interior",
+    tenantEditUsersInterior: "#tenant-edit-users-interior",
 });
 
 XOSTenantApp.buildViews = function() {
@@ -73,7 +100,9 @@ XOSTenantApp.buildViews = function() {
 \r
      tenantSummaryClass = XOSDetailView.extend({template: "#xos-detail-template",\r
                                                 app: XOSTenantApp,\r
-                                                detailFields: ["serviceClass", "default_image", "default_flavor", "network_ports", "mount_data_sets"]});\r
+                                                detailFields: ["serviceClass", "default_image", "default_flavor", "network_ports", "mount_data_sets"],\r
+                                                fieldDisplayNames: {serviceClass: "Service Level", "default_flavor": "Flavor", "default_image": "Image"},\r
+                                                });\r
 \r
      XOSTenantApp.tenantSummaryView = tenantSummaryClass;\r
 \r
@@ -138,10 +167,14 @@ XOSTenantApp.adjustCollectionField = function(collectionName, id, fieldName, amo
 \r
 XOSTenantApp.addSlice = function() {\r
     var app=this;\r
-    model = new xos.slicesPlus.model({site: xos.tenant().current_user_site_id});\r
+    model = new xos.slicesPlus.model({site: xos.tenant().current_user_site_id,\r
+                                      name: xos.tenant().current_user_login_base + "_"});\r
     console.log(model);\r
-    var detailView = new XOSTenantApp.tenantAddView({model: model, collection: xos.slicesPlus});\r
-    detailView.dialog = $("tenant-addslice-dialog");\r
+    var detailView = new XOSTenantApp.tenantAddView({model: model,\r
+                                                    collection: xos.slicesPlus,\r
+                                                    noSubmitButton: true,\r
+                                                    });\r
+    detailView.dialog = $("#tenant-addslice-dialog");\r
     app.tenantAddSliceInterior.show(detailView);\r
     $("#tenant-addslice-dialog").dialog({\r
        autoOpen: false,
@@ -150,6 +183,7 @@ XOSTenantApp.addSlice = function() {
        buttons : {
             "Save" : function() {
               var addDialog = this;
+              console.log("SAVE!!!");
               detailView.synchronous = true;
               detailView.afterSave = function() { $(addDialog).dialog("close"); XOSTenantApp.navToSlice(detailView.model.id); }
               detailView.save();
@@ -162,6 +196,31 @@ XOSTenantApp.addSlice = function() {
     $("#tenant-addslice-dialog").dialog("open");\r
 };\r
 \r
+XOSTenantApp.editUsers = function(model) {\r
+    var app=this;\r
+    var detailView = new XOSEditUsersView({model: model, collection: xos.slicesPlus});\r
+    detailView.dialog = $("#tenant-edit-users-dialog");\r
+    app.tenantEditUsersInterior.show(detailView);\r
+    $("#tenant-edit-users-dialog").dialog({\r
+       autoOpen: false,
+       modal: true,
+       width: 640,
+       buttons : {
+            "Save" : function() {
+              var editDialog = this;
+              user_ids = all_options($("#tenant-edit-users-dialog").find(".select-picker-to"));
+              user_ids = user_ids.map( function(x) { return parseInt(x,10); } );
+              model.attributes.users = user_ids;
+              $(editDialog).dialog("close");
+            },
+            "Cancel" : function() {
+              $(this).dialog("close");
+            }
+          }
+        });
+    $("#tenant-edit-users-dialog").dialog("open");\r
+};\r
+\r
 XOSTenantApp.deleteSlice = function(model) {\r
     var app=this;\r
     app.deleteDialog(model, function() { console.log("afterDelete"); app.viewSlice(undefined); });\r
@@ -181,13 +240,14 @@ XOSTenantApp.viewSlice = function(model) {
     tenantSummary = new XOSTenantApp.tenantSummaryView({model: model,\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
+                                                                  default_image: make_choices(xos.tenant().blessed_image_names, xos.tenant().blessed_images),\r
+                                                                  default_flavor: make_choices(xos.tenant().blessed_flavor_names, xos.tenant().blessed_flavors),},\r
                                                        });\r
     XOSTenantApp.tenantSummary.show(tenantSummary);\r
 \r
     tenantSites = new XOSTenantSiteCollection();\r
-    tenantSites.updateFromSlice(model);\r
+    tenantSites.getFromSlice(model);\r
+    model.tenantSiteCollection = tenantSites;\r
     XOSTenantApp.tenantSites = tenantSites;\r
 \r
     tenantSiteList = new XOSTenantApp.tenantSiteListView({collection: tenantSites });\r