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",
24 addChildDetail: "#xos-addchild-detail"
27 XOSAdminApp.navigateToModel = function(app, detailClass, detailNavLink, model) {
28 XOSAdminApp.Router.navigate(detailNavLink + "/" + model.id, {trigger: true});
31 XOSAdminApp.navigate = function(what, modelName, modelId) {
\r
32 collection_name = modelName + "s";
\r
34 XOSAdminApp.Router.navigate(collection_name, {trigger: true})
\r
35 } else if (what=="detail") {
\r
36 XOSAdminApp.Router.navigate(collection_name + "/" + modelId, {trigger: true})
\r
37 } else if (what=="add") {
\r
38 XOSAdminApp.Router.navigate("add" + firstCharUpper(modelName), {trigger: true})
\r
42 ICON_CLASSES = {home: "icon-home", deployments: "icon-deployment", sites: "icon-site", slices: "icon-slice", users: "icon-user"};
\r
44 XOSAdminApp.updateNavigationPanel = function() {
\r
45 buttonTemplate=$("#xos-navbutton").html();
\r
46 assert(buttonTemplate != undefined, "buttonTemplate is undefined");
\r
47 html="<div class='left-nav'><ul>";
\r
48 for (var index in NAV_OBJS) {
\r
49 name = NAV_OBJS[index];
\r
50 collection_name = name+"s";
\r
51 nav_url = "#" + collection_name;
\r
53 icon_class = ICON_CLASSES[collection_name] || "icon-cog";
\r
55 html = html + _.template(buttonTemplate, {name: collection_name, router: "XOSAdminApp.Router", routeUrl: nav_url, iconClass: icon_class});
\r
58 html = html + "</ul>";
\r
60 $("#navigationPanel").html(html);
\r
63 XOSAdminApp.buildViews = function() {
\r
64 for (var index in OBJS) {
\r
66 tr_template = '#xosAdmin-' + name + '-listitem-template';
67 table_template = '#xosAdmin-' + name + '-list-template';
68 detail_template = '#xosAdmin-' + name + '-detail-template';
69 collection_name = name + "s";
70 region_name = name + "List";
71 detailNavLink = collection_name;
73 detailClass = XOSDetailView.extend({
74 template: detail_template,
\r
77 XOSAdminApp[collection_name + "DetailView"] = detailClass;
\r
79 itemViewClass = XOSItemView.extend({
80 detailClass: detailClass,
81 template: tr_template,
83 detailNavLink: detailNavLink,
86 listViewClass = XOSListView.extend({
87 childView: itemViewClass,
88 template: table_template,
89 collection: xos[collection_name],
94 XOSAdminApp[collection_name + "ListView"] = listViewClass;
96 xos[collection_name].fetch(); //startPolling();
100 XOSAdminApp.initRouter = function() {
\r
101 router = XOSRouter;
\r
105 for (var index in OBJS) {
\r
106 name = OBJS[index];
\r
107 collection_name = name + "s";
\r
108 nav_url = collection_name;
\r
109 api_command = "list" + firstCharUpper(collection_name);
\r
110 listViewName = collection_name + "ListView";
\r
111 detailViewName = collection_name + "DetailView";
\r
113 api[api_command] = XOSAdminApp.createListHandler(listViewName, collection_name, "detail", collection_name);
\r
114 routes[nav_url] = api_command;
\r
116 nav_url = collection_name + "/:id";
\r
117 api_command = "detail" + firstCharUpper(collection_name);
\r
119 api[api_command] = XOSAdminApp.createDetailHandler(detailViewName, collection_name, "detail", name);
\r
120 routes[nav_url] = api_command;
\r
122 nav_url = "add" + firstCharUpper(name);
\r
123 api_command = "add" + firstCharUpper(name);
\r
124 api[api_command] = XOSAdminApp.createAddHandler(detailViewName, collection_name, "detail", name);
\r
125 routes[nav_url] = api_command;
\r
127 nav_url = "addChild" + firstCharUpper(name) + "/:parentModel/:parentField/:parentId";
\r
128 api_command = "addChild" + firstCharUpper(name);
\r
129 api[api_command] = XOSAdminApp.createAddChildHandler(detailViewName, collection_name);
\r
130 routes[nav_url] = api_command;
\r
132 nav_url = "delete" + firstCharUpper(name) + "/:id";
\r
133 api_command = "delete" + firstCharUpper(name);
\r
134 api[api_command] = XOSAdminApp.createDeleteHandler(collection_name, name);
\r
135 routes[nav_url] = api_command;
\r
138 XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
\r
143 Rewrite the links in the suit navbar from django-links to marionette
\r
144 links. This let's us intercept the navbar and make it function within
\r
145 this view rather than jumping back out to a django view.
\r
148 XOSAdminApp.rewriteLinks = function () {
\r
149 $("a").each(function() {
\r
150 href=$(this).attr("href");
\r
151 rewrite_href=REWRITES[href];
\r
152 if (rewrite_href) {
\r
153 $(this).attr("href", rewrite_href);
\r
158 XOSAdminApp.startNavigation = function() {
\r
159 Backbone.history.start();
\r
160 XOSAdminApp.navigationStarted = true;
\r
163 XOSAdminApp.collectionLoadChange = function() {
\r
164 stats = xos.getCollectionStatus();
\r
166 if (!XOSAdminApp.navigationStarted) {
\r
167 if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
\r
168 XOSAdminApp.startNavigation();
\r
170 $("#detail").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");
\r
171 $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
\r
176 XOSAdminApp.on("start", function() {
\r
177 XOSAdminApp.buildViews();
179 XOSAdminApp.initRouter();
181 XOSAdminApp.updateNavigationPanel();
183 XOSAdminApp.rewriteLinks();
185 // fire it once to initially show the progress bar
186 XOSAdminApp.collectionLoadChange();
188 // fire it each time the collection load status is updated
189 Backbone.on("xoslib:collectionLoadChange", XOSAdminApp.collectionLoadChange);
192 $(document).ready(function(){