--- /dev/null
+OBJS = ['deployment', 'image', 'networkTemplate', 'network', 'networkSliver', 'networkDeployment', 'node', 'service', 'site', 'slice', 'sliceDeployment', 'slicePrivilege', 'sliver', 'user', 'sliceRole', 'userDeployment'];
+NAV_OBJS = ['deployment', 'site', 'slice', 'user'];
+
+function assert(outcome, description) {
+ if (!outcome) {
+ console.log(description);
+ }
+}
+
+XOSAdminApp = new XOSApplication();
+
+XOSAdminApp.addRegions({
+ navigation: "#navigationPanel",
+
+ detail: "#detail",
+ linkedObjs1: "#linkedObjs1",
+ linkedObjs2: "#linkedObjs2",
+ linkedObjs3: "#linkedObjs3",
+ linkedObjs4: "#linkedObjs4"
+});
+
+XOSAdminApp.navigateToModel = function(app, detailClass, detailNavLink, model) {
+ XOSAdminApp.Router.navigate(detailNavLink + "/" + model.id, {trigger: true});
+};\r
+\r
+XOSAdminApp.updateNavigationPanel = function() {\r
+ buttonTemplate=$("#xos-navbutton").html();\r
+ assert(buttonTemplate != undefined, "buttonTemplate is undefined");\r
+ html=""\r
+ for (var index in NAV_OBJS) {\r
+ name = NAV_OBJS[index];\r
+ collection_name = name+"s";\r
+ nav_url = "/" + collection_name;\r
+ id = "nav-"+name;\r
+\r
+ html = html + _.template(buttonTemplate, {name: collection_name, router: "XOSAdminApp.Router", routeUrl: nav_url});\r
+ }\r
+\r
+ $("#navigationPanel").html(html);\r
+};\r
+\r
+XOSAdminApp.buildViews = function() {\r
+ for (var index in OBJS) {\r
+ name = OBJS[index];
+ tr_template = '#xosAdmin-' + name + '-listitem-template';
+ table_template = '#xosAdmin-' + name + '-list-template';
+ detail_template = '#xosAdmin-' + name + '-detail-template';
+ collection_name = name + "s";
+ region_name = name + "List";
+ detailNavLink = collection_name;
+
+ detailClass = XOSDetailView.extend({
+ template: detail_template,\r
+ app: XOSAdminApp,\r
+ });\r
+ XOSAdminApp[collection_name + "DetailView"] = detailClass;\r
+
+ itemViewClass = XOSItemView.extend({
+ detailClass: detailClass,
+ template: tr_template,
+ app: XOSAdminApp,
+ detailNavLink: detailNavLink,
+ });
+
+ listViewClass = XOSListView.extend({
+ childView: itemViewClass,
+ template: table_template,
+ collection: xos[collection_name],
+ title: name + "s",
+ app: XOSAdminApp,
+ });
+
+ XOSAdminApp[collection_name + "ListView"] = listViewClass;
+
+ xos[collection_name].fetch(); //startPolling();
+ }\r
+};\r
+\r
+XOSAdminApp.initRouter = function() {\r
+ router = Marionette.AppRouter.extend({\r
+ });\r
+\r
+ var api = {};\r
+ var routes = {};\r
+\r
+ function listViewShower(listViewName) {\r
+ return function() {\r
+ XOSAdminApp.detail.show(new XOSAdminApp[listViewName]);\r
+ }\r
+ };\r
+\r
+ function detailShower(detailName, collection_name) {\r
+ shower = function(model_id) {\r
+ model = xos[collection_name].get(model_id);\r
+ if (model == undefined) {\r
+ $("#detail").html("not ready yet");\r
+ return;\r
+ }\r
+ detailViewClass = XOSAdminApp[detailName];\r
+ detailView = new detailViewClass({model: model});\r
+ XOSAdminApp.detail.show(detailView);\r
+ detailView.showLinkedItems();\r
+ }\r
+ return shower;\r
+ };\r
+\r
+ for (var index in OBJS) {\r
+ name = OBJS[index];\r
+ collection_name = name + "s";\r
+ nav_url = collection_name;\r
+ api_command = "list" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);\r
+ listViewName = collection_name + "ListView";\r
+ detailViewName = collection_name + "DetailView";\r
+\r
+ api[api_command] = listViewShower(listViewName);\r
+ routes[nav_url] = api_command;\r
+\r
+ nav_url = collection_name + "/:id";\r
+ api_command = "detail" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);\r
+\r
+ api[api_command] = detailShower(detailViewName, collection_name);\r
+ routes[nav_url] = api_command;\r
+ };\r
+\r
+ XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });\r
+}\r
+\r
+XOSAdminApp.on("start", function() {\r
+ XOSAdminApp.buildViews();
+
+ XOSAdminApp.initRouter();
+
+ XOSAdminApp.updateNavigationPanel();
+
+ if (Backbone.history) {
+ console.log("history start");
+ Backbone.history.start();
+ }
+});
+
+$(document).ready(function(){
+ XOSAdminApp.start();
+});
+