blob: 5095505186a23641dc09cbac416c940489fb03e1 [file] [log] [blame]
Scott Baker342d9b92015-01-11 13:44:30 -08001XOSTenantSite = XOSModel.extend( {
2 listFields: ["name", "allocated"],
3 modelName: "tenantSite",
4 collectionName: "tenantSites"
5});
6
7XOSTenantSiteCollection = 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
31XOSTenantButtonView = 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) {
41 },
42
43 deleteClicked: function(e) {
44 this.options.linkedView.deleteClicked.call(this.options.linkedView, e);
45 },
46
47 addUserClicked: function(e) {
48 },
49
50 saveClicked: function(e) {
51 this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
52 },
53 });
54
55XOSTenantApp = new XOSApplication({
56 logTableId: "#logTable",
57 statusMsgId: "#statusMsg",
58 hideTabsByDefault: true
59});
60
61XOSTenantApp.addRegions({
62 tenantSliceSelector: "#tenantSliceSelector",
63 tenantSummary: "#tenantSummary",
64 tenantSiteList: "#tenantSiteList",
65 tenantButtons: "#tenantButtons",
66});
67
68XOSTenantApp.buildViews = function() {
69 XOSTenantApp.tenantSites = new XOSTenantSiteCollection();
70
71 tenantSummaryClass = XOSDetailView.extend({template: "#xos-detail-template",
72 app: XOSTenantApp,
73 detailFields: ["serviceClass", "image_preference", "network_ports", "mount_data_sets"]});
74
75 XOSTenantApp.tenantSummaryView = tenantSummaryClass;
76
77 tenantSiteItemClass = XOSItemView.extend({template: "#xos-listitem-template",
78 app: XOSTenantApp});
79
80 XOSTenantApp.tenantSiteItemView = tenantSiteItemClass;
81
82 tenantSiteListClass = XOSDataTableView.extend({template: "#xos-list-template",
83 app: XOSTenantApp,
84 childView: tenantSiteItemClass,
85 collection: XOSTenantApp.tenantSites,
86 title: "sites",
87 inputType: {allocated: "spinner"},
88 noDeleteColumn: true,
89 });
90
91 XOSTenantApp.tenantSiteListView = tenantSiteListClass;
92
93 XOSTenantApp.tenantSliceSelectorView = SliceSelectorView.extend( {
94 sliceChanged: function(id) {
95 //console.log("navigate to " + id);
96 XOSTenantApp.Router.navigate("slice/" + id, {trigger: true});
97 },
98 });
99
100 xos.sites.fetch();
101 xos.slicesPlus.fetch();
102 xos.tenantview.fetch();
103};
104
105make_choices = function(list_of_names, list_of_values) {
106 result = [];
107 if (!list_of_values) {
108 for (index in list_of_names) {
109 displayName = list_of_names[index];
110 result.push( [displayName, displayName] );
111 }
112 }
113 return result;
114};
115
116XOSTenantApp.viewSlice = function(model) {
117 if (!model && xos.slicesPlus.models.length > 0) {
118 model = xos.slicesPlus.models[0];
119 }
120
121 sliceSelector = new XOSTenantApp.tenantSliceSelectorView({collection: xos.slicesPlus,
122 selectedID: model.id,
123 } );
124 XOSTenantApp.sliceSelector = sliceSelector;
125 XOSTenantApp.tenantSliceSelector.show(sliceSelector);
126
127 tenantSummary = new XOSTenantApp.tenantSummaryView({model: model,
128 choices: {mount_data_sets: make_choices(xos.tenantview.models[0].attributes.public_volume_names, null),
129 image_preference: make_choices(xos.tenantview.models[0].attributes.blessed_image_names, null)},
130 });
131 XOSTenantApp.tenantSummary.show(tenantSummary);
132
133 tenantSites = new XOSTenantSiteCollection();
134 tenantSites.updateFromSlice(model);
135 XOSTenantApp.tenantSites = tenantSites;
136
137 tenantSiteList = new XOSTenantApp.tenantSiteListView({collection: tenantSites });
138 XOSTenantApp.tenantSiteList.show(tenantSiteList);
139 // on xos.slicePlus.sort, need to update xostenantapp.tenantSites
140
141 XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { app: XOSTenantApp,
142 linkedView: tenantSummary } ) );
143};
144
145XOSTenantApp.initRouter = function() {
146 router = XOSRouter;
147 var api = {};
148 var routes = {};
149
150 nav_url = "slice/:id";
151 api_command = "viewSlice";
152 api[api_command] = function(id) { XOSTenantApp.viewSlice(xos.slicesPlus.get(id)); };
153 routes[nav_url] = api_command;
154
155 nav_url = "increase/:collectionName/:id/:fieldName";
156 api_command = "increase";
157 api[api_command] = function(collectionName, id, fieldName) {
158 XOSTenantApp.Router.showPreviousURL();
159 model = XOSTenantApp[collectionName].get(id);
160 model.set(fieldName, model.get(fieldName) + 1);
161 };
162 routes[nav_url] = api_command;
163
164 nav_url = "decrease/:collectionName/:id/:fieldName";
165 api_command = "decrease";
166 api[api_command] = function(collectionName, id, fieldName) {
167 XOSTenantApp.Router.showPreviousURL();
168 model = XOSTenantApp[collectionName].get(id);
169 model.set(fieldName, Math.max(0, model.get(fieldName) - 1));
170 };
171 routes[nav_url] = api_command;
172
173 nav_url = "*path";
174 api_command = "defaultRoute";
175 api[api_command] = function() { XOSTenantApp.viewSlice(undefined); };
176 routes[nav_url] = api_command;
177
178 XOSTenantApp.Router = new router({ appRoutes: routes, controller: api });
179};
180
181XOSTenantApp.startNavigation = function() {
182 Backbone.history.start();
183 XOSTenantApp.navigationStarted = true;
184}
185
186XOSTenantApp.collectionLoadChange = function() {
187 stats = xos.getCollectionStatus();
188
189 if (!XOSTenantApp.navigationStarted) {
190 if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
191 XOSTenantApp.startNavigation();
192
193 //if (xos.slicesPlus.models.length > 0) {
194 // XOSTenantApp.Router.navigate("slice/" + xos.slicesPlus.models[0].id, {trigger:true});
195 //}
196 } else {
197 $("#tenantSummary").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");
198 $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
199 }
200 }
201};
202
203XOSTenantApp.on("start", function() {
204 XOSTenantApp.buildViews();
205
206 XOSTenantApp.initRouter();
207
208 // fire it once to initially show the progress bar
209 XOSTenantApp.collectionLoadChange();
210
211 // fire it each time the collection load status is updated
212 Backbone.on("xoslib:collectionLoadChange", XOSTenantApp.collectionLoadChange);
213});
214
215$(document).ready(function(){
216 XOSTenantApp.start();
217});
218