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