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