X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2FxosTenant.js;h=ae6f955eeda30063cd3acdaee29e13fe865e8b6a;hb=e5eeb46dd6b896101cf680bcf4d1d3083960afdf;hp=fc510f3450fbb35d72250165f6c48514bd639eae;hpb=9496740998d3d5aeaf3c2f76b312f309c15c4f60;p=plstackapi.git diff --git a/planetstack/core/xoslib/static/js/xosTenant.js b/planetstack/core/xoslib/static/js/xosTenant.js index fc510f3..ae6f955 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", @@ -58,6 +72,7 @@ XOSTenantButtonView = Marionette.ItemView.extend({ "click button.btn-tenant-delete": "deleteClicked", "click button.btn-tenant-add-user": "addUserClicked", "click button.btn-tenant-save": "saveClicked", + "click button.btn-tenant-download-ssh": "downloadClicked", }, createClicked: function(e) { @@ -72,10 +87,19 @@ XOSTenantButtonView = Marionette.ItemView.extend({ XOSTenantApp.editUsers(this.options.linkedView.model); }, + downloadClicked: function(e) { + XOSTenantApp.downloadSSH(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); + model.attributes.users = model.usersBuffer; + + e.preventDefault(); + this.options.linkedView.save(); + //this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e); + //XOSTenantApp.setDirty(false); }, }); @@ -83,6 +107,7 @@ XOSTenantApp = new XOSApplication({ logTableId: "#logTable", statusMsgId: "#statusMsg", hideTabsByDefault: true, + dirty: false, varName: "XOSTenantApp", }); @@ -93,15 +118,33 @@ XOSTenantApp.addRegions({ tenantButtons: "#tenantButtons", tenantAddSliceInterior: "#tenant-addslice-interior", tenantEditUsersInterior: "#tenant-edit-users-interior", + tenantSSHCommandsInterior: "#tenant-ssh-commands-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"}, + fieldDisplayNames: {serviceClass: "Service Level", "default_flavor": "Flavor", "default_image": "Image", "mount_data_sets": "Data Sets"}, + helpText: {"serviceClass": "Existing slivers will be re-instantiated if changed", + "default_image": "Existing slivers will be re-instantiated if changed", + "default_flavor": "Existing slivers will be re-instantiated if changed"}, + + 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 +167,9 @@ XOSTenantApp.buildViews = function() { title: "sites", inputType: {allocated: "spinner"}, noDeleteColumn: true, + disablePaginate: true, + disableFilter: true, + fieldDisplayNames: {"name": "Site"}, }); XOSTenantApp.tenantSiteListView = tenantSiteListClass; @@ -163,16 +209,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 +235,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 +260,14 @@ 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; + if (!array_same_elements(user_ids, model.usersBuffer)) { + XOSTenantApp.setDirty(true); + } + model.usersBuffer = user_ids; $(editDialog).dialog("close"); }, "Cancel" : function() { @@ -221,41 +278,109 @@ XOSTenantApp.editUsers = function(model) { $("#tenant-edit-users-dialog").dialog("open"); }; +XOSTenantApp.downloadSSHOld = function(model) { + sshCommands = ""; + for (index in model.attributes.sliceInfo.sshCommands) { + sshCommand = model.attributes.sliceInfo.sshCommands[index]; + sshCommands = sshCommands + sshCommand + "\n"; + } + + if (sshCommands.length == 0) { + alert("this slice has no instantiated slivers yet"); + return; + } + + var myWindow = window.open("", "ssh_command_list",""); // "width=640, height=480"); + myWindow.document.write("SSH Commands
" + sshCommands + "
"); + myWindow.document.close(); +}; + +XOSTenantApp.downloadSSH = function(model) { + sshCommands = ""; + for (index in model.attributes.sliceInfo.sshCommands) { + sshCommand = model.attributes.sliceInfo.sshCommands[index]; + sshCommands = sshCommands + sshCommand + "\n"; + } + + if (sshCommands.length == 0) { + alert("this slice has no instantiated slivers yet"); + return; + } + + var htmlView = new HTMLView({html: '
' + sshCommands + '
'}); + XOSTenantApp.tenantSSHCommandsInterior.show(htmlView); + + $("#tenant-ssh-commands-dialog").dialog({ + autoOpen: false, + modal: true, + width: 640, + buttons : { + "Ok" : function() { + $(this).dialog("close"); + }, + } + }); + $("#tenant-ssh-commands-dialog").dialog("open"); +}; + XOSTenantApp.deleteSlice = function(model) { var app=this; app.deleteDialog(model, function() { console.log("afterDelete"); app.viewSlice(undefined); }); }; 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]; } - sliceSelector = new XOSTenantApp.tenantSliceSelectorView({collection: xos.slicesPlus, - selectedID: model.id, - } ); - XOSTenantApp.sliceSelector = sliceSelector; - XOSTenantApp.tenantSliceSelector.show(sliceSelector); - - tenantSummary = new XOSTenantApp.tenantSummaryView({model: model, - choices: {mount_data_sets: make_choices(xos.tenant().public_volume_names, null), - serviceClass: make_choices(xos.tenant().blessed_service_class_names, xos.tenant().blessed_service_classes), - default_image: make_choices(xos.tenant().blessed_image_names, xos.tenant().blessed_images), - default_flavor: make_choices(xos.tenant().blessed_flavor_names, xos.tenant().blessed_flavors),}, - }); - XOSTenantApp.tenantSummary.show(tenantSummary); - - tenantSites = new XOSTenantSiteCollection(); - tenantSites.getFromSlice(model); - model.tenantSiteCollection = tenantSites; - XOSTenantApp.tenantSites = tenantSites; - - tenantSiteList = new XOSTenantApp.tenantSiteListView({collection: tenantSites }); - XOSTenantApp.tenantSiteList.show(tenantSiteList); - // on xos.slicePlus.sort, need to update xostenantapp.tenantSites - - XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { app: XOSTenantApp, - linkedView: tenantSummary } ) ); + if (model) { + sliceSelector = new XOSTenantApp.tenantSliceSelectorView({collection: xos.slicesPlus, + selectedID: model ? model.id : null, + } ); + XOSTenantApp.sliceSelector = sliceSelector; + XOSTenantApp.tenantSliceSelector.show(sliceSelector); + + tenantSummary = new XOSTenantApp.tenantSummaryView({model: model, + choices: {mount_data_sets: make_choices(xos.tenant().public_volume_names, null), + serviceClass: make_choices(xos.tenant().blessed_service_class_names, xos.tenant().blessed_service_classes), + default_image: make_choices(xos.tenant().blessed_image_names, xos.tenant().blessed_images), + default_flavor: make_choices(xos.tenant().blessed_flavor_names, xos.tenant().blessed_flavors),}, + }); + XOSTenantApp.tenantSummary.show(tenantSummary); + + 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; + + tenantSiteList = new XOSTenantApp.tenantSiteListView({collection: tenantSites }); + XOSTenantApp.tenantSiteList.show(tenantSiteList); + // on xos.slicePlus.sort, need to update xostenantapp.tenantSites + + 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"})); + XOSTenantApp.tenantSiteList.show(new HTMLView({html: ""})); + XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { template: "#xos-tenant-buttons-noslice-template", + app: XOSTenantApp, + linkedView: tenantSummary } ) ); + } }; XOSTenantApp.sanityCheck = function() { @@ -272,6 +397,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("
"));