X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2FxosTenant.js;h=286537db1138a953573bb93393594dd64af662fd;hb=c2d7c700233884cf21df441192598df8347994ea;hp=cb816a860fb28c138ee241410ea02832467c80f0;hpb=462341a013fac9032894eb2e56f5a36dfa4fd468;p=plstackapi.git diff --git a/planetstack/core/xoslib/static/js/xosTenant.js b/planetstack/core/xoslib/static/js/xosTenant.js index cb816a8..286537d 100644 --- a/planetstack/core/xoslib/static/js/xosTenant.js +++ b/planetstack/core/xoslib/static/js/xosTenant.js @@ -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); }, }); @@ -84,6 +102,7 @@ XOSTenantApp = new XOSApplication({ logTableId: "#logTable", statusMsgId: "#statusMsg", hideTabsByDefault: true, + dirty: false, varName: "XOSTenantApp", }); @@ -96,13 +115,27 @@ XOSTenantApp.addRegions({ tenantEditUsersInterior: "#tenant-edit-users-interior", }); +XOSTenantApp.setDirty = function(dirty) { + XOSTenantApp.dirty = 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", "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; @@ -127,6 +160,7 @@ XOSTenantApp.buildViews = function() { noDeleteColumn: true, disablePaginate: true, disableFilter: true, + fieldDisplayNames: {"name": "Site"}, }); XOSTenantApp.tenantSiteListView = tenantSiteListClass; @@ -166,6 +200,7 @@ 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() { @@ -177,11 +212,12 @@ XOSTenantApp.addSlice = function() { } 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); @@ -219,6 +255,9 @@ XOSTenantApp.editUsers = function(model) { 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); } ); + if (!array_same_elements(user_ids, model.usersBuffer)) { + XOSTenantApp.setDirty(true); + } model.usersBuffer = user_ids; $(editDialog).dialog("close"); }, @@ -236,6 +275,15 @@ XOSTenantApp.deleteSlice = function(model) { }; XOSTenantApp.viewSlice = function(model) { + if (XOSTenantApp.dirty) { + if (!confirm("The current sliver has unsaved data -- view new sliver anyway ?")) { + $("#tenantSliceSelector select").val(XOSTenantApp.currentSlice.id); + return; + } + } + + XOSTenantApp.setDirty(false); + if (!model && xos.slicesPlus.models.length > 0) { model = xos.slicesPlus.models[0]; } @@ -258,6 +306,8 @@ 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; @@ -267,6 +317,8 @@ XOSTenantApp.viewSlice = function(model) { XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { app: XOSTenantApp, linkedView: tenantSummary } ) ); + + XOSTenantApp.currentSlice = model; } else { XOSTenantApp.tenantSliceSelector.show(new HTMLView({html: ""})); XOSTenantApp.tenantSummary.show(new HTMLView({html: "You have no slices"})); @@ -291,6 +343,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("
"));