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,
|
| 76 | detailFields: ["serviceClass", "image_preference", "network_ports", "mount_data_sets"]});
|
| 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 | }
|
| 120 | }
|
| 121 | return result;
|
| 122 | };
|
| 123 |
|
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 124 | XOSTenantApp.navToSlice = function(id) {
|
| 125 | XOSTenantApp.viewSlice(xos.slicesPlus.get(id));
|
| 126 | };
|
| 127 |
|
| 128 | XOSTenantApp.adjustCollectionField = function(collectionName, id, fieldName, amount) {
|
| 129 | model = XOSTenantApp[collectionName].get(id);
|
| 130 | model.set(fieldName, Math.max(model.get(fieldName) + amount, 0));
|
| 131 | };
|
| 132 |
|
| 133 | XOSTenantApp.addSlice = function() {
|
| 134 | var app=this;
|
| 135 | model = new xos.slicesPlus.model({site: xos.tenant().current_user_site_id});
|
| 136 | console.log(model);
|
| 137 | var detailView = new XOSTenantApp.tenantAddView({model: model, collection: xos.slicesPlus});
|
| 138 | detailView.dialog = $("tenant-addslice-dialog");
|
| 139 | app.tenantAddSliceInterior.show(detailView);
|
| 140 | $("#tenant-addslice-dialog").dialog({
|
| 141 | autoOpen: false, |
| 142 | modal: true, |
| 143 | width: 640, |
| 144 | buttons : { |
| 145 | "Save" : function() { |
| 146 | var addDialog = this; |
| 147 | detailView.synchronous = true; |
| 148 | detailView.afterSave = function() { $(addDialog).dialog("close"); XOSTenantApp.navToSlice(detailView.model.id); } |
| 149 | detailView.save(); |
| 150 | }, |
| 151 | "Cancel" : function() { |
| 152 | $(this).dialog("close"); |
| 153 | } |
| 154 | } |
| 155 | }); |
| 156 | $("#tenant-addslice-dialog").dialog("open");
|
| 157 | };
|
| 158 |
|
Scott Baker | 6b145aa | 2015-01-12 12:56:25 -0800 | [diff] [blame] | 159 | XOSTenantApp.deleteSlice = function(model) {
|
| 160 | var app=this;
|
| 161 | app.deleteDialog(model, function() { console.log("afterDelete"); app.viewSlice(undefined); });
|
| 162 | };
|
| 163 |
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 164 | XOSTenantApp.viewSlice = function(model) {
|
| 165 | if (!model && xos.slicesPlus.models.length > 0) {
|
| 166 | model = xos.slicesPlus.models[0];
|
| 167 | }
|
| 168 |
|
| 169 | sliceSelector = new XOSTenantApp.tenantSliceSelectorView({collection: xos.slicesPlus,
|
| 170 | selectedID: model.id,
|
| 171 | } );
|
| 172 | XOSTenantApp.sliceSelector = sliceSelector;
|
| 173 | XOSTenantApp.tenantSliceSelector.show(sliceSelector);
|
| 174 |
|
| 175 | tenantSummary = new XOSTenantApp.tenantSummaryView({model: model,
|
| 176 | choices: {mount_data_sets: make_choices(xos.tenantview.models[0].attributes.public_volume_names, null),
|
| 177 | image_preference: make_choices(xos.tenantview.models[0].attributes.blessed_image_names, null)},
|
| 178 | });
|
| 179 | XOSTenantApp.tenantSummary.show(tenantSummary);
|
| 180 |
|
| 181 | tenantSites = new XOSTenantSiteCollection();
|
| 182 | tenantSites.updateFromSlice(model);
|
| 183 | XOSTenantApp.tenantSites = tenantSites;
|
| 184 |
|
| 185 | tenantSiteList = new XOSTenantApp.tenantSiteListView({collection: tenantSites });
|
| 186 | XOSTenantApp.tenantSiteList.show(tenantSiteList);
|
| 187 | // on xos.slicePlus.sort, need to update xostenantapp.tenantSites
|
| 188 |
|
| 189 | XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { app: XOSTenantApp,
|
| 190 | linkedView: tenantSummary } ) );
|
| 191 | };
|
| 192 |
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 193 | XOSTenantApp.startNavigation = function() {
|
| 194 | Backbone.history.start();
|
| 195 | XOSTenantApp.navigationStarted = true;
|
| 196 | }
|
| 197 |
|
| 198 | XOSTenantApp.collectionLoadChange = function() {
|
| 199 | stats = xos.getCollectionStatus();
|
| 200 |
|
| 201 | if (!XOSTenantApp.navigationStarted) {
|
| 202 | if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
|
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 203 | XOSTenantApp.viewSlice(undefined);
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 204 | } else {
|
| 205 | $("#tenantSummary").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");
|
| 206 | $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
|
| 207 | }
|
| 208 | }
|
| 209 | };
|
| 210 |
|
| 211 | XOSTenantApp.on("start", function() {
|
| 212 | XOSTenantApp.buildViews(); |
| 213 | |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 214 | // fire it once to initially show the progress bar |
| 215 | XOSTenantApp.collectionLoadChange(); |
| 216 | |
| 217 | // fire it each time the collection load status is updated |
| 218 | Backbone.on("xoslib:collectionLoadChange", XOSTenantApp.collectionLoadChange); |
| 219 | }); |
| 220 | |
| 221 | $(document).ready(function(){ |
| 222 | XOSTenantApp.start(); |
| 223 | }); |
| 224 | |