blob: ceb2589b0f1e523b7b8038f90ef632efc96cd22a [file] [log] [blame]
Scott Baker694f5662014-11-03 23:46:20 -08001OBJS = ['deployment', 'image', 'networkTemplate', 'network', 'networkSliver', 'networkDeployment', 'node', 'service', 'site', 'slice', 'sliceDeployment', 'slicePrivilege', 'sliver', 'user', 'sliceRole', 'userDeployment'];
2NAV_OBJS = ['deployment', 'site', 'slice', 'user'];
3
Scott Bakerac694222014-11-05 22:12:33 -08004REWRITES = {"/admin/core/deployment/": "#deployments",
5 "/admin/core/site/" : "#sites",
6 "/admin/core/slice/" : "#slices",
7 "/admin/core/user/" : "#users"};
8
9XOSAdminApp = new XOSApplication({
10 logTableId: "#logTable",
11 statusMsgId: "#statusMsg",
12 hideTabsByDefault: true
13});
Scott Baker694f5662014-11-03 23:46:20 -080014
15XOSAdminApp.addRegions({
16 navigation: "#navigationPanel",
17
18 detail: "#detail",
19 linkedObjs1: "#linkedObjs1",
20 linkedObjs2: "#linkedObjs2",
21 linkedObjs3: "#linkedObjs3",
22 linkedObjs4: "#linkedObjs4"
23});
24
25XOSAdminApp.navigateToModel = function(app, detailClass, detailNavLink, model) {
26 XOSAdminApp.Router.navigate(detailNavLink + "/" + model.id, {trigger: true});
27};
28
Scott Baker13e6f0d2014-11-18 17:02:07 -080029XOSAdminApp.navigate = function(what, modelName, modelId) {
30 collection_name = modelName + "s";
31 if (what=="list") {
32 XOSAdminApp.Router.navigate(collection_name, {trigger: true})
33 } else if (what=="detail") {
34 XOSAdminApp.Router.navigate(collection_name + "/" + modelId, {trigger: true})
35 } else if (what=="add") {
36 XOSAdminApp.Router.navigate("add" + firstCharUpper(modelName), {trigger: true})
37 }
38}
39
Scott Bakerf76d33a2014-11-04 09:34:01 -080040ICON_CLASSES = {home: "icon-home", deployments: "icon-deployment", sites: "icon-site", slices: "icon-slice", users: "icon-user"};
41
Scott Baker694f5662014-11-03 23:46:20 -080042XOSAdminApp.updateNavigationPanel = function() {
43 buttonTemplate=$("#xos-navbutton").html();
44 assert(buttonTemplate != undefined, "buttonTemplate is undefined");
Scott Bakerf76d33a2014-11-04 09:34:01 -080045 html="<div class='left-nav'><ul>";
Scott Baker694f5662014-11-03 23:46:20 -080046 for (var index in NAV_OBJS) {
47 name = NAV_OBJS[index];
48 collection_name = name+"s";
Scott Bakerf76d33a2014-11-04 09:34:01 -080049 nav_url = "#" + collection_name;
Scott Baker694f5662014-11-03 23:46:20 -080050 id = "nav-"+name;
Scott Bakerf76d33a2014-11-04 09:34:01 -080051 icon_class = ICON_CLASSES[collection_name] || "icon-cog";
Scott Baker694f5662014-11-03 23:46:20 -080052
Scott Bakerf76d33a2014-11-04 09:34:01 -080053 html = html + _.template(buttonTemplate, {name: collection_name, router: "XOSAdminApp.Router", routeUrl: nav_url, iconClass: icon_class});
Scott Baker694f5662014-11-03 23:46:20 -080054 }
55
Scott Bakerf76d33a2014-11-04 09:34:01 -080056 html = html + "</ul>";
57
Scott Baker694f5662014-11-03 23:46:20 -080058 $("#navigationPanel").html(html);
59};
60
61XOSAdminApp.buildViews = function() {
62 for (var index in OBJS) {
63 name = OBJS[index];
64 tr_template = '#xosAdmin-' + name + '-listitem-template';
65 table_template = '#xosAdmin-' + name + '-list-template';
66 detail_template = '#xosAdmin-' + name + '-detail-template';
67 collection_name = name + "s";
68 region_name = name + "List";
69 detailNavLink = collection_name;
70
71 detailClass = XOSDetailView.extend({
72 template: detail_template,
73 app: XOSAdminApp,
74 });
75 XOSAdminApp[collection_name + "DetailView"] = detailClass;
76
77 itemViewClass = XOSItemView.extend({
78 detailClass: detailClass,
79 template: tr_template,
80 app: XOSAdminApp,
81 detailNavLink: detailNavLink,
82 });
83
84 listViewClass = XOSListView.extend({
85 childView: itemViewClass,
86 template: table_template,
87 collection: xos[collection_name],
88 title: name + "s",
89 app: XOSAdminApp,
90 });
91
92 XOSAdminApp[collection_name + "ListView"] = listViewClass;
93
94 xos[collection_name].fetch(); //startPolling();
95 }
96};
97
98XOSAdminApp.initRouter = function() {
99 router = Marionette.AppRouter.extend({
100 });
101
102 var api = {};
103 var routes = {};
104
Scott Baker694f5662014-11-03 23:46:20 -0800105 for (var index in OBJS) {
106 name = OBJS[index];
107 collection_name = name + "s";
108 nav_url = collection_name;
Scott Baker7ce23652014-11-07 16:40:30 -0800109 api_command = "list" + firstCharUpper(collection_name);
Scott Baker694f5662014-11-03 23:46:20 -0800110 listViewName = collection_name + "ListView";
111 detailViewName = collection_name + "DetailView";
112
Scott Baker9d37d562014-11-04 23:20:48 -0800113 api[api_command] = XOSAdminApp.listViewShower(listViewName, collection_name, "detail", collection_name);
Scott Baker694f5662014-11-03 23:46:20 -0800114 routes[nav_url] = api_command;
115
116 nav_url = collection_name + "/:id";
Scott Baker7ce23652014-11-07 16:40:30 -0800117 api_command = "detail" + firstCharUpper(collection_name);
Scott Baker694f5662014-11-03 23:46:20 -0800118
Scott Baker9d37d562014-11-04 23:20:48 -0800119 api[api_command] = XOSAdminApp.detailShower(detailViewName, collection_name, "detail", name);
Scott Baker694f5662014-11-03 23:46:20 -0800120 routes[nav_url] = api_command;
Scott Baker7ce23652014-11-07 16:40:30 -0800121
122 nav_url = "add" + firstCharUpper(name);
123 api_command = "add" + firstCharUpper(name);
124 api[api_command] = XOSAdminApp.addShower(detailViewName, collection_name, "detail", name);
125 routes[nav_url] = api_command;
Scott Baker694f5662014-11-03 23:46:20 -0800126 };
127
128 XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
Scott Bakerac694222014-11-05 22:12:33 -0800129};
130
131/* rewriteLinks
132
133 Rewrite the links in the suit navbar from django-links to marionette
134 links. This let's us intercept the navbar and make it function within
135 this view rather than jumping back out to a django view.
136*/
137
138XOSAdminApp.rewriteLinks = function () {
139 $("a").each(function() {
140 href=$(this).attr("href");
141 rewrite_href=REWRITES[href];
142 if (rewrite_href) {
143 $(this).attr("href", rewrite_href);
144 }
145 });
146};
Scott Baker694f5662014-11-03 23:46:20 -0800147
Scott Baker66aaad42014-11-13 15:52:02 -0800148XOSAdminApp.startNavigation = function() {
149 Backbone.history.start();
150 XOSAdminApp.navigationStarted = true;
151}
152
153XOSAdminApp.collectionLoadChange = function() {
154 stats = xos.getCollectionStatus();
155
156 if (!XOSAdminApp.navigationStarted) {
157 if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
158 XOSAdminApp.startNavigation();
159 } else {
160 $("#detail").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");
161 $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
162 }
163 }
164};
165
Scott Baker694f5662014-11-03 23:46:20 -0800166XOSAdminApp.on("start", function() {
167 XOSAdminApp.buildViews();
168
169 XOSAdminApp.initRouter();
170
171 XOSAdminApp.updateNavigationPanel();
172
Scott Bakerac694222014-11-05 22:12:33 -0800173 XOSAdminApp.rewriteLinks();
174
Scott Baker66aaad42014-11-13 15:52:02 -0800175 // fire it once to initially show the progress bar
176 XOSAdminApp.collectionLoadChange();
177
178 // fire it each time the collection load status is updated
179 Backbone.on("xoslib:collectionLoadChange", XOSAdminApp.collectionLoadChange);
Scott Baker694f5662014-11-03 23:46:20 -0800180});
181
182$(document).ready(function(){
183 XOSAdminApp.start();
184});
185