1 XOSTenantSite = XOSModel.extend( {
2 listFields: ["name", "allocated"],
3 modelName: "tenantSite",
4 collectionName: "tenantSites"
7 XOSTenantSiteCollection = XOSCollection.extend( {
8 listFields: ["name", "allocated"],
9 modelName: "tenantSite",
10 collectionName: "tenantSites",
12 updateFromSlice: function(slice) {
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} ));
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} ));
27 this.set(tenantSites);
31 XOSTenantButtonView = Marionette.ItemView.extend({
32 template: "#xos-tenant-buttons-template",
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",
40 createClicked: function(e) {
41 XOSTenantApp.addSlice();
44 deleteClicked: function(e) {
45 this.options.linkedView.deleteClicked.call(this.options.linkedView, e);
48 addUserClicked: function(e) {
51 saveClicked: function(e) {
52 this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
56 XOSTenantApp = new XOSApplication({
57 logTableId: "#logTable",
58 statusMsgId: "#statusMsg",
59 hideTabsByDefault: true,
60 varName: "XOSTenantApp",
63 XOSTenantApp.addRegions({
64 tenantSliceSelector: "#tenantSliceSelector",
65 tenantSummary: "#tenantSummary",
66 tenantSiteList: "#tenantSiteList",
67 tenantButtons: "#tenantButtons",
68 tenantAddSliceInterior: "#tenant-addslice-interior",
71 XOSTenantApp.buildViews = function() {
72 XOSTenantApp.tenantSites = new XOSTenantSiteCollection();
\r
74 tenantSummaryClass = XOSDetailView.extend({template: "#xos-detail-template",
\r
76 detailFields: ["serviceClass", "image_preference", "network_ports", "mount_data_sets"]});
\r
78 XOSTenantApp.tenantSummaryView = tenantSummaryClass;
\r
80 tenantAddClass = XOSDetailView.extend({template: "#xos-detail-template",
\r
82 detailFields: ["name", "description"]});
\r
84 XOSTenantApp.tenantAddView = tenantAddClass;
\r
86 tenantSiteItemClass = XOSItemView.extend({template: "#xos-listitem-template",
\r
87 app: XOSTenantApp});
\r
89 XOSTenantApp.tenantSiteItemView = tenantSiteItemClass;
\r
91 tenantSiteListClass = XOSDataTableView.extend({template: "#xos-list-template",
\r
93 childView: tenantSiteItemClass,
\r
94 collection: XOSTenantApp.tenantSites,
\r
96 inputType: {allocated: "spinner"},
\r
97 noDeleteColumn: true,
\r
100 XOSTenantApp.tenantSiteListView = tenantSiteListClass;
\r
102 XOSTenantApp.tenantSliceSelectorView = SliceSelectorView.extend( {
\r
103 sliceChanged: function(id) {
\r
104 XOSTenantApp.navToSlice(id);
\r
109 xos.slicesPlus.fetch();
\r
110 xos.tenantview.fetch();
\r
113 make_choices = function(list_of_names, list_of_values) {
\r
115 if (!list_of_values) {
\r
116 for (index in list_of_names) {
\r
117 displayName = list_of_names[index];
\r
118 result.push( [displayName, displayName] );
\r
124 XOSTenantApp.navToSlice = function(id) {
\r
125 XOSTenantApp.viewSlice(xos.slicesPlus.get(id));
\r
128 XOSTenantApp.adjustCollectionField = function(collectionName, id, fieldName, amount) {
\r
129 model = XOSTenantApp[collectionName].get(id);
\r
130 model.set(fieldName, Math.max(model.get(fieldName) + amount, 0));
\r
133 XOSTenantApp.addSlice = function() {
\r
135 model = new xos.slicesPlus.model({site: xos.tenant().current_user_site_id});
\r
136 console.log(model);
\r
137 var detailView = new XOSTenantApp.tenantAddView({model: model, collection: xos.slicesPlus});
\r
138 detailView.dialog = $("tenant-addslice-dialog");
\r
139 app.tenantAddSliceInterior.show(detailView);
\r
140 $("#tenant-addslice-dialog").dialog({
\r
145 "Save" : function() {
146 var addDialog = this;
147 detailView.synchronous = true;
148 detailView.afterSave = function() { $(addDialog).dialog("close"); XOSTenantApp.navToSlice(detailView.model.id); }
151 "Cancel" : function() {
152 $(this).dialog("close");
156 $("#tenant-addslice-dialog").dialog("open");
\r
159 XOSTenantApp.viewSlice = function(model) {
\r
160 if (!model && xos.slicesPlus.models.length > 0) {
\r
161 model = xos.slicesPlus.models[0];
\r
164 sliceSelector = new XOSTenantApp.tenantSliceSelectorView({collection: xos.slicesPlus,
\r
165 selectedID: model.id,
\r
167 XOSTenantApp.sliceSelector = sliceSelector;
\r
168 XOSTenantApp.tenantSliceSelector.show(sliceSelector);
\r
170 tenantSummary = new XOSTenantApp.tenantSummaryView({model: model,
\r
171 choices: {mount_data_sets: make_choices(xos.tenantview.models[0].attributes.public_volume_names, null),
\r
172 image_preference: make_choices(xos.tenantview.models[0].attributes.blessed_image_names, null)},
\r
174 XOSTenantApp.tenantSummary.show(tenantSummary);
\r
176 tenantSites = new XOSTenantSiteCollection();
\r
177 tenantSites.updateFromSlice(model);
\r
178 XOSTenantApp.tenantSites = tenantSites;
\r
180 tenantSiteList = new XOSTenantApp.tenantSiteListView({collection: tenantSites });
\r
181 XOSTenantApp.tenantSiteList.show(tenantSiteList);
\r
182 // on xos.slicePlus.sort, need to update xostenantapp.tenantSites
\r
184 XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { app: XOSTenantApp,
\r
185 linkedView: tenantSummary } ) );
\r
188 XOSTenantApp.startNavigation = function() {
\r
189 Backbone.history.start();
\r
190 XOSTenantApp.navigationStarted = true;
\r
193 XOSTenantApp.collectionLoadChange = function() {
\r
194 stats = xos.getCollectionStatus();
\r
196 if (!XOSTenantApp.navigationStarted) {
\r
197 if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
\r
198 XOSTenantApp.viewSlice(undefined);
\r
200 $("#tenantSummary").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");
\r
201 $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
\r
206 XOSTenantApp.on("start", function() {
\r
207 XOSTenantApp.buildViews();
209 // fire it once to initially show the progress bar
210 XOSTenantApp.collectionLoadChange();
212 // fire it each time the collection load status is updated
213 Backbone.on("xoslib:collectionLoadChange", XOSTenantApp.collectionLoadChange);
216 $(document).ready(function(){
217 XOSTenantApp.start();