blob: 6fb46a056af12e16fc5ee8f4d5bace2386829e1c [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 Bakerf76d33a2014-11-04 09:34:01 -080029ICON_CLASSES = {home: "icon-home", deployments: "icon-deployment", sites: "icon-site", slices: "icon-slice", users: "icon-user"};
30
Scott Baker694f5662014-11-03 23:46:20 -080031XOSAdminApp.updateNavigationPanel = function() {
32 buttonTemplate=$("#xos-navbutton").html();
33 assert(buttonTemplate != undefined, "buttonTemplate is undefined");
Scott Bakerf76d33a2014-11-04 09:34:01 -080034 html="<div class='left-nav'><ul>";
Scott Baker694f5662014-11-03 23:46:20 -080035 for (var index in NAV_OBJS) {
36 name = NAV_OBJS[index];
37 collection_name = name+"s";
Scott Bakerf76d33a2014-11-04 09:34:01 -080038 nav_url = "#" + collection_name;
Scott Baker694f5662014-11-03 23:46:20 -080039 id = "nav-"+name;
Scott Bakerf76d33a2014-11-04 09:34:01 -080040 icon_class = ICON_CLASSES[collection_name] || "icon-cog";
Scott Baker694f5662014-11-03 23:46:20 -080041
Scott Bakerf76d33a2014-11-04 09:34:01 -080042 html = html + _.template(buttonTemplate, {name: collection_name, router: "XOSAdminApp.Router", routeUrl: nav_url, iconClass: icon_class});
Scott Baker694f5662014-11-03 23:46:20 -080043 }
44
Scott Bakerf76d33a2014-11-04 09:34:01 -080045 html = html + "</ul>";
46
Scott Baker694f5662014-11-03 23:46:20 -080047 $("#navigationPanel").html(html);
48};
49
50XOSAdminApp.buildViews = function() {
51 for (var index in OBJS) {
52 name = OBJS[index];
53 tr_template = '#xosAdmin-' + name + '-listitem-template';
54 table_template = '#xosAdmin-' + name + '-list-template';
55 detail_template = '#xosAdmin-' + name + '-detail-template';
56 collection_name = name + "s";
57 region_name = name + "List";
58 detailNavLink = collection_name;
59
60 detailClass = XOSDetailView.extend({
61 template: detail_template,
62 app: XOSAdminApp,
63 });
64 XOSAdminApp[collection_name + "DetailView"] = detailClass;
65
66 itemViewClass = XOSItemView.extend({
67 detailClass: detailClass,
68 template: tr_template,
69 app: XOSAdminApp,
70 detailNavLink: detailNavLink,
71 });
72
73 listViewClass = XOSListView.extend({
74 childView: itemViewClass,
75 template: table_template,
76 collection: xos[collection_name],
77 title: name + "s",
78 app: XOSAdminApp,
79 });
80
81 XOSAdminApp[collection_name + "ListView"] = listViewClass;
82
83 xos[collection_name].fetch(); //startPolling();
84 }
85};
86
87XOSAdminApp.initRouter = function() {
88 router = Marionette.AppRouter.extend({
89 });
90
91 var api = {};
92 var routes = {};
93
Scott Baker694f5662014-11-03 23:46:20 -080094 for (var index in OBJS) {
95 name = OBJS[index];
96 collection_name = name + "s";
97 nav_url = collection_name;
98 api_command = "list" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
99 listViewName = collection_name + "ListView";
100 detailViewName = collection_name + "DetailView";
101
Scott Baker9d37d562014-11-04 23:20:48 -0800102 api[api_command] = XOSAdminApp.listViewShower(listViewName, collection_name, "detail", collection_name);
Scott Baker694f5662014-11-03 23:46:20 -0800103 routes[nav_url] = api_command;
104
105 nav_url = collection_name + "/:id";
106 api_command = "detail" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
107
Scott Baker9d37d562014-11-04 23:20:48 -0800108 api[api_command] = XOSAdminApp.detailShower(detailViewName, collection_name, "detail", name);
Scott Baker694f5662014-11-03 23:46:20 -0800109 routes[nav_url] = api_command;
110 };
111
112 XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
Scott Bakerac694222014-11-05 22:12:33 -0800113};
114
115/* rewriteLinks
116
117 Rewrite the links in the suit navbar from django-links to marionette
118 links. This let's us intercept the navbar and make it function within
119 this view rather than jumping back out to a django view.
120*/
121
122XOSAdminApp.rewriteLinks = function () {
123 $("a").each(function() {
124 href=$(this).attr("href");
125 rewrite_href=REWRITES[href];
126 if (rewrite_href) {
127 $(this).attr("href", rewrite_href);
128 }
129 });
130};
Scott Baker694f5662014-11-03 23:46:20 -0800131
132XOSAdminApp.on("start", function() {
133 XOSAdminApp.buildViews();
134
135 XOSAdminApp.initRouter();
136
137 XOSAdminApp.updateNavigationPanel();
138
Scott Bakerac694222014-11-05 22:12:33 -0800139 XOSAdminApp.rewriteLinks();
140
Scott Baker694f5662014-11-03 23:46:20 -0800141 if (Backbone.history) {
142 console.log("history start");
143 Backbone.history.start();
144 }
145});
146
147$(document).ready(function(){
148 XOSAdminApp.start();
149});
150