Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 1 | XOSTenantSite = XOSModel.extend( { |
| 2 | listFields: ["name", "allocated"], |
| 3 | modelName: "tenantSite", |
| 4 | collectionName: "tenantSites" |
| 5 | }); |
| 6 | |
| 7 | XOSTenantSiteCollection = XOSCollection.extend( { |
| 8 | listFields: ["name", "allocated"], |
| 9 | modelName: "tenantSite", |
| 10 | collectionName: "tenantSites", |
| 11 | |
| 12 | updateFromSlice: function(slice) { |
| 13 | var tenantSites = []; |
| 14 | var id = 0; |
| 15 | for (siteName in slice.attributes.site_allocation) { |
| 16 | allocated = slice.attributes.site_allocation[siteName]; |
| 17 | tenantSites.push(new XOSTenantSite( { name: siteName, allocated: allocated, id: id} )); |
| 18 | id = id + 1; |
| 19 | } |
| 20 | for (index in xos.tenantview.models[0].attributes.blessed_site_names) { |
| 21 | siteName = xos.tenantview.models[0].attributes.blessed_site_names[index]; |
| 22 | if (! (siteName in slice.attributes.site_allocation)) { |
| 23 | tenantSites.push(new XOSTenantSite( { name: siteName, allocated: 0, id: id} )); |
| 24 | id = id + 1; |
| 25 | } |
| 26 | } |
| 27 | this.set(tenantSites); |
| 28 | }, |
| 29 | }); |
| 30 | |
| 31 | XOSTenantButtonView = Marionette.ItemView.extend({ |
| 32 | template: "#xos-tenant-buttons-template", |
| 33 | |
| 34 | events: {"click button.btn-tenant-create": "createClicked", |
| 35 | "click button.btn-tenant-delete": "deleteClicked", |
| 36 | "click button.btn-tenant-add-user": "addUserClicked", |
| 37 | "click button.btn-tenant-save": "saveClicked", |
| 38 | }, |
| 39 | |
| 40 | createClicked: function(e) { |
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 41 | XOSTenantApp.addSlice(); |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 42 | }, |
| 43 | |
| 44 | deleteClicked: function(e) { |
Scott Baker | 6b145aa | 2015-01-12 12:56:25 -0800 | [diff] [blame] | 45 | XOSTenantApp.deleteSlice(this.options.linkedView.model); |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 46 | }, |
| 47 | |
| 48 | addUserClicked: function(e) { |
| 49 | }, |
| 50 | |
| 51 | saveClicked: function(e) { |
| 52 | this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e); |
| 53 | }, |
| 54 | }); |
| 55 | |
| 56 | XOSTenantApp = new XOSApplication({ |
| 57 | logTableId: "#logTable", |
| 58 | statusMsgId: "#statusMsg", |
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 59 | hideTabsByDefault: true, |
| 60 | varName: "XOSTenantApp", |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 61 | }); |
| 62 | |
| 63 | XOSTenantApp.addRegions({ |
| 64 | tenantSliceSelector: "#tenantSliceSelector", |
| 65 | tenantSummary: "#tenantSummary", |
| 66 | tenantSiteList: "#tenantSiteList", |
| 67 | tenantButtons: "#tenantButtons", |
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 68 | tenantAddSliceInterior: "#tenant-addslice-interior", |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 69 | }); |
| 70 | |
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 71 | XOSTenantApp.buildViews = function() { |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 72 | XOSTenantApp.tenantSites = new XOSTenantSiteCollection();
|
| 73 |
|
| 74 | tenantSummaryClass = XOSDetailView.extend({template: "#xos-detail-template",
|
| 75 | app: XOSTenantApp,
|
Scott Baker | aba9183 | 2015-01-12 13:37:31 -0800 | [diff] [blame^] | 76 | detailFields: ["serviceClass", "default_image", "default_flavor", "network_ports", "mount_data_sets"]});
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 77 |
|
| 78 | XOSTenantApp.tenantSummaryView = tenantSummaryClass;
|
| 79 |
|
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 80 | tenantAddClass = XOSDetailView.extend({template: "#xos-detail-template",
|
| 81 | app: XOSTenantApp,
|
| 82 | detailFields: ["name", "description"]});
|
| 83 |
|
| 84 | XOSTenantApp.tenantAddView = tenantAddClass;
|
| 85 |
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 86 | tenantSiteItemClass = XOSItemView.extend({template: "#xos-listitem-template",
|
| 87 | app: XOSTenantApp});
|
| 88 |
|
| 89 | XOSTenantApp.tenantSiteItemView = tenantSiteItemClass;
|
| 90 |
|
| 91 | tenantSiteListClass = XOSDataTableView.extend({template: "#xos-list-template",
|
| 92 | app: XOSTenantApp,
|
| 93 | childView: tenantSiteItemClass,
|
| 94 | collection: XOSTenantApp.tenantSites,
|
| 95 | title: "sites",
|
| 96 | inputType: {allocated: "spinner"},
|
| 97 | noDeleteColumn: true,
|
| 98 | });
|
| 99 |
|
| 100 | XOSTenantApp.tenantSiteListView = tenantSiteListClass;
|
| 101 |
|
| 102 | XOSTenantApp.tenantSliceSelectorView = SliceSelectorView.extend( {
|
| 103 | sliceChanged: function(id) {
|
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 104 | XOSTenantApp.navToSlice(id);
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 105 | },
|
| 106 | });
|
| 107 |
|
| 108 | xos.sites.fetch();
|
| 109 | xos.slicesPlus.fetch();
|
| 110 | xos.tenantview.fetch();
|
| 111 | };
|
| 112 |
|
| 113 | make_choices = function(list_of_names, list_of_values) {
|
| 114 | result = [];
|
| 115 | if (!list_of_values) {
|
| 116 | for (index in list_of_names) {
|
| 117 | displayName = list_of_names[index];
|
| 118 | result.push( [displayName, displayName] );
|
| 119 | }
|
Scott Baker | aba9183 | 2015-01-12 13:37:31 -0800 | [diff] [blame^] | 120 | } else {
|
| 121 | for (index in list_of_names) {
|
| 122 | displayName = list_of_names[index];
|
| 123 | id = list_of_values[index];
|
| 124 | result.push( [displayName, id] );
|
| 125 | }
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 126 | }
|
| 127 | return result;
|
| 128 | };
|
| 129 |
|
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 130 | XOSTenantApp.navToSlice = function(id) {
|
| 131 | XOSTenantApp.viewSlice(xos.slicesPlus.get(id));
|
| 132 | };
|
| 133 |
|
| 134 | XOSTenantApp.adjustCollectionField = function(collectionName, id, fieldName, amount) {
|
| 135 | model = XOSTenantApp[collectionName].get(id);
|
| 136 | model.set(fieldName, Math.max(model.get(fieldName) + amount, 0));
|
| 137 | };
|
| 138 |
|
| 139 | XOSTenantApp.addSlice = function() {
|
| 140 | var app=this;
|
| 141 | model = new xos.slicesPlus.model({site: xos.tenant().current_user_site_id});
|
| 142 | console.log(model);
|
| 143 | var detailView = new XOSTenantApp.tenantAddView({model: model, collection: xos.slicesPlus});
|
| 144 | detailView.dialog = $("tenant-addslice-dialog");
|
| 145 | app.tenantAddSliceInterior.show(detailView);
|
| 146 | $("#tenant-addslice-dialog").dialog({
|
| 147 | autoOpen: false, |
| 148 | modal: true, |
| 149 | width: 640, |
| 150 | buttons : { |
| 151 | "Save" : function() { |
| 152 | var addDialog = this; |
| 153 | detailView.synchronous = true; |
| 154 | detailView.afterSave = function() { $(addDialog).dialog("close"); XOSTenantApp.navToSlice(detailView.model.id); } |
| 155 | detailView.save(); |
| 156 | }, |
| 157 | "Cancel" : function() { |
| 158 | $(this).dialog("close"); |
| 159 | } |
| 160 | } |
| 161 | }); |
| 162 | $("#tenant-addslice-dialog").dialog("open");
|
| 163 | };
|
| 164 |
|
Scott Baker | 6b145aa | 2015-01-12 12:56:25 -0800 | [diff] [blame] | 165 | XOSTenantApp.deleteSlice = function(model) {
|
| 166 | var app=this;
|
| 167 | app.deleteDialog(model, function() { console.log("afterDelete"); app.viewSlice(undefined); });
|
| 168 | };
|
| 169 |
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 170 | XOSTenantApp.viewSlice = function(model) {
|
| 171 | if (!model && xos.slicesPlus.models.length > 0) {
|
| 172 | model = xos.slicesPlus.models[0];
|
| 173 | }
|
| 174 |
|
| 175 | sliceSelector = new XOSTenantApp.tenantSliceSelectorView({collection: xos.slicesPlus,
|
| 176 | selectedID: model.id,
|
| 177 | } );
|
| 178 | XOSTenantApp.sliceSelector = sliceSelector;
|
| 179 | XOSTenantApp.tenantSliceSelector.show(sliceSelector);
|
| 180 |
|
| 181 | tenantSummary = new XOSTenantApp.tenantSummaryView({model: model,
|
Scott Baker | aba9183 | 2015-01-12 13:37:31 -0800 | [diff] [blame^] | 182 | choices: {mount_data_sets: make_choices(xos.tenant().public_volume_names, null),
|
| 183 | serviceClass: make_choices(xos.tenant().blessed_service_class_names, xos.tenant().blessed_service_classes),
|
| 184 | default_image: make_choices(xos.tenant().blessed_image_names, xos.tenant().blessed_image_ids),
|
| 185 | default_flavor: make_choices(xos.tenant().blessed_flavor_names, xos.tenant().blessed_flavor_ids),},
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 186 | });
|
| 187 | XOSTenantApp.tenantSummary.show(tenantSummary);
|
| 188 |
|
| 189 | tenantSites = new XOSTenantSiteCollection();
|
| 190 | tenantSites.updateFromSlice(model);
|
| 191 | XOSTenantApp.tenantSites = tenantSites;
|
| 192 |
|
| 193 | tenantSiteList = new XOSTenantApp.tenantSiteListView({collection: tenantSites });
|
| 194 | XOSTenantApp.tenantSiteList.show(tenantSiteList);
|
| 195 | // on xos.slicePlus.sort, need to update xostenantapp.tenantSites
|
| 196 |
|
| 197 | XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { app: XOSTenantApp,
|
| 198 | linkedView: tenantSummary } ) );
|
| 199 | };
|
| 200 |
|
Scott Baker | aba9183 | 2015-01-12 13:37:31 -0800 | [diff] [blame^] | 201 | XOSTenantApp.sanityCheck = function() {
|
| 202 | errors = [];
|
| 203 | if (xos.tenant().blessed_service_classes.length == 0) {
|
| 204 | errors.push("no blessed service classes");
|
| 205 | }
|
| 206 | if (xos.tenant().blessed_flavors.length == 0) {
|
| 207 | errors.push("no blessed flavors");
|
| 208 | }
|
| 209 | if (xos.tenant().blessed_images.length == 0) {
|
| 210 | errors.push("no blessed images");
|
| 211 | }
|
| 212 | if (xos.tenant().blessed_sites.length == 0) {
|
| 213 | errors.push("no blessed sites");
|
| 214 | }
|
| 215 |
|
| 216 | if (errors.length > 0) {
|
| 217 | $("#tenantSummary").html("Tenant view sanity check failed<br>" + errors.join("<br>"));
|
| 218 | return false;
|
| 219 | }
|
| 220 |
|
| 221 | return true;
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 222 | }
|
| 223 |
|
| 224 | XOSTenantApp.collectionLoadChange = function() {
|
| 225 | stats = xos.getCollectionStatus();
|
| 226 |
|
| 227 | if (!XOSTenantApp.navigationStarted) {
|
| 228 | if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
|
Scott Baker | aba9183 | 2015-01-12 13:37:31 -0800 | [diff] [blame^] | 229 | if (XOSTenantApp.sanityCheck()) {
|
| 230 | XOSTenantApp.viewSlice(undefined);
|
| 231 | }
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 232 | } else {
|
| 233 | $("#tenantSummary").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");
|
| 234 | $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
|
| 235 | }
|
| 236 | }
|
| 237 | };
|
| 238 |
|
| 239 | XOSTenantApp.on("start", function() {
|
| 240 | XOSTenantApp.buildViews(); |
| 241 | |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 242 | // fire it once to initially show the progress bar |
| 243 | XOSTenantApp.collectionLoadChange(); |
| 244 | |
| 245 | // fire it each time the collection load status is updated |
| 246 | Backbone.on("xoslib:collectionLoadChange", XOSTenantApp.collectionLoadChange); |
| 247 | }); |
| 248 | |
| 249 | $(document).ready(function(){ |
| 250 | XOSTenantApp.start(); |
| 251 | }); |
| 252 | |