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 function assert(outcome, description) {
6 console.log(description);
10 XOSAdminApp = new XOSApplication();
12 XOSAdminApp.addRegions({
13 navigation: "#navigationPanel",
16 linkedObjs1: "#linkedObjs1",
17 linkedObjs2: "#linkedObjs2",
18 linkedObjs3: "#linkedObjs3",
19 linkedObjs4: "#linkedObjs4"
22 XOSAdminApp.navigateToModel = function(app, detailClass, detailNavLink, model) {
23 XOSAdminApp.Router.navigate(detailNavLink + "/" + model.id, {trigger: true});
26 ICON_CLASSES = {home: "icon-home", deployments: "icon-deployment", sites: "icon-site", slices: "icon-slice", users: "icon-user"};
\r
28 XOSAdminApp.updateNavigationPanel = function() {
\r
29 buttonTemplate=$("#xos-navbutton").html();
\r
30 assert(buttonTemplate != undefined, "buttonTemplate is undefined");
\r
31 html="<div class='left-nav'><ul>";
\r
32 for (var index in NAV_OBJS) {
\r
33 name = NAV_OBJS[index];
\r
34 collection_name = name+"s";
\r
35 //nav_url = "/" + collection_name;
\r
36 nav_url = "#" + collection_name;
\r
38 icon_class = ICON_CLASSES[collection_name] || "icon-cog";
\r
40 html = html + _.template(buttonTemplate, {name: collection_name, router: "XOSAdminApp.Router", routeUrl: nav_url, iconClass: icon_class});
\r
43 html = html + "</ul>";
\r
45 $("#navigationPanel").html(html);
\r
48 XOSAdminApp.buildViews = function() {
\r
49 for (var index in OBJS) {
\r
51 tr_template = '#xosAdmin-' + name + '-listitem-template';
52 table_template = '#xosAdmin-' + name + '-list-template';
53 detail_template = '#xosAdmin-' + name + '-detail-template';
54 collection_name = name + "s";
55 region_name = name + "List";
56 detailNavLink = collection_name;
58 detailClass = XOSDetailView.extend({
59 template: detail_template,
\r
62 XOSAdminApp[collection_name + "DetailView"] = detailClass;
\r
64 itemViewClass = XOSItemView.extend({
65 detailClass: detailClass,
66 template: tr_template,
68 detailNavLink: detailNavLink,
71 listViewClass = XOSListView.extend({
72 childView: itemViewClass,
73 template: table_template,
74 collection: xos[collection_name],
79 XOSAdminApp[collection_name + "ListView"] = listViewClass;
81 xos[collection_name].fetch(); //startPolling();
85 XOSAdminApp.initRouter = function() {
\r
86 router = Marionette.AppRouter.extend({
\r
92 function listViewShower(listViewName) {
\r
94 XOSAdminApp.detail.show(new XOSAdminApp[listViewName]);
\r
98 function detailShower(detailName, collection_name) {
\r
99 shower = function(model_id) {
\r
100 model = xos[collection_name].get(model_id);
\r
101 if (model == undefined) {
\r
102 $("#detail").html("not ready yet");
\r
105 detailViewClass = XOSAdminApp[detailName];
\r
106 detailView = new detailViewClass({model: model});
\r
107 XOSAdminApp.detail.show(detailView);
\r
108 detailView.showLinkedItems();
\r
113 for (var index in OBJS) {
\r
114 name = OBJS[index];
\r
115 collection_name = name + "s";
\r
116 nav_url = collection_name;
\r
117 api_command = "list" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
\r
118 listViewName = collection_name + "ListView";
\r
119 detailViewName = collection_name + "DetailView";
\r
121 api[api_command] = listViewShower(listViewName);
\r
122 routes[nav_url] = api_command;
\r
124 nav_url = collection_name + "/:id";
\r
125 api_command = "detail" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
\r
127 api[api_command] = detailShower(detailViewName, collection_name);
\r
128 routes[nav_url] = api_command;
\r
131 XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
\r
134 XOSAdminApp.on("start", function() {
\r
135 XOSAdminApp.buildViews();
137 XOSAdminApp.initRouter();
139 XOSAdminApp.updateNavigationPanel();
141 if (Backbone.history) {
142 console.log("history start");
143 Backbone.history.start();
147 $(document).ready(function(){