X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2FxosTenant.js;h=10e70e62907f3c7403f41ddd2ca331f64c6ec951;hb=d7020d06768e4cec644a3b26802212de4ba56e65;hp=4c70f704ce694a0555db06f7b184c4f05a5b5c3c;hpb=d6eff632b3c39cf25e1bad326fe9a8a1a6f1dc5d;p=plstackapi.git
diff --git a/planetstack/core/xoslib/static/js/xosTenant.js b/planetstack/core/xoslib/static/js/xosTenant.js
index 4c70f70..10e70e6 100644
--- a/planetstack/core/xoslib/static/js/xosTenant.js
+++ b/planetstack/core/xoslib/static/js/xosTenant.js
@@ -30,7 +30,7 @@ XOSTenantSiteCollection = XOSCollection.extend( {
putToSlice: function(slice) {
slice.attributes.site_allocation = {};
for (index in this.models) {
- model = this.models[index];
+ var model = this.models[index];
slice.attributes.site_allocation[ model.attributes.name ] = model.attributes.allocated;
}
},
@@ -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",
@@ -75,7 +89,12 @@ XOSTenantButtonView = Marionette.ItemView.extend({
saveClicked: function(e) {
model = this.options.linkedView.model;
model.tenantSiteCollection.putToSlice(model);
- this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
+ model.attributes.users = model.usersBuffer;
+
+ e.preventDefault();
+ this.options.linkedView.save();
+ //this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
+ //XOSTenantApp.setDirty(false);
},
});
@@ -95,13 +114,26 @@ 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();
- tenantSummaryClass = XOSDetailView.extend({template: "#xos-detail-template",
+ tenantSummaryClass = XOSTenantSummaryView.extend({template: "#xos-detail-template",
app: XOSTenantApp,
detailFields: ["serviceClass", "default_image", "default_flavor", "network_ports", "mount_data_sets"],
- fieldDisplayNames: {serviceClass: "Service Level", "default_flavor": "Flavor", "default_image": "Image"},
+ fieldDisplayNames: {serviceClass: "Service Level", "default_flavor": "Flavor", "default_image": "Image", "mount_data_sets": "Data Sets"},
+
+ onShow: function() {
+ // the slice selector is in a different table, so make every label cell the maximal width
+ make_same_width("#xos-tenant-view-panel", ".xos-label-cell");
+ },
});
XOSTenantApp.tenantSummaryView = tenantSummaryClass;
@@ -124,6 +156,9 @@ XOSTenantApp.buildViews = function() {
title: "sites",
inputType: {allocated: "spinner"},
noDeleteColumn: true,
+ disablePaginate: true,
+ disableFilter: true,
+ fieldDisplayNames: {"name": "Site"},
});
XOSTenantApp.tenantSiteListView = tenantSiteListClass;
@@ -163,16 +198,24 @@ XOSTenantApp.navToSlice = function(id) {
XOSTenantApp.adjustCollectionField = function(collectionName, id, fieldName, amount) {
model = XOSTenantApp[collectionName].get(id);
model.set(fieldName, Math.max(model.get(fieldName) + amount, 0));
+ XOSTenantApp.setDirty(true);
};
XOSTenantApp.addSlice = function() {
var app=this;
+
+ if (!xos.tenant().current_user_can_create_slice) {
+ window.alert("You do not have sufficient rights to create a slice on your site");
+ return;
+ }
+
model = new xos.slicesPlus.model({site: xos.tenant().current_user_site_id,
- name: xos.tenant().current_user_login_base + "_"});
+ name: xos.tenant().current_user_login_base + "_",
+ creator: xos.tenant().current_user_id});
console.log(model);
var detailView = new XOSTenantApp.tenantAddView({model: model,
- collection: xos.slicesPlus,
- noSubmitButton: true,
+ collection: xos.slicesPlus,
+ noSubmitButton: true,
});
detailView.dialog = $("#tenant-addslice-dialog");
app.tenantAddSliceInterior.show(detailView);
@@ -181,7 +224,7 @@ XOSTenantApp.addSlice = function() {
modal: true,
width: 640,
buttons : {
- "Save" : function() {
+ "Create Slice" : function() {
var addDialog = this;
console.log("SAVE!!!");
detailView.synchronous = true;
@@ -206,11 +249,11 @@ XOSTenantApp.editUsers = function(model) {
modal: true,
width: 640,
buttons : {
- "Save" : function() {
+ "Ok" : 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;
+ model.usersBuffer = user_ids;
$(editDialog).dialog("close");
},
"Cancel" : function() {
@@ -248,6 +291,9 @@ XOSTenantApp.viewSlice = function(model) {
tenantSites = new XOSTenantSiteCollection();
tenantSites.getFromSlice(model);
+ 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 */
+ model.usersOrig = model.attributes.users; /* save an immutable copy that we'll use for username lookups */
+ model.user_namesOrig = model.attributes.user_names;
model.tenantSiteCollection = tenantSites;
XOSTenantApp.tenantSites = tenantSites;
@@ -281,6 +327,9 @@ XOSTenantApp.sanityCheck = function() {
if (xos.tenant().blessed_sites.length == 0) {
errors.push("no blessed sites");
}
+ if (xos.tenant().current_user_site_id == null) {
+ errors.push("current user does not have a site");
+ }
if (errors.length > 0) {
$("#tenantSummary").html("Tenant view sanity check failed
" + errors.join("
"));