Scott Baker | c6870e7 | 2014-12-22 17:56:44 -0800 | [diff] [blame^] | 1 | OBJS = ['deployment', 'image', 'networkTemplate', 'network', 'networkSliver', 'node', 'service', 'site', 'slice', 'slicePrivilege', 'sliver', 'user', 'sliceRole', 'flavor', 'controller', 'siteDeployment']; |
Scott Baker | 325e3e2 | 2014-12-22 15:54:13 -0800 | [diff] [blame] | 2 | // 'networkDeployment', 'userDeployment', 'sliceDeployment', 'imageDeployment' |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 3 | NAV_OBJS = ['deployment', 'site', 'slice', 'user']; |
| 4 | |
Scott Baker | ac69422 | 2014-11-05 22:12:33 -0800 | [diff] [blame] | 5 | REWRITES = {"/admin/core/deployment/": "#deployments", |
| 6 | "/admin/core/site/" : "#sites", |
| 7 | "/admin/core/slice/" : "#slices", |
| 8 | "/admin/core/user/" : "#users"}; |
| 9 | |
| 10 | XOSAdminApp = new XOSApplication({ |
| 11 | logTableId: "#logTable", |
| 12 | statusMsgId: "#statusMsg", |
| 13 | hideTabsByDefault: true |
| 14 | }); |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 15 | |
| 16 | XOSAdminApp.addRegions({ |
| 17 | navigation: "#navigationPanel", |
| 18 | |
| 19 | detail: "#detail", |
| 20 | linkedObjs1: "#linkedObjs1", |
| 21 | linkedObjs2: "#linkedObjs2", |
| 22 | linkedObjs3: "#linkedObjs3", |
Scott Baker | 3e8d473 | 2014-12-04 17:22:01 -0800 | [diff] [blame] | 23 | linkedObjs4: "#linkedObjs4", |
| 24 | |
Scott Baker | ca4bf92 | 2014-12-09 18:38:13 -0800 | [diff] [blame] | 25 | addChildDetail: "#xos-addchild-detail", |
| 26 | |
| 27 | rightButtonPanel: "#rightButtonPanel" |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 28 | }); |
| 29 | |
Scott Baker | 13e6f0d | 2014-11-18 17:02:07 -0800 | [diff] [blame] | 30 | XOSAdminApp.navigate = function(what, modelName, modelId) {
|
Scott Baker | ab5f136 | 2014-12-09 19:39:45 -0800 | [diff] [blame] | 31 | console.log("XOSAsminApp.navigate");
|
Scott Baker | 13e6f0d | 2014-11-18 17:02:07 -0800 | [diff] [blame] | 32 | collection_name = modelName + "s";
|
| 33 | if (what=="list") {
|
| 34 | XOSAdminApp.Router.navigate(collection_name, {trigger: true})
|
| 35 | } else if (what=="detail") {
|
| 36 | XOSAdminApp.Router.navigate(collection_name + "/" + modelId, {trigger: true})
|
| 37 | } else if (what=="add") {
|
Scott Baker | ab5f136 | 2014-12-09 19:39:45 -0800 | [diff] [blame] | 38 | XOSAdminApp.Router.navigate("add" + firstCharUpper(modelName), {trigger: true, force: true})
|
Scott Baker | 13e6f0d | 2014-11-18 17:02:07 -0800 | [diff] [blame] | 39 | }
|
| 40 | }
|
| 41 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 42 | ICON_CLASSES = {home: "icon-home", deployments: "icon-deployment", sites: "icon-site", slices: "icon-slice", users: "icon-user"};
|
| 43 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 44 | XOSAdminApp.updateNavigationPanel = function() {
|
| 45 | buttonTemplate=$("#xos-navbutton").html();
|
| 46 | assert(buttonTemplate != undefined, "buttonTemplate is undefined");
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 47 | html="<div class='left-nav'><ul>";
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 48 | for (var index in NAV_OBJS) {
|
| 49 | name = NAV_OBJS[index];
|
| 50 | collection_name = name+"s";
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 51 | nav_url = "#" + collection_name;
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 52 | id = "nav-"+name;
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 53 | icon_class = ICON_CLASSES[collection_name] || "icon-cog";
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 54 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 55 | 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] | 56 | }
|
| 57 |
|
Scott Baker | f76d33a | 2014-11-04 09:34:01 -0800 | [diff] [blame] | 58 | html = html + "</ul>";
|
| 59 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 60 | $("#navigationPanel").html(html);
|
| 61 | };
|
| 62 |
|
| 63 | XOSAdminApp.buildViews = function() {
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 64 | genericAddChildClass = XOSDetailView.extend({template: "#xos-add-template",
|
| 65 | app: XOSAdminApp});
|
| 66 | XOSAdminApp["genericAddChildView"] = genericAddChildClass;
|
| 67 |
|
| 68 | genericDetailClass = XOSDetailView.extend({template: "#xos-detail-template",
|
| 69 | app: XOSAdminApp});
|
| 70 | XOSAdminApp["genericDetailView"] = genericDetailClass;
|
| 71 |
|
Scott Baker | e68d37b | 2014-12-09 16:59:08 -0800 | [diff] [blame] | 72 | genericItemViewClass = XOSItemView.extend({template: "#xos-listitem-template",
|
| 73 | app: XOSAdminApp});
|
| 74 | XOSAdminApp["genericItemView"] = genericItemViewClass;
|
| 75 |
|
Scott Baker | 0060907 | 2014-12-12 14:45:40 -0800 | [diff] [blame] | 76 | //genericListViewClass = XOSListView.extend({template: "#xos-list-template",
|
| 77 | // app: XOSAdminApp});
|
| 78 |
|
| 79 | genericListViewClass = XOSDataTableView.extend({template: "#xos-list-template", app: XOSAdminApp});
|
Scott Baker | e68d37b | 2014-12-09 16:59:08 -0800 | [diff] [blame] | 80 | XOSAdminApp["genericListView"] = genericListViewClass;
|
| 81 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 82 | for (var index in OBJS) {
|
| 83 | name = OBJS[index]; |
| 84 | tr_template = '#xosAdmin-' + name + '-listitem-template'; |
| 85 | table_template = '#xosAdmin-' + name + '-list-template'; |
| 86 | detail_template = '#xosAdmin-' + name + '-detail-template'; |
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 87 | add_child_template = '#xosAdmin-' + name + '-add-child-template'; |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 88 | collection_name = name + "s"; |
| 89 | region_name = name + "List"; |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 90 | |
Scott Baker | b45e885 | 2014-12-15 16:47:19 -0800 | [diff] [blame] | 91 | if (window["XOSDetailView_" + name]) { |
| 92 | detailClass = window["XOSDetailView_" + name].extend({template: "#xos-detail-template", |
| 93 | app: XOSAdminApp}); |
| 94 | } else { |
| 95 | detailClass = genericDetailClass; |
| 96 | } |
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 97 | if ($(detail_template).length) { |
Scott Baker | b45e885 | 2014-12-15 16:47:19 -0800 | [diff] [blame] | 98 | detailClass = detailClass.extend({ |
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 99 | template: detail_template,
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 100 | });
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 101 | }
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 102 | XOSAdminApp[collection_name + "DetailView"] = detailClass;
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 103 |
|
Scott Baker | b45e885 | 2014-12-15 16:47:19 -0800 | [diff] [blame] | 104 | if (window["XOSDetailView_" + name]) {
|
| 105 | addClass = window["XOSDetailView_" + name].extend({template: "#xos-add-template", |
| 106 | app: XOSAdminApp}); |
| 107 | } else { |
| 108 | addClass = genericAddChildClass; |
| 109 | } |
| 110 | if ($(add_child_template).length) { |
| 111 | addClass = detailClass.extend({ |
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 112 | template: add_child_template,
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 113 | });
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 114 | }
|
| 115 | XOSAdminApp[collection_name + "AddChildView"] = addClass;
|
| 116 |
|
Scott Baker | e68d37b | 2014-12-09 16:59:08 -0800 | [diff] [blame] | 117 | if ($(tr_template).length) {
|
| 118 | itemViewClass = XOSItemView.extend({
|
| 119 | template: tr_template,
|
| 120 | app: XOSAdminApp, |
| 121 | }); |
| 122 | } else { |
| 123 | itemViewClass = genericItemViewClass; |
| 124 | } |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 125 | |
Scott Baker | e68d37b | 2014-12-09 16:59:08 -0800 | [diff] [blame] | 126 | if ($(table_template).length) { |
| 127 | listViewClass = XOSListView.extend({ |
| 128 | childView: itemViewClass, |
| 129 | template: table_template, |
| 130 | collection: xos[collection_name], |
| 131 | title: name + "s", |
| 132 | app: XOSAdminApp, |
| 133 | }); |
| 134 | } else { |
| 135 | listViewClass = genericListViewClass.extend( { childView: itemViewClass, |
| 136 | collection: xos[collection_name], |
| 137 | title: name + "s", |
| 138 | } ); |
| 139 | } |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 140 | |
| 141 | XOSAdminApp[collection_name + "ListView"] = listViewClass; |
| 142 | |
| 143 | xos[collection_name].fetch(); //startPolling(); |
| 144 | }
|
| 145 | };
|
| 146 |
|
| 147 | XOSAdminApp.initRouter = function() {
|
Scott Baker | 29e8a2c | 2014-12-02 17:59:02 -0800 | [diff] [blame] | 148 | router = XOSRouter;
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 149 | var api = {};
|
| 150 | var routes = {};
|
| 151 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 152 | for (var index in OBJS) {
|
| 153 | name = OBJS[index];
|
| 154 | collection_name = name + "s";
|
| 155 | nav_url = collection_name;
|
Scott Baker | 7ce2365 | 2014-11-07 16:40:30 -0800 | [diff] [blame] | 156 | api_command = "list" + firstCharUpper(collection_name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 157 | listViewName = collection_name + "ListView";
|
| 158 | detailViewName = collection_name + "DetailView";
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 159 | addChildViewName = collection_name + "AddChildView";
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 160 |
|
Scott Baker | 3e8d473 | 2014-12-04 17:22:01 -0800 | [diff] [blame] | 161 | api[api_command] = XOSAdminApp.createListHandler(listViewName, collection_name, "detail", collection_name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 162 | routes[nav_url] = api_command;
|
| 163 |
|
| 164 | nav_url = collection_name + "/:id";
|
Scott Baker | 7ce2365 | 2014-11-07 16:40:30 -0800 | [diff] [blame] | 165 | api_command = "detail" + firstCharUpper(collection_name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 166 |
|
Scott Baker | 3e8d473 | 2014-12-04 17:22:01 -0800 | [diff] [blame] | 167 | api[api_command] = XOSAdminApp.createDetailHandler(detailViewName, collection_name, "detail", name);
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 168 | routes[nav_url] = api_command;
|
Scott Baker | 7ce2365 | 2014-11-07 16:40:30 -0800 | [diff] [blame] | 169 |
|
| 170 | nav_url = "add" + firstCharUpper(name);
|
| 171 | api_command = "add" + firstCharUpper(name);
|
Scott Baker | 3e8d473 | 2014-12-04 17:22:01 -0800 | [diff] [blame] | 172 | api[api_command] = XOSAdminApp.createAddHandler(detailViewName, collection_name, "detail", name);
|
| 173 | routes[nav_url] = api_command;
|
| 174 |
|
| 175 | nav_url = "addChild" + firstCharUpper(name) + "/:parentModel/:parentField/:parentId";
|
| 176 | api_command = "addChild" + firstCharUpper(name);
|
Scott Baker | 0a636cb | 2014-12-07 22:27:09 -0800 | [diff] [blame] | 177 | api[api_command] = XOSAdminApp.createAddChildHandler(addChildViewName, collection_name);
|
Scott Baker | 7ce2365 | 2014-11-07 16:40:30 -0800 | [diff] [blame] | 178 | routes[nav_url] = api_command;
|
Scott Baker | 29e8a2c | 2014-12-02 17:59:02 -0800 | [diff] [blame] | 179 |
|
| 180 | nav_url = "delete" + firstCharUpper(name) + "/:id";
|
| 181 | api_command = "delete" + firstCharUpper(name);
|
Scott Baker | 3e8d473 | 2014-12-04 17:22:01 -0800 | [diff] [blame] | 182 | api[api_command] = XOSAdminApp.createDeleteHandler(collection_name, name);
|
Scott Baker | 29e8a2c | 2014-12-02 17:59:02 -0800 | [diff] [blame] | 183 | routes[nav_url] = api_command;
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 184 | };
|
| 185 |
|
| 186 | XOSAdminApp.Router = new router({ appRoutes: routes, controller: api });
|
Scott Baker | ac69422 | 2014-11-05 22:12:33 -0800 | [diff] [blame] | 187 | };
|
| 188 |
|
| 189 | /* rewriteLinks
|
| 190 |
|
| 191 | Rewrite the links in the suit navbar from django-links to marionette
|
| 192 | links. This let's us intercept the navbar and make it function within
|
| 193 | this view rather than jumping back out to a django view.
|
| 194 | */
|
| 195 |
|
| 196 | XOSAdminApp.rewriteLinks = function () {
|
| 197 | $("a").each(function() {
|
| 198 | href=$(this).attr("href");
|
| 199 | rewrite_href=REWRITES[href];
|
| 200 | if (rewrite_href) {
|
| 201 | $(this).attr("href", rewrite_href);
|
| 202 | }
|
| 203 | });
|
| 204 | };
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 205 |
|
Scott Baker | 66aaad4 | 2014-11-13 15:52:02 -0800 | [diff] [blame] | 206 | XOSAdminApp.startNavigation = function() {
|
| 207 | Backbone.history.start();
|
| 208 | XOSAdminApp.navigationStarted = true;
|
| 209 | }
|
| 210 |
|
| 211 | XOSAdminApp.collectionLoadChange = function() {
|
| 212 | stats = xos.getCollectionStatus();
|
| 213 |
|
| 214 | if (!XOSAdminApp.navigationStarted) {
|
| 215 | if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {
|
| 216 | XOSAdminApp.startNavigation();
|
| 217 | } else {
|
| 218 | $("#detail").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");
|
| 219 | $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});
|
| 220 | }
|
| 221 | }
|
| 222 | };
|
| 223 |
|
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 224 | XOSAdminApp.on("start", function() {
|
| 225 | XOSAdminApp.buildViews(); |
| 226 | |
| 227 | XOSAdminApp.initRouter(); |
| 228 | |
| 229 | XOSAdminApp.updateNavigationPanel(); |
| 230 | |
Scott Baker | ac69422 | 2014-11-05 22:12:33 -0800 | [diff] [blame] | 231 | XOSAdminApp.rewriteLinks(); |
| 232 | |
Scott Baker | 66aaad4 | 2014-11-13 15:52:02 -0800 | [diff] [blame] | 233 | // fire it once to initially show the progress bar |
| 234 | XOSAdminApp.collectionLoadChange(); |
| 235 | |
| 236 | // fire it each time the collection load status is updated |
| 237 | Backbone.on("xoslib:collectionLoadChange", XOSAdminApp.collectionLoadChange); |
Scott Baker | 694f566 | 2014-11-03 23:46:20 -0800 | [diff] [blame] | 238 | }); |
| 239 | |
| 240 | $(document).ready(function(){ |
| 241 | XOSAdminApp.start(); |
| 242 | }); |
| 243 | |