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) {
43 deleteClicked: function(e) {
44 this.options.linkedView.deleteClicked.call(this.options.linkedView, e);
47 addUserClicked: function(e) {
50 saveClicked: function(e) {
51 this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
55 XOSTenantApp = new XOSApplication({
56 logTableId: "#logTable",
57 statusMsgId: "#statusMsg",
58 hideTabsByDefault: true
61 XOSTenantApp.addRegions({
62 tenantSliceSelector: "#tenantSliceSelector",
63 tenantSummary: "#tenantSummary",
64 tenantSiteList: "#tenantSiteList",
65 tenantButtons: "#tenantButtons",
68 XOSTenantApp.buildViews = function() {
\r
69 XOSTenantApp.tenantSites = new XOSTenantSiteCollection();
\r
71 tenantSummaryClass = XOSDetailView.extend({template: "#xos-detail-template",
\r
73 detailFields: ["serviceClass", "image_preference", "network_ports", "mount_data_sets"]});
\r
75 XOSTenantApp.tenantSummaryView = tenantSummaryClass;
\r
77 tenantSiteItemClass = XOSItemView.extend({template: "#xos-listitem-template",
\r
78 app: XOSTenantApp});
\r
80 XOSTenantApp.tenantSiteItemView = tenantSiteItemClass;
\r
82 tenantSiteListClass = XOSDataTableView.extend({template: "#xos-list-template",
\r
84 childView: tenantSiteItemClass,
\r
85 collection: XOSTenantApp.tenantSites,
\r
87 inputType: {allocated: "spinner"},
\r
88 noDeleteColumn: true,
\r
91 XOSTenantApp.tenantSiteListView = tenantSiteListClass;
\r
93 XOSTenantApp.tenantSliceSelectorView = SliceSelectorView.extend( {
\r
94 sliceChanged: function(id) {
\r
95 //console.log("navigate to " + id);
\r
96 XOSTenantApp.Router.navigate("slice/" + id, {trigger: true});
\r
101 xos.slicesPlus.fetch();
\r
102 xos.tenantview.fetch();
\r
105 make_choices = function(list_of_names, list_of_values) {
\r
107 if (!list_of_values) {
\r
108 for (index in list_of_names) {
\r
109 displayName = list_of_names[index];
\r
110 result.push( [displayName, displayName] );
\r
116 XOSTenantApp.viewSlice = function(model) {
\r
117 if (!model && xos.slicesPlus.models.length > 0) {
\r
118 model = xos.slicesPlus.models[0];
\r
121 sliceSelector = new XOSTenantApp.tenantSliceSelectorView({collection: xos.slicesPlus,
\r
122 selectedID: model.id,
\r
124 XOSTenantApp.sliceSelector = sliceSelector;
\r
125 XOSTenantApp.tenantSliceSelector.show(sliceSelector);
\r
127 tenantSummary = new XOSTenantApp.tenantSummaryView({model: model,
\r
128 choices: {mount_data_sets: make_choices(xos.tenantview.models[0].attributes.public_volume_names, null),
\r
129 image_preference: make_choices(xos.tenantview.models[0].attributes.blessed_image_names, null)},
\r
131 XOSTenantApp.tenantSummary.show(tenantSummary);
\r
133 tenantSites = new XOSTenantSiteCollection();
\r
134 tenantSites.updateFromSlice(model);
\r
135 XOSTenantApp.tenantSites = tenantSites;
\r
137 tenantSiteList = new XOSTenantApp.tenantSiteListView({collection: tenantSites });
\r
138 XOSTenantApp.tenantSiteList.show(tenantSiteList);
\r
139 // on xos.slicePlus.sort, need to update xostenantapp.tenantSites
\r
141 XOSTenantApp.tenantButtons.show( new XOSTenantButtonView( { app: XOSTenantApp,
\r
142 linkedView: tenantSummary } ) );
\r
145 XOSTenantApp.initRouter = function() {
\r
146 router = XOSRouter;
\r
150 nav_url = "slice/:id";
\r
151 api_command = "viewSlice";
\r
152 api[api_command] = function(id) { XOSTenantApp.viewSlice(xos.slicesPlus.get(id)); };
\r
153 routes[nav_url] = api_command;
\r
155 nav_url = "increase/:collectionName/:id/:fieldName";
\r
156 api_command = "increase";
\r
157 api[api_command] = function(collectionName, id, fieldName) {
\r
158 XOSTenantApp.Router.showPreviousURL();
\r
159 model = XOSTenantApp[collectionName].get(id);
\r
160 model.set(fieldName, model.get(fieldName) + 1);
\r
162 routes[nav_url] = api_command;
\r
164 nav_url = "decrease/:collectionName/:id/:fieldName";
\r
165 api_command = "decrease";
\r
166 api[api_command] = function(collectionName, id, fieldName) {
\r
167 XOSTenantApp.Router.showPreviousURL();
\r
168 model = XOSTenantApp[collectionName].get(id);
\r
169 model.set(fieldName, Math.max(0, model.get(fieldName) - 1));
\r
171 routes[nav_url] = api_command;
\r
174 api_command = "defaultRoute";
\r
175 api[api_command] = function() { XOSTenantApp.viewSlice(undefined); };
\r
176 routes[nav_url] = api_command;
\r
178 XOSTenantApp.Router = new router({ appRoutes: routes, controller: api });
\r
181 XOSTenantApp.startNavigation = function() {
\r
182 Backbone.history.start();
\r
183 XOSTenantApp.navigationStarted = true;
\r
186 XOSTenantApp.collectionLoadChange = function() {
\r
187 stats = xos.getCollectionStatus();
\r
189 if (!XOSTenantApp.navigationStarted) {
\r
190 if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
\r
191 XOSTenantApp.startNavigation();
\r
193 //if (xos.slicesPlus.models.length > 0) {
\r
194 // XOSTenantApp.Router.navigate("slice/" + xos.slicesPlus.models[0].id, {trigger:true});
\r
197 $("#tenantSummary").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");
\r
198 $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
\r
203 XOSTenantApp.on("start", function() {
\r
204 XOSTenantApp.buildViews();
206 XOSTenantApp.initRouter();
208 // fire it once to initially show the progress bar
209 XOSTenantApp.collectionLoadChange();
211 // fire it each time the collection load status is updated
212 Backbone.on("xoslib:collectionLoadChange", XOSTenantApp.collectionLoadChange);
215 $(document).ready(function(){
216 XOSTenantApp.start();