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 | ac69422 | 2014-11-05 22:12:33 -0800 | [diff] [blame] | 4 | REWRITES = {"/admin/core/deployment/": "#deployments", |
| 5 | "/admin/core/site/" : "#sites", |
| 6 | "/admin/core/slice/" : "#slices", |
| 7 | "/admin/core/user/" : "#users"}; |
| 8 | |
| 9 | XOSAdminApp = new XOSApplication({ |
| 10 | logTableId: "#logTable", |
| 11 | statusMsgId: "#statusMsg", |
| 12 | hideTabsByDefault: true |
| 13 | }); |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 14 | |
| 15 | XOSAdminApp.addRegions({ |
| 16 | navigation: "#navigationPanel", |
| 17 | |
| 18 | detail: "#detail", |
| 19 | linkedObjs1: "#linkedObjs1", |
| 20 | linkedObjs2: "#linkedObjs2", |
| 21 | linkedObjs3: "#linkedObjs3", |
| 22 | linkedObjs4: "#linkedObjs4" |
| 23 | }); |
| 24 | |
| 25 | XOSAdminApp.navigateToModel = function(app, detailClass, detailNavLink, model) { |
| 26 | XOSAdminApp.Router.navigate(detailNavLink + "/" + model.id, {trigger: true}); |
| 27 | };
|
| 28 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 29 | ICON_CLASSES = {home: "icon-home", deployments: "icon-deployment", sites: "icon-site", slices: "icon-slice", users: "icon-user"};
|
| 30 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 31 | XOSAdminApp.updateNavigationPanel = function() {
|
| 32 | buttonTemplate=$("#xos-navbutton").html();
|
| 33 | assert(buttonTemplate != undefined, "buttonTemplate is undefined");
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 34 | html="<div class='left-nav'><ul>";
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 35 | for (var index in NAV_OBJS) {
|
| 36 | name = NAV_OBJS[index];
|
| 37 | collection_name = name+"s";
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 38 | nav_url = "#" + collection_name;
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 39 | id = "nav-"+name;
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 40 | icon_class = ICON_CLASSES[collection_name] || "icon-cog";
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 41 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 42 | 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] | 43 | }
|
| 44 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 45 | html = html + "</ul>";
|
| 46 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 47 | $("#navigationPanel").html(html);
|
| 48 | };
|
| 49 |
|
| 50 | XOSAdminApp.buildViews = function() {
|
| 51 | for (var index in OBJS) {
|
| 52 | name = OBJS[index]; |
| 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; |
Scott Baker | 01c9d61 | 2014-11-14 16:13:43 -0800 | [diff] [blame^] | 59 | listNavLink = collection_name; |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 60 | |
| 61 | detailClass = XOSDetailView.extend({ |
| 62 | template: detail_template,
|
| 63 | app: XOSAdminApp,
|
Scott Baker | 01c9d61 | 2014-11-14 16:13:43 -0800 | [diff] [blame^] | 64 | listNavLink: listNavLink,
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 65 | });
|
| 66 | XOSAdminApp[collection_name + "DetailView"] = detailClass;
|
| 67 | |
| 68 | itemViewClass = XOSItemView.extend({ |
| 69 | detailClass: detailClass, |
| 70 | template: tr_template, |
| 71 | app: XOSAdminApp, |
| 72 | detailNavLink: detailNavLink, |
| 73 | }); |
| 74 | |
| 75 | listViewClass = XOSListView.extend({ |
| 76 | childView: itemViewClass, |
| 77 | template: table_template, |
| 78 | collection: xos[collection_name], |
| 79 | title: name + "s", |
| 80 | app: XOSAdminApp, |
| 81 | }); |
| 82 | |
| 83 | XOSAdminApp[collection_name + "ListView"] = listViewClass; |
| 84 | |
| 85 | xos[collection_name].fetch(); //startPolling(); |
| 86 | }
|
| 87 | };
|
| 88 |
|
| 89 | XOSAdminApp.initRouter = function() {
|
| 90 | router = Marionette.AppRouter.extend({
|
| 91 | });
|
| 92 |
|
| 93 | var api = {};
|
| 94 | var routes = {};
|
| 95 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 96 | for (var index in OBJS) {
|
| 97 | name = OBJS[index];
|
| 98 | collection_name = name + "s";
|
| 99 | nav_url = collection_name;
|
Scott Baker | 7ce2365 | 2014-11-07 16:40:30 -0800 | [diff] [blame] | 100 | api_command = "list" + firstCharUpper(collection_name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 101 | listViewName = collection_name + "ListView";
|
| 102 | detailViewName = collection_name + "DetailView";
|
| 103 |
|
Scott Baker | 9d37d56 | 2014-11-04 23:20:48 -0800 | [diff] [blame] | 104 | api[api_command] = XOSAdminApp.listViewShower(listViewName, collection_name, "detail", collection_name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 105 | routes[nav_url] = api_command;
|
| 106 |
|
| 107 | nav_url = collection_name + "/:id";
|
Scott Baker | 7ce2365 | 2014-11-07 16:40:30 -0800 | [diff] [blame] | 108 | api_command = "detail" + firstCharUpper(collection_name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 109 |
|
Scott Baker | 9d37d56 | 2014-11-04 23:20:48 -0800 | [diff] [blame] | 110 | api[api_command] = XOSAdminApp.detailShower(detailViewName, collection_name, "detail", name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 111 | routes[nav_url] = api_command;
|
Scott Baker | 7ce2365 | 2014-11-07 16:40:30 -0800 | [diff] [blame] | 112 |
|
| 113 | nav_url = "add" + firstCharUpper(name);
|
| 114 | api_command = "add" + firstCharUpper(name);
|
| 115 | api[api_command] = XOSAdminApp.addShower(detailViewName, collection_name, "detail", name);
|
| 116 | routes[nav_url] = api_command;
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 117 | };
|
| 118 |
|
| 119 | XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
|
Scott Baker | ac69422 | 2014-11-05 22:12:33 -0800 | [diff] [blame] | 120 | };
|
| 121 |
|
| 122 | /* rewriteLinks
|
| 123 |
|
| 124 | Rewrite the links in the suit navbar from django-links to marionette
|
| 125 | links. This let's us intercept the navbar and make it function within
|
| 126 | this view rather than jumping back out to a django view.
|
| 127 | */
|
| 128 |
|
| 129 | XOSAdminApp.rewriteLinks = function () {
|
| 130 | $("a").each(function() {
|
| 131 | href=$(this).attr("href");
|
| 132 | rewrite_href=REWRITES[href];
|
| 133 | if (rewrite_href) {
|
| 134 | $(this).attr("href", rewrite_href);
|
| 135 | }
|
| 136 | });
|
| 137 | };
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 138 |
|
Scott Baker | 66aaad4 | 2014-11-13 15:52:02 -0800 | [diff] [blame] | 139 | XOSAdminApp.startNavigation = function() {
|
| 140 | Backbone.history.start();
|
| 141 | XOSAdminApp.navigationStarted = true;
|
| 142 | }
|
| 143 |
|
| 144 | XOSAdminApp.collectionLoadChange = function() {
|
| 145 | stats = xos.getCollectionStatus();
|
| 146 |
|
| 147 | if (!XOSAdminApp.navigationStarted) {
|
| 148 | if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
|
| 149 | XOSAdminApp.startNavigation();
|
| 150 | } else {
|
| 151 | $("#detail").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");
|
| 152 | $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
|
| 153 | }
|
| 154 | }
|
| 155 | };
|
| 156 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 157 | XOSAdminApp.on("start", function() {
|
| 158 | XOSAdminApp.buildViews(); |
| 159 | |
| 160 | XOSAdminApp.initRouter(); |
| 161 | |
| 162 | XOSAdminApp.updateNavigationPanel(); |
| 163 | |
Scott Baker | ac69422 | 2014-11-05 22:12:33 -0800 | [diff] [blame] | 164 | XOSAdminApp.rewriteLinks(); |
| 165 | |
Scott Baker | 66aaad4 | 2014-11-13 15:52:02 -0800 | [diff] [blame] | 166 | // fire it once to initially show the progress bar |
| 167 | XOSAdminApp.collectionLoadChange(); |
| 168 | |
| 169 | // fire it each time the collection load status is updated |
| 170 | Backbone.on("xoslib:collectionLoadChange", XOSAdminApp.collectionLoadChange); |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 171 | }); |
| 172 | |
| 173 | $(document).ready(function(){ |
| 174 | XOSAdminApp.start(); |
| 175 | }); |
| 176 | |