Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 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']; |
| 3 | |
Scott Baker | 6207731 | 2014-11-04 23:34:32 -0800 | [diff] [blame^] | 4 | XOSAdminApp = new XOSApplication({logTableId: "#logTable", hideTabsByDefault: true}); |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 5 | |
| 6 | XOSAdminApp.addRegions({ |
| 7 | navigation: "#navigationPanel", |
| 8 | |
| 9 | detail: "#detail", |
| 10 | linkedObjs1: "#linkedObjs1", |
| 11 | linkedObjs2: "#linkedObjs2", |
| 12 | linkedObjs3: "#linkedObjs3", |
| 13 | linkedObjs4: "#linkedObjs4" |
| 14 | }); |
| 15 | |
| 16 | XOSAdminApp.navigateToModel = function(app, detailClass, detailNavLink, model) { |
| 17 | XOSAdminApp.Router.navigate(detailNavLink + "/" + model.id, {trigger: true}); |
| 18 | };
|
| 19 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 20 | ICON_CLASSES = {home: "icon-home", deployments: "icon-deployment", sites: "icon-site", slices: "icon-slice", users: "icon-user"};
|
| 21 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 22 | XOSAdminApp.updateNavigationPanel = function() {
|
| 23 | buttonTemplate=$("#xos-navbutton").html();
|
| 24 | assert(buttonTemplate != undefined, "buttonTemplate is undefined");
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 25 | html="<div class='left-nav'><ul>";
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 26 | for (var index in NAV_OBJS) {
|
| 27 | name = NAV_OBJS[index];
|
| 28 | collection_name = name+"s";
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 29 | nav_url = "#" + collection_name;
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 30 | id = "nav-"+name;
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 31 | icon_class = ICON_CLASSES[collection_name] || "icon-cog";
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 32 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 33 | html = html + _.template(buttonTemplate, {name: collection_name, router: "XOSAdminApp.Router", routeUrl: nav_url, iconClass: icon_class});
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 34 | }
|
| 35 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 36 | html = html + "</ul>";
|
| 37 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 38 | $("#navigationPanel").html(html);
|
| 39 | };
|
| 40 |
|
| 41 | XOSAdminApp.buildViews = function() {
|
| 42 | for (var index in OBJS) {
|
| 43 | name = OBJS[index]; |
| 44 | tr_template = '#xosAdmin-' + name + '-listitem-template'; |
| 45 | table_template = '#xosAdmin-' + name + '-list-template'; |
| 46 | detail_template = '#xosAdmin-' + name + '-detail-template'; |
| 47 | collection_name = name + "s"; |
| 48 | region_name = name + "List"; |
| 49 | detailNavLink = collection_name; |
| 50 | |
| 51 | detailClass = XOSDetailView.extend({ |
| 52 | template: detail_template,
|
| 53 | app: XOSAdminApp,
|
| 54 | });
|
| 55 | XOSAdminApp[collection_name + "DetailView"] = detailClass;
|
| 56 | |
| 57 | itemViewClass = XOSItemView.extend({ |
| 58 | detailClass: detailClass, |
| 59 | template: tr_template, |
| 60 | app: XOSAdminApp, |
| 61 | detailNavLink: detailNavLink, |
| 62 | }); |
| 63 | |
| 64 | listViewClass = XOSListView.extend({ |
| 65 | childView: itemViewClass, |
| 66 | template: table_template, |
| 67 | collection: xos[collection_name], |
| 68 | title: name + "s", |
| 69 | app: XOSAdminApp, |
| 70 | }); |
| 71 | |
| 72 | XOSAdminApp[collection_name + "ListView"] = listViewClass; |
| 73 | |
| 74 | xos[collection_name].fetch(); //startPolling(); |
| 75 | }
|
| 76 | };
|
| 77 |
|
| 78 | XOSAdminApp.initRouter = function() {
|
| 79 | router = Marionette.AppRouter.extend({
|
| 80 | });
|
| 81 |
|
| 82 | var api = {};
|
| 83 | var routes = {};
|
| 84 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 85 | for (var index in OBJS) {
|
| 86 | name = OBJS[index];
|
| 87 | collection_name = name + "s";
|
| 88 | nav_url = collection_name;
|
| 89 | api_command = "list" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
|
| 90 | listViewName = collection_name + "ListView";
|
| 91 | detailViewName = collection_name + "DetailView";
|
| 92 |
|
Scott Baker | 9d37d56 | 2014-11-04 23:20:48 -0800 | [diff] [blame] | 93 | api[api_command] = XOSAdminApp.listViewShower(listViewName, collection_name, "detail", collection_name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 94 | routes[nav_url] = api_command;
|
| 95 |
|
| 96 | nav_url = collection_name + "/:id";
|
| 97 | api_command = "detail" + collection_name.charAt(0).toUpperCase() + collection_name.slice(1);
|
| 98 |
|
Scott Baker | 9d37d56 | 2014-11-04 23:20:48 -0800 | [diff] [blame] | 99 | api[api_command] = XOSAdminApp.detailShower(detailViewName, collection_name, "detail", name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 100 | routes[nav_url] = api_command;
|
| 101 | };
|
| 102 |
|
| 103 | XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
|
| 104 | }
|
| 105 |
|
| 106 | XOSAdminApp.on("start", function() {
|
| 107 | XOSAdminApp.buildViews(); |
| 108 | |
| 109 | XOSAdminApp.initRouter(); |
| 110 | |
| 111 | XOSAdminApp.updateNavigationPanel(); |
| 112 | |
| 113 | if (Backbone.history) { |
| 114 | console.log("history start"); |
| 115 | Backbone.history.start(); |
| 116 | } |
| 117 | }); |
| 118 | |
| 119 | $(document).ready(function(){ |
| 120 | XOSAdminApp.start(); |
| 121 | }); |
| 122 | |