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 | |
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 12 | getFromSlice: function(slice) { |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 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 | }, |
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 29 | |
| 30 | putToSlice: function(slice) { |
| 31 | slice.attributes.site_allocation = {}; |
| 32 | for (index in this.models) { |
Scott Baker | 435c2c9 | 2015-01-14 00:34:45 -0800 | [diff] [blame] | 33 | var model = this.models[index]; |
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 34 | slice.attributes.site_allocation[ model.attributes.name ] = model.attributes.allocated; |
| 35 | } |
| 36 | }, |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 37 | }); |
| 38 | |
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 39 | XOSEditUsersView = Marionette.ItemView.extend({ |
| 40 | template: "#tenant-edit-users", |
| 41 | viewInitializers: [], |
| 42 | |
| 43 | onShow: function() { |
| 44 | _.each(this.viewInitializers, function(initializer) { |
| 45 | initializer(); |
| 46 | }); |
| 47 | }, |
| 48 | |
| 49 | templateHelpers: function() { return { detailView: this, model: this.model }; }, |
| 50 | |
| 51 | }); |
| 52 | |
Scott Baker | f5d97bd | 2015-01-20 00:04:19 -0800 | [diff] [blame] | 53 | XOSTenantSummaryView = XOSDetailView.extend({ |
| 54 | events: {"change": "onChange"}, |
| 55 | |
| 56 | onChange: function(e) { |
| 57 | XOSTenantApp.setDirty(true); |
| 58 | }, |
| 59 | |
| 60 | saveSuccess: function() { |
| 61 | console.log("saveSuccess!"); |
| 62 | XOSTenantApp.setDirty(false); |
| 63 | }, |
| 64 | |
| 65 | }); |
| 66 | |
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 67 | |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 68 | XOSTenantButtonView = Marionette.ItemView.extend({ |
| 69 | template: "#xos-tenant-buttons-template", |
| 70 | |
| 71 | events: {"click button.btn-tenant-create": "createClicked", |
| 72 | "click button.btn-tenant-delete": "deleteClicked", |
| 73 | "click button.btn-tenant-add-user": "addUserClicked", |
| 74 | "click button.btn-tenant-save": "saveClicked", |
Scott Baker | ec93010 | 2015-01-20 01:02:08 -0800 | [diff] [blame] | 75 | "click button.btn-tenant-download-ssh": "downloadClicked", |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 76 | }, |
| 77 | |
| 78 | createClicked: function(e) { |
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 79 | XOSTenantApp.addSlice(); |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 80 | }, |
| 81 | |
| 82 | deleteClicked: function(e) { |
Scott Baker | 6b145aa | 2015-01-12 12:56:25 -0800 | [diff] [blame] | 83 | XOSTenantApp.deleteSlice(this.options.linkedView.model); |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 84 | }, |
| 85 | |
| 86 | addUserClicked: function(e) { |
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 87 | XOSTenantApp.editUsers(this.options.linkedView.model); |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 88 | }, |
| 89 | |
Scott Baker | ec93010 | 2015-01-20 01:02:08 -0800 | [diff] [blame] | 90 | downloadClicked: function(e) { |
| 91 | XOSTenantApp.downloadSSH(this.options.linkedView.model); |
| 92 | }, |
| 93 | |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 94 | saveClicked: function(e) { |
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 95 | model = this.options.linkedView.model; |
| 96 | model.tenantSiteCollection.putToSlice(model); |
Scott Baker | 435c2c9 | 2015-01-14 00:34:45 -0800 | [diff] [blame] | 97 | model.attributes.users = model.usersBuffer; |
Scott Baker | f5d97bd | 2015-01-20 00:04:19 -0800 | [diff] [blame] | 98 | |
| 99 | e.preventDefault(); |
| 100 | this.options.linkedView.save(); |
| 101 | //this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e); |
| 102 | //XOSTenantApp.setDirty(false); |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 103 | }, |
| 104 | }); |
| 105 | |
| 106 | XOSTenantApp = new XOSApplication({ |
| 107 | logTableId: "#logTable", |
| 108 | statusMsgId: "#statusMsg", |
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 109 | hideTabsByDefault: true, |
Scott Baker | 5175e8a | 2015-01-20 00:20:12 -0800 | [diff] [blame] | 110 | dirty: false, |
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 111 | varName: "XOSTenantApp", |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 112 | }); |
| 113 | |
| 114 | XOSTenantApp.addRegions({ |
| 115 | tenantSliceSelector: "#tenantSliceSelector", |
| 116 | tenantSummary: "#tenantSummary", |
| 117 | tenantSiteList: "#tenantSiteList", |
| 118 | tenantButtons: "#tenantButtons", |
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 119 | tenantAddSliceInterior: "#tenant-addslice-interior", |
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 120 | tenantEditUsersInterior: "#tenant-edit-users-interior", |
Scott Baker | ec93010 | 2015-01-20 01:02:08 -0800 | [diff] [blame] | 121 | tenantSSHCommandsInterior: "#tenant-ssh-commands-interior", |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 122 | }); |
| 123 | |
Scott Baker | f5d97bd | 2015-01-20 00:04:19 -0800 | [diff] [blame] | 124 | XOSTenantApp.setDirty = function(dirty) { |
Scott Baker | 5175e8a | 2015-01-20 00:20:12 -0800 | [diff] [blame] | 125 | XOSTenantApp.dirty = dirty; |
Scott Baker | f5d97bd | 2015-01-20 00:04:19 -0800 | [diff] [blame] | 126 | if (dirty) { |
| 127 | $("button.btn-tenant-save").addClass("btn-success"); |
| 128 | } else { |
| 129 | $("button.btn-tenant-save").removeClass("btn-success"); |
| 130 | } |
| 131 | }; |
| 132 | |
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 133 | XOSTenantApp.buildViews = function() { |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 134 | XOSTenantApp.tenantSites = new XOSTenantSiteCollection();
|
| 135 |
|
Scott Baker | f5d97bd | 2015-01-20 00:04:19 -0800 | [diff] [blame] | 136 | tenantSummaryClass = XOSTenantSummaryView.extend({template: "#xos-detail-template",
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 137 | app: XOSTenantApp,
|
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 138 | detailFields: ["serviceClass", "default_image", "default_flavor", "network_ports", "mount_data_sets"],
|
Scott Baker | e56d327 | 2015-01-14 00:47:50 -0800 | [diff] [blame] | 139 | fieldDisplayNames: {serviceClass: "Service Level", "default_flavor": "Flavor", "default_image": "Image", "mount_data_sets": "Data Sets"},
|
Scott Baker | c3876fb | 2015-01-20 12:37:36 -0800 | [diff] [blame] | 140 | helpText: {"serviceClass": "Existing slivers will be re-instantiated if changed",
|
| 141 | "default_image": "Existing slivers will be re-instantiated if changed",
|
Scott Baker | 51bacad | 2015-01-20 12:24:16 -0800 | [diff] [blame] | 142 | "default_flavor": "Existing slivers will be re-instantiated if changed"},
|
Scott Baker | e7a9045 | 2015-01-14 17:07:30 -0800 | [diff] [blame] | 143 |
|
| 144 | onShow: function() {
|
| 145 | // the slice selector is in a different table, so make every label cell the maximal width
|
| 146 | make_same_width("#xos-tenant-view-panel", ".xos-label-cell");
|
| 147 | },
|
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 148 | });
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 149 |
|
| 150 | XOSTenantApp.tenantSummaryView = tenantSummaryClass;
|
| 151 |
|
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 152 | tenantAddClass = XOSDetailView.extend({template: "#xos-detail-template",
|
| 153 | app: XOSTenantApp,
|
| 154 | detailFields: ["name", "description"]});
|
| 155 |
|
| 156 | XOSTenantApp.tenantAddView = tenantAddClass;
|
| 157 |
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 158 | tenantSiteItemClass = XOSItemView.extend({template: "#xos-listitem-template",
|
| 159 | app: XOSTenantApp});
|
| 160 |
|
| 161 | XOSTenantApp.tenantSiteItemView = tenantSiteItemClass;
|
| 162 |
|
| 163 | tenantSiteListClass = XOSDataTableView.extend({template: "#xos-list-template",
|
| 164 | app: XOSTenantApp,
|
| 165 | childView: tenantSiteItemClass,
|
| 166 | collection: XOSTenantApp.tenantSites,
|
| 167 | title: "sites",
|
| 168 | inputType: {allocated: "spinner"},
|
| 169 | noDeleteColumn: true,
|
Scott Baker | e56d327 | 2015-01-14 00:47:50 -0800 | [diff] [blame] | 170 | disablePaginate: true,
|
| 171 | disableFilter: true,
|
Scott Baker | e7a9045 | 2015-01-14 17:07:30 -0800 | [diff] [blame] | 172 | fieldDisplayNames: {"name": "Site"},
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 173 | });
|
| 174 |
|
| 175 | XOSTenantApp.tenantSiteListView = tenantSiteListClass;
|
| 176 |
|
| 177 | XOSTenantApp.tenantSliceSelectorView = SliceSelectorView.extend( {
|
| 178 | sliceChanged: function(id) {
|
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 179 | XOSTenantApp.navToSlice(id);
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 180 | },
|
Scott Baker | e0e407a | 2015-01-20 17:02:53 -0800 | [diff] [blame] | 181 | filter: function(slice) {
|
| 182 | return slice.attributes.current_user_can_see;
|
| 183 | },
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 184 | });
|
| 185 |
|
| 186 | xos.sites.fetch();
|
| 187 | xos.slicesPlus.fetch();
|
| 188 | xos.tenantview.fetch();
|
| 189 | };
|
| 190 |
|
| 191 | make_choices = function(list_of_names, list_of_values) {
|
| 192 | result = [];
|
| 193 | if (!list_of_values) {
|
| 194 | for (index in list_of_names) {
|
| 195 | displayName = list_of_names[index];
|
| 196 | result.push( [displayName, displayName] );
|
| 197 | }
|
Scott Baker | aba9183 | 2015-01-12 13:37:31 -0800 | [diff] [blame] | 198 | } else {
|
| 199 | for (index in list_of_names) {
|
| 200 | displayName = list_of_names[index];
|
| 201 | id = list_of_values[index];
|
| 202 | result.push( [displayName, id] );
|
| 203 | }
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 204 | }
|
| 205 | return result;
|
| 206 | };
|
| 207 |
|
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 208 | XOSTenantApp.navToSlice = function(id) {
|
| 209 | XOSTenantApp.viewSlice(xos.slicesPlus.get(id));
|
| 210 | };
|
| 211 |
|
| 212 | XOSTenantApp.adjustCollectionField = function(collectionName, id, fieldName, amount) {
|
| 213 | model = XOSTenantApp[collectionName].get(id);
|
| 214 | model.set(fieldName, Math.max(model.get(fieldName) + amount, 0));
|
Scott Baker | f5d97bd | 2015-01-20 00:04:19 -0800 | [diff] [blame] | 215 | XOSTenantApp.setDirty(true);
|
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 216 | };
|
| 217 |
|
| 218 | XOSTenantApp.addSlice = function() {
|
| 219 | var app=this;
|
Scott Baker | ce0dfb8 | 2015-01-14 09:54:19 -0800 | [diff] [blame] | 220 |
|
| 221 | if (!xos.tenant().current_user_can_create_slice) {
|
| 222 | window.alert("You do not have sufficient rights to create a slice on your site");
|
| 223 | return;
|
| 224 | }
|
| 225 |
|
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 226 | model = new xos.slicesPlus.model({site: xos.tenant().current_user_site_id,
|
Scott Baker | c898437 | 2015-01-19 08:56:16 -0800 | [diff] [blame] | 227 | name: xos.tenant().current_user_login_base + "_",
|
| 228 | creator: xos.tenant().current_user_id});
|
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 229 | console.log(model);
|
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 230 | var detailView = new XOSTenantApp.tenantAddView({model: model,
|
Scott Baker | c898437 | 2015-01-19 08:56:16 -0800 | [diff] [blame] | 231 | collection: xos.slicesPlus,
|
| 232 | noSubmitButton: true,
|
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 233 | });
|
| 234 | detailView.dialog = $("#tenant-addslice-dialog");
|
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 235 | app.tenantAddSliceInterior.show(detailView);
|
| 236 | $("#tenant-addslice-dialog").dialog({
|
| 237 | autoOpen: false, |
| 238 | modal: true, |
| 239 | width: 640, |
| 240 | buttons : { |
Scott Baker | 435c2c9 | 2015-01-14 00:34:45 -0800 | [diff] [blame] | 241 | "Create Slice" : function() { |
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 242 | var addDialog = this; |
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 243 | console.log("SAVE!!!"); |
Scott Baker | cd07a59 | 2015-01-12 12:37:38 -0800 | [diff] [blame] | 244 | detailView.synchronous = true; |
| 245 | detailView.afterSave = function() { $(addDialog).dialog("close"); XOSTenantApp.navToSlice(detailView.model.id); } |
| 246 | detailView.save(); |
| 247 | }, |
| 248 | "Cancel" : function() { |
| 249 | $(this).dialog("close"); |
| 250 | } |
| 251 | } |
| 252 | }); |
| 253 | $("#tenant-addslice-dialog").dialog("open");
|
| 254 | };
|
| 255 |
|
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 256 | XOSTenantApp.editUsers = function(model) {
|
| 257 | var app=this;
|
| 258 | var detailView = new XOSEditUsersView({model: model, collection: xos.slicesPlus});
|
| 259 | detailView.dialog = $("#tenant-edit-users-dialog");
|
| 260 | app.tenantEditUsersInterior.show(detailView);
|
| 261 | $("#tenant-edit-users-dialog").dialog({
|
| 262 | autoOpen: false, |
| 263 | modal: true, |
| 264 | width: 640, |
| 265 | buttons : { |
Scott Baker | 435c2c9 | 2015-01-14 00:34:45 -0800 | [diff] [blame] | 266 | "Ok" : function() { |
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 267 | var editDialog = this; |
| 268 | user_ids = all_options($("#tenant-edit-users-dialog").find(".select-picker-to")); |
| 269 | user_ids = user_ids.map( function(x) { return parseInt(x,10); } ); |
Scott Baker | 5175e8a | 2015-01-20 00:20:12 -0800 | [diff] [blame] | 270 | if (!array_same_elements(user_ids, model.usersBuffer)) { |
| 271 | XOSTenantApp.setDirty(true); |
| 272 | } |
Scott Baker | 435c2c9 | 2015-01-14 00:34:45 -0800 | [diff] [blame] | 273 | model.usersBuffer = user_ids; |
Scott Baker | 97acad9 | 2015-01-12 19:45:40 -0800 | [diff] [blame] | 274 | $(editDialog).dialog("close"); |
| 275 | }, |
| 276 | "Cancel" : function() { |
| 277 | $(this).dialog("close"); |
| 278 | } |
| 279 | } |
| 280 | }); |
| 281 | $("#tenant-edit-users-dialog").dialog("open");
|
| 282 | };
|
| 283 |
|
Scott Baker | ec93010 | 2015-01-20 01:02:08 -0800 | [diff] [blame] | 284 | XOSTenantApp.downloadSSHOld = function(model) {
|
| 285 | sshCommands = "";
|
| 286 | for (index in model.attributes.sliceInfo.sshCommands) {
|
| 287 | sshCommand = model.attributes.sliceInfo.sshCommands[index];
|
| 288 | sshCommands = sshCommands + sshCommand + "\n";
|
| 289 | }
|
| 290 |
|
| 291 | if (sshCommands.length == 0) {
|
| 292 | alert("this slice has no instantiated slivers yet");
|
| 293 | return;
|
| 294 | }
|
| 295 |
|
| 296 | var myWindow = window.open("", "ssh_command_list",""); // "width=640, height=480");
|
| 297 | myWindow.document.write("<html><head><title>SSH Commands</title></head><body><pre>" + sshCommands + "</pre></body></html>");
|
| 298 | myWindow.document.close();
|
| 299 | };
|
| 300 |
|
| 301 | XOSTenantApp.downloadSSH = function(model) {
|
| 302 | sshCommands = "";
|
| 303 | for (index in model.attributes.sliceInfo.sshCommands) {
|
| 304 | sshCommand = model.attributes.sliceInfo.sshCommands[index];
|
| 305 | sshCommands = sshCommands + sshCommand + "\n";
|
| 306 | }
|
| 307 |
|
| 308 | if (sshCommands.length == 0) {
|
| 309 | alert("this slice has no instantiated slivers yet");
|
| 310 | return;
|
| 311 | }
|
| 312 |
|
Scott Baker | 61b5bfc | 2015-01-20 01:19:12 -0800 | [diff] [blame] | 313 | var htmlView = new HTMLView({html: '<pre style="overflow: auto; word-wrap: normal; white-space: pre; word-wrap: normal;">' + sshCommands + '</pre>'});
|
Scott Baker | ec93010 | 2015-01-20 01:02:08 -0800 | [diff] [blame] | 314 | XOSTenantApp.tenantSSHCommandsInterior.show(htmlView);
|
| 315 |
|
| 316 | $("#tenant-ssh-commands-dialog").dialog({
|
| 317 | autoOpen: false, |
| 318 | modal: true, |
| 319 | width: 640, |
| 320 | buttons : { |
| 321 | "Ok" : function() { |
| 322 | $(this).dialog("close"); |
| 323 | }, |
| 324 | } |
| 325 | }); |
| 326 | $("#tenant-ssh-commands-dialog").dialog("open");
|
| 327 | };
|
| 328 |
|
Scott Baker | 6b145aa | 2015-01-12 12:56:25 -0800 | [diff] [blame] | 329 | XOSTenantApp.deleteSlice = function(model) {
|
| 330 | var app=this;
|
| 331 | app.deleteDialog(model, function() { console.log("afterDelete"); app.viewSlice(undefined); });
|
| 332 | };
|
| 333 |
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 334 | XOSTenantApp.viewSlice = function(model) {
|
Scott Baker | 5175e8a | 2015-01-20 00:20:12 -0800 | [diff] [blame] | 335 | if (XOSTenantApp.dirty) {
|
| 336 | if (!confirm("The current sliver has unsaved data -- view new sliver anyway ?")) {
|
| 337 | $("#tenantSliceSelector select").val(XOSTenantApp.currentSlice.id);
|
| 338 | return;
|
| 339 | }
|
| 340 | }
|
| 341 |
|
| 342 | XOSTenantApp.setDirty(false);
|
| 343 |
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 344 | if (!model && xos.slicesPlus.models.length > 0) {
|
| 345 | model = xos.slicesPlus.models[0];
|
| 346 | }
|
| 347 |
|
Scott Baker | b52f7af | 2015-01-13 14:41:41 -0800 | [diff] [blame] | 348 | if (model) {
|
| 349 | sliceSelector = new XOSTenantApp.tenantSliceSelectorView({collection: xos.slicesPlus,
|
| 350 | selectedID: model ? model.id : null,
|
| 351 | } );
|
| 352 | XOSTenantApp.sliceSelector = sliceSelector;
|
| 353 | XOSTenantApp.tenantSliceSelector.show(sliceSelector);
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 354 |
|
Scott Baker | b52f7af | 2015-01-13 14:41:41 -0800 | [diff] [blame] | 355 | tenantSummary = new XOSTenantApp.tenantSummaryView({model: model,
|
| 356 | choices: {mount_data_sets: make_choices(xos.tenant().public_volume_names, null),
|
| 357 | serviceClass: make_choices(xos.tenant().blessed_service_class_names, xos.tenant().blessed_service_classes),
|
| 358 | default_image: make_choices(xos.tenant().blessed_image_names, xos.tenant().blessed_images),
|
| 359 | default_flavor: make_choices(xos.tenant().blessed_flavor_names, xos.tenant().blessed_flavors),},
|
| 360 | });
|
| 361 | XOSTenantApp.tenantSummary.show(tenantSummary);
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 362 |
|
Scott Baker | b52f7af | 2015-01-13 14:41:41 -0800 | [diff] [blame] | 363 | tenantSites = new XOSTenantSiteCollection();
|
| 364 | tenantSites.getFromSlice(model);
|
Scott Baker | 435c2c9 | 2015-01-14 00:34:45 -0800 | [diff] [blame] | 365 | 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 */
|
Scott Baker | 1215424 | 2015-01-16 19:26:54 -0800 | [diff] [blame] | 366 | model.usersOrig = model.attributes.users; /* save an immutable copy that we'll use for username lookups */
|
| 367 | model.user_namesOrig = model.attributes.user_names;
|
Scott Baker | b52f7af | 2015-01-13 14:41:41 -0800 | [diff] [blame] | 368 | model.tenantSiteCollection = tenantSites;
|
| 369 | XOSTenantApp.tenantSites = tenantSites;
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 370 |
|
Scott Baker | b52f7af | 2015-01-13 14:41:41 -0800 | [diff] [blame] | 371 | tenantSiteList = new XOSTenantApp.tenantSiteListView({collection: tenantSites });
|
| 372 | XOSTenantApp.tenantSiteList.show(tenantSiteList);
|
| 373 | // on xos.slicePlus.sort, need to update xostenantapp.tenantSites
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 374 |
|
Scott Baker | b52f7af | 2015-01-13 14:41:41 -0800 | [diff] [blame] | 375 | XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { app: XOSTenantApp,
|
| 376 | linkedView: tenantSummary } ) );
|
Scott Baker | 5175e8a | 2015-01-20 00:20:12 -0800 | [diff] [blame] | 377 |
|
| 378 | XOSTenantApp.currentSlice = model;
|
Scott Baker | b52f7af | 2015-01-13 14:41:41 -0800 | [diff] [blame] | 379 | } else {
|
| 380 | XOSTenantApp.tenantSliceSelector.show(new HTMLView({html: ""}));
|
| 381 | XOSTenantApp.tenantSummary.show(new HTMLView({html: "You have no slices"}));
|
| 382 | XOSTenantApp.tenantSiteList.show(new HTMLView({html: ""}));
|
| 383 | XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { template: "#xos-tenant-buttons-noslice-template",
|
| 384 | app: XOSTenantApp,
|
| 385 | linkedView: tenantSummary } ) );
|
| 386 | }
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 387 | };
|
| 388 |
|
Scott Baker | aba9183 | 2015-01-12 13:37:31 -0800 | [diff] [blame] | 389 | XOSTenantApp.sanityCheck = function() {
|
| 390 | errors = [];
|
| 391 | if (xos.tenant().blessed_service_classes.length == 0) {
|
| 392 | errors.push("no blessed service classes");
|
| 393 | }
|
| 394 | if (xos.tenant().blessed_flavors.length == 0) {
|
| 395 | errors.push("no blessed flavors");
|
| 396 | }
|
| 397 | if (xos.tenant().blessed_images.length == 0) {
|
| 398 | errors.push("no blessed images");
|
| 399 | }
|
| 400 | if (xos.tenant().blessed_sites.length == 0) {
|
| 401 | errors.push("no blessed sites");
|
| 402 | }
|
Scott Baker | 9eebcb6 | 2015-01-18 17:04:35 -0800 | [diff] [blame] | 403 | if (xos.tenant().current_user_site_id == null) {
|
| 404 | errors.push("current user does not have a site");
|
| 405 | }
|
Scott Baker | aba9183 | 2015-01-12 13:37:31 -0800 | [diff] [blame] | 406 |
|
| 407 | if (errors.length > 0) {
|
| 408 | $("#tenantSummary").html("Tenant view sanity check failed<br>" + errors.join("<br>"));
|
| 409 | return false;
|
| 410 | }
|
| 411 |
|
| 412 | return true;
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 413 | }
|
| 414 |
|
| 415 | XOSTenantApp.collectionLoadChange = function() {
|
| 416 | stats = xos.getCollectionStatus();
|
| 417 |
|
| 418 | if (!XOSTenantApp.navigationStarted) {
|
| 419 | if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
|
Scott Baker | aba9183 | 2015-01-12 13:37:31 -0800 | [diff] [blame] | 420 | if (XOSTenantApp.sanityCheck()) {
|
| 421 | XOSTenantApp.viewSlice(undefined);
|
| 422 | }
|
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 423 | } else {
|
| 424 | $("#tenantSummary").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");
|
| 425 | $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
|
| 426 | }
|
| 427 | }
|
| 428 | };
|
| 429 |
|
| 430 | XOSTenantApp.on("start", function() {
|
| 431 | XOSTenantApp.buildViews(); |
| 432 | |
Scott Baker | 342d9b9 | 2015-01-11 13:44:30 -0800 | [diff] [blame] | 433 | // fire it once to initially show the progress bar |
| 434 | XOSTenantApp.collectionLoadChange(); |
| 435 | |
| 436 | // fire it each time the collection load status is updated |
| 437 | Backbone.on("xoslib:collectionLoadChange", XOSTenantApp.collectionLoadChange); |
| 438 | }); |
| 439 | |
| 440 | $(document).ready(function(){ |
| 441 | XOSTenantApp.start(); |
| 442 | }); |
| 443 | |