1 OBJS = ['deployment', 'image', 'networkTemplate', 'network', 'networkSliver', 'networkDeployment', 'node', 'service', 'site', 'slice', 'sliceDeployment', 'slicePrivilege', 'sliver', 'user', 'sliceRole', 'userDeployment'];
2 NAV_OBJS = ['deployment', 'site', 'slice', 'user'];
4 REWRITES = {"/admin/core/deployment/": "#deployments",
5 "/admin/core/site/" : "#sites",
6 "/admin/core/slice/" : "#slices",
7 "/admin/core/user/" : "#users"};
9 XOSAdminApp = new XOSApplication({
10 logTableId: "#logTable",
11 statusMsgId: "#statusMsg",
12 hideTabsByDefault: true
15 XOSAdminApp.addRegions({
16 navigation: "#navigationPanel",
19 linkedObjs1: "#linkedObjs1",
20 linkedObjs2: "#linkedObjs2",
21 linkedObjs3: "#linkedObjs3",
22 linkedObjs4: "#linkedObjs4"
25 XOSAdminApp.navigateToModel = function(app, detailClass, detailNavLink, model) {
26 XOSAdminApp.Router.navigate(detailNavLink + "/" + model.id, {trigger: true});
29 ICON_CLASSES = {home: "icon-home", deployments: "icon-deployment", sites: "icon-site", slices: "icon-slice", users: "icon-user"};
\r
31 XOSAdminApp.updateNavigationPanel = function() {
\r
32 buttonTemplate=$("#xos-navbutton").html();
\r
33 assert(buttonTemplate != undefined, "buttonTemplate is undefined");
\r
34 html="<div class='left-nav'><ul>";
\r
35 for (var index in NAV_OBJS) {
\r
36 name = NAV_OBJS[index];
\r
37 collection_name = name+"s";
\r
38 nav_url = "#" + collection_name;
\r
40 icon_class = ICON_CLASSES[collection_name] || "icon-cog";
\r
42 html = html + _.template(buttonTemplate, {name: collection_name, router: "XOSAdminApp.Router", routeUrl: nav_url, iconClass: icon_class});
\r
45 html = html + "</ul>";
\r
47 $("#navigationPanel").html(html);
\r
50 XOSAdminApp.buildViews = function() {
\r
51 for (var index in OBJS) {
\r
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;
60 detailClass = XOSDetailView.extend({
61 template: detail_template,
\r
64 XOSAdminApp[collection_name + "DetailView"] = detailClass;
\r
66 itemViewClass = XOSItemView.extend({
67 detailClass: detailClass,
68 template: tr_template,
70 detailNavLink: detailNavLink,
73 listViewClass = XOSListView.extend({
74 childView: itemViewClass,
75 template: table_template,
76 collection: xos[collection_name],
81 XOSAdminApp[collection_name + "ListView"] = listViewClass;
83 xos[collection_name].fetch(); //startPolling();
87 XOSAdminApp.initRouter = function() {
\r
88 router = Marionette.AppRouter.extend({
\r
94 for (var index in OBJS) {
\r
96 collection_name = name + "s";
\r
97 nav_url = collection_name;
\r
98 api_command = "list" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
\r
99 listViewName = collection_name + "ListView";
\r
100 detailViewName = collection_name + "DetailView";
\r
102 api[api_command] = XOSAdminApp.listViewShower(listViewName, collection_name, "detail", collection_name);
\r
103 routes[nav_url] = api_command;
\r
105 nav_url = collection_name + "/:id";
\r
106 api_command = "detail" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
\r
108 api[api_command] = XOSAdminApp.detailShower(detailViewName, collection_name, "detail", name);
\r
109 routes[nav_url] = api_command;
\r
112 XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
\r
117 Rewrite the links in the suit navbar from django-links to marionette
\r
118 links. This let's us intercept the navbar and make it function within
\r
119 this view rather than jumping back out to a django view.
\r
122 XOSAdminApp.rewriteLinks = function () {
\r
123 $("a").each(function() {
\r
124 href=$(this).attr("href");
\r
125 rewrite_href=REWRITES[href];
\r
126 if (rewrite_href) {
\r
127 $(this).attr("href", rewrite_href);
\r
132 XOSAdminApp.on("start", function() {
\r
133 XOSAdminApp.buildViews();
135 XOSAdminApp.initRouter();
137 XOSAdminApp.updateNavigationPanel();
139 XOSAdminApp.rewriteLinks();
141 if (Backbone.history) {
142 console.log("history start");
143 Backbone.history.start();
147 $(document).ready(function(){